	SECTION _TEXT CLASS=CODE USE32
	SECTION _DATA CLASS=DATA USE32
	SECTION _BSS  CLASS=BSS USE32
	SECTION _CONST  CLASS=CONST USE32
	SECTION _STRING  CLASS=STRING USE32
	SECTION cstartup CLASS=INITDATA USE32
	SECTION crundown CLASS=EXITDATA USE32
	SECTION cppinit  CLASS=CPPINIT USE32
	SECTION cppexit  CLASS=CPPEXIT USE32
	GROUP DGROUP _DATA _BSS _CONST _STRING

SECTION _TEXT
[GLOBAL	__basefopen]
;
; Line 13:	{
;
__basefopen:
	PUSH	EBP
	MOV	EBP,ESP
	SUB	ESP,BYTE 014H
	PUSH	EBX
	PUSH	ESI
	PUSH	EDI
;
; Line 14:		int flags = 0,append = 0, update = 0, id = 0,i;
;
	MOV	EBX,00H
	MOV	DWORD [EBP+0FFFFFFECH],00H
	MOV	DWORD [EBP+0FFFFFFF0H],00H
	MOV	DWORD [EBP+0FFFFFFF4H],00H
;
; Line 17:		if (maxfiles >= 20) {
;
	CMP	DWORD [_maxfiles],BYTE 014H
	JL	SHORT	L_2
;
; Line 18:			_dos_errno = errno = 4       ;
;
	MOV	DWORD [_errno],04H
	MOV	DWORD [__dos_errno],04H
;
; Line 19:			return 0;
;
	MOV	EAX,00H
	JMP	L_4
L_2:
	MOV	DWORD [EBP+0FFFFFFF8H],00H
	JMP	L_7
L_5:
;
; Line 22:			switch (mode[i]) {
;
	MOV	EAX,DWORD [EBP+0CH]
	MOV	ECX,DWORD [EBP+0FFFFFFF8H]
	MOV	AL,BYTE [EAX+ECX+00H]
	CMP	AL,BYTE 072H
	JE	NEAR	L_11
	JG	NEAR	L_18
	CMP	AL,BYTE 061H
	JE	NEAR	L_13
	JG	SHORT	L_19
	CMP	AL,BYTE 02BH
	JE	NEAR	L_14
	JMP	L_9
L_19:
	CMP	AL,BYTE 062H
	JE	NEAR	L_15
	JMP	L_9
L_18:
	CMP	AL,BYTE 077H
	JE	SHORT	L_12
	JG	NEAR	L_9
	CMP	AL,BYTE 074H
	JE	NEAR	L_16
	JMP	L_9
L_11:
;
; Line 24:					flags |= 0x0001                   ;
;
	BTS	EBX,00H
;
; Line 25:					break;
;
	JMP	L_10
L_12:
;
; Line 27:					flags |= 0x0002                   ;
;
	BTS	EBX,01H
;
; Line 28:					break;
;
	JMP	L_10
L_13:
;
; Line 30:					flags |= 0x0002                   ;
;
	BTS	EBX,01H
;
; Line 31:					append = 1;
;
	MOV	DWORD [EBP+0FFFFFFECH],01H
;
; Line 32:					break;
;
	JMP	L_10
L_14:
;
; Line 34:					update = 1;
;
	MOV	DWORD [EBP+0FFFFFFF0H],01H
;
; Line 35:					break;
;
	JMP	L_10
L_15:
;
; Line 37:					flags |= 0x0040                   ;
;
	BTS	EBX,06H
;
; Line 38:					break;
;
	JMP	L_10
L_16:
;
; Line 40:					flags &= ~0x0040                   ;
;
	BTR	EBX,06H
;
; Line 41:					break;
;
	JMP	L_10
L_9:
;
; Line 43:					return 0;
;
	MOV	EAX,00H
	JMP	L_4
L_10:
;
; Line 45:		}
;
;
; Line 21:		for (i=0; i < strlen(mode); i++) {
;
L_6:
	INC	DWORD [EBP+0FFFFFFF8H]
L_7:
	PUSH	EDI
	MOV	EDI,DWORD [EBP+0CH]
	CLD
	SUB	EAX,EAX
	MOV	ECX,0FFFFFFFFH
	REPNZ	SCASB
	NOT	ECX
	DEC	ECX
	MOV	EAX,ECX
	POP	EDI
	CMP	DWORD [EBP+0FFFFFFF8H],EAX
	JB	NEAR	L_5
L_8:
;
; Line 46:		if (!(flags & (0x0001                    | 0x0002                   )))
;
	MOV	EAX,EBX
	AND	EAX,BYTE 03H
	JNE	SHORT	L_20
;
; Line 47:			return 0;
;
	MOV	EAX,00H
	JMP	L_4
L_20:
;
; Line 48:		fname = malloc(strlen(name)+1);
;
	PUSH	EDI
	MOV	EDI,DWORD [EBP+08H]
	CLD
	SUB	EAX,EAX
	MOV	ECX,0FFFFFFFFH
	REPNZ	SCASB
	NOT	ECX
	DEC	ECX
	MOV	EAX,ECX
	POP	EDI
	INC	EAX
	PUSH	EAX
	CALL	_malloc
	POP	ECX
	MOV	DWORD [EBP+0FFFFFFFCH],EAX
;
; Line 49:		if (!fname) 
;
	CMP	DWORD [EBP+0FFFFFFFCH],BYTE 00H
	JNE	SHORT	L_22
;
; Line 50:			return 0;
;
	MOV	EAX,00H
	JMP	L_4
L_22:
;
; Line 51:		strcpy(fname,name);
;
	PUSH	ESI
	PUSH	EDI
	MOV	ESI,DWORD [EBP+08H]
	MOV	EDI,DWORD [EBP+0FFFFFFFCH]
	XCHG	ESI,EDI
	CLD
	PUSH	EDI
	SUB	EAX,EAX
	MOV	ECX,0FFFFFFFFH
	REPNZ	SCASB
	NOT	ECX
	MOV	EAX,ECX
	POP	EDI
	XCHG	ESI,EDI
	REPNZ	MOVSB
	POP	EDI
	POP	ESI
;
; Line 52:		if (stream)
;
	CMP	DWORD [EBP+010H],BYTE 00H
	JE	SHORT	L_24
;
; Line 53:			file = stream;
;
	MOV	ESI,DWORD [EBP+010H]
	JMP	L_25
L_24:
;
; Line 55:			if ((file = malloc(sizeof(FILE))) == 0) {
;
	PUSH	BYTE 01FH
	CALL	_malloc
	POP	ECX
	MOV	ESI,EAX
	TEST	EAX,EAX
	JNE	SHORT	L_26
;
; Line 56:				free(fname);
;
	PUSH	DWORD [EBP+0FFFFFFFCH]
	CALL	_free
	POP	ECX
;
; Line 57:				return 0;
;
	MOV	EAX,00H
	JMP	L_4
L_26:
;
; Line 60:				memset(file,0,sizeof(FILE));
;
	MOV	EAX,00H
	MOV	ECX,01FH
	PUSH	EDI
	PUSH	EAX
	MOV	EDI,ESI
	CLD
	REPNZ	STOSB
	POP	EAX
	POP	EDI
L_27:
L_25:
;
; Line 61:		file->flags = 0;
;
	MOV	DWORD [ESI+04H],00H
;
; Line 62:		buf = malloc(512          );
;
	PUSH	DWORD 0200H
	CALL	_malloc
	POP	ECX
	MOV	EDI,EAX
;
; Line 63:		if (!buf) {
;
	TEST	EDI,EDI
	JNE	SHORT	L_28
;
; Line 64:			free(fname);
;
	PUSH	DWORD [EBP+0FFFFFFFCH]
	CALL	_free
	POP	ECX
;
; Line 65:			free(file);
;
	PUSH	ESI
	CALL	_free
	POP	ECX
;
; Line 66:			return 0;
;
	MOV	EAX,00H
	JMP	L_4
L_28:
;
; Line 68:		switch (flags & (0x0001                    | 0x0002                   )) {
;
	MOV	EAX,EBX
	AND	EAX,BYTE 03H
	CMP	EAX,DWORD 00H
	JE	SHORT	L_32
	CMP	EAX,DWORD 01H
	JE	SHORT	L_33
	CMP	EAX,DWORD 02H
	JE	NEAR	L_34
	CMP	EAX,DWORD 03H
	JE	NEAR	L_35
	JMP	L_30
L_32:
;
; Line 70:				goto nofile;
;
	JMP	L_1
L_33:
;
; Line 72:				if (update)
;
	CMP	DWORD [EBP+0FFFFFFF0H],BYTE 00H
	JE	SHORT	L_36
;
; Line 73:					flags |= 0x0002                   ;
;
	BTS	EBX,01H
L_36:
;
; Line 74:		 		id = _ll_open(name,	_ll_flags(flags));
;
	PUSH	EBX
	CALL	__ll_flags
	POP	ECX
	PUSH	EAX
	PUSH	DWORD [EBP+08H]
	CALL	__ll_open
	ADD	ESP,BYTE 08H
	MOV	DWORD [EBP+0FFFFFFF4H],EAX
;
; Line 75:				break;
;
	JMP	L_31
L_34:
;
; Line 77:				if (update)
;
	CMP	DWORD [EBP+0FFFFFFF0H],BYTE 00H
	JE	SHORT	L_38
;
; Line 78:					flags |= 0x0001                   ;
;
	BTS	EBX,00H
L_38:
;
; Line 79:				id = 0;
;
	MOV	DWORD [EBP+0FFFFFFF4H],00H
;
; Line 80:				if (append)
;
	CMP	DWORD [EBP+0FFFFFFECH],BYTE 00H
	JE	SHORT	L_40
;
; Line 81:					id = _ll_open(name,_ll_flags(flags));
;
	PUSH	EBX
	CALL	__ll_flags
	POP	ECX
	PUSH	EAX
	PUSH	DWORD [EBP+08H]
	CALL	__ll_open
	ADD	ESP,BYTE 08H
	MOV	DWORD [EBP+0FFFFFFF4H],EAX
L_40:
;
; Line 82:				if (!id)
;
	CMP	DWORD [EBP+0FFFFFFF4H],BYTE 00H
	JNE	SHORT	L_42
;
; Line 83:					id = _ll_creat(name,_ll_flags(flags));
;
	PUSH	EBX
	CALL	__ll_flags
	POP	ECX
	PUSH	EAX
	PUSH	DWORD [EBP+08H]
	CALL	__ll_creat
	ADD	ESP,BYTE 08H
	MOV	DWORD [EBP+0FFFFFFF4H],EAX
L_42:
;
; Line 84:				break;
;
	JMP	L_31
L_35:
;
; Line 86:				return 0;
;
	MOV	EAX,00H
	JMP	L_4
L_30:
L_31:
;
; Line 88:		if (id == 0)
;
	CMP	DWORD [EBP+0FFFFFFF4H],BYTE 00H
	JE	NEAR	L_1
;
; Line 89:			goto nofile;
;
L_44:
;
; Line 90:		file->token = 0x444c;
;
	MOV	WORD [ESI+01DH],0444CH
;
; Line 91:		file->level = 0;
;
	MOV	DWORD [ESI+00H],00H
;
; Line 92:		file->fd = id;
;
	MOV	EAX,DWORD [EBP+0FFFFFFF4H]
	MOV	DWORD [ESI+08H],EAX
;
; Line 93:		file->flags |= flags;
;
	OR	DWORD [ESI+04H],EBX
;
; Line 94:		file->istemp = 0;
;
	MOV	DWORD [ESI+019H],00H
;
; Line 95:		file->hold = 0;
;
	MOV	BYTE [ESI+0CH],00H
;
; Line 96:		if (flags & 0x0040                   )
;
	MOV	EAX,EBX
	AND	EAX,BYTE 040H
	JE	SHORT	L_46
;
; Line 97:			setvbuf(file,buf,1,512          );
;
	PUSH	DWORD 0200H
	PUSH	BYTE 01H
	PUSH	EDI
	PUSH	ESI
	CALL	_setvbuf
	ADD	ESP,BYTE 010H
	JMP	L_47
L_46:
;
; Line 99:			setvbuf(file,buf,2,512          );
;
	PUSH	DWORD 0200H
	PUSH	BYTE 02H
	PUSH	EDI
	PUSH	ESI
	CALL	_setvbuf
	ADD	ESP,BYTE 010H
L_47:
;
; Line 100:		flags |= 0x0004                   ;
;
	BTS	EBX,02H
;
; Line 101:		if (append) {
;
	CMP	DWORD [EBP+0FFFFFFECH],BYTE 00H
	JE	NEAR	L_48
;
; Line 102:			if (fseek(file,0,2)) {
;
	PUSH	BYTE 02H
	PUSH	BYTE 00H
	PUSH	ESI
	CALL	_fseek
	ADD	ESP,BYTE 0CH
	TEST	EAX,EAX
	JE	NEAR	L_50
L_1:
;
; Line 104:				free(fname);
;
	PUSH	DWORD [EBP+0FFFFFFFCH]
	CALL	_free
	POP	ECX
;
; Line 105:				free(file->buffer);
;
	PUSH	DWORD [ESI+011H]
	CALL	_free
	POP	ECX
;
; Line 106:				free(file);
;
	PUSH	ESI
	CALL	_free
	POP	ECX
;
; Line 107:				return 0;
;
	MOV	EAX,00H
	JMP	L_4
L_50:
;
; Line 109:			file->flags |= 0x800			 ;
;
	BTS	DWORD [ESI+04H],0BH
;
; Line 110:		}
;
L_48:
;
; Line 111:		_filenames[maxfiles] = fname;
;
	MOV	EAX,DWORD [_maxfiles]
	MOV	ECX,DWORD [EBP+0FFFFFFFCH]
	MOV	DWORD [EAX*4+__filenames+00H],ECX
;
; Line 112:		_pstreams[maxfiles++] = file;
;
	MOV	EAX,DWORD [_maxfiles]
	INC	DWORD [_maxfiles]
	MOV	DWORD [EAX*4+__pstreams+00H],ESI
;
; Line 113:		return file;
;
	MOV	EAX,ESI
L_4:
	POP	EDI
	POP	ESI
	POP	EBX
	MOV	ESP,EBP
	POP	EBP
	RET
[GLOBAL	_fopen]
;
; Line 116:	{
;
_fopen:
	PUSH	EBP
	MOV	EBP,ESP
;
; Line 117:		return _basefopen(name,mode,0);
;
	PUSH	BYTE 00H
	PUSH	DWORD [EBP+0CH]
	PUSH	DWORD [EBP+08H]
	CALL	__basefopen
	ADD	ESP,BYTE 0CH
L_52:
	POP	EBP
	RET


SECTION _TEXT
[EXTERN	_setvbuf]
[EXTERN	_free]
[EXTERN	_malloc]
[EXTERN	__ll_creat]
[EXTERN	_fseek]
[EXTERN	__ll_flags]
[EXTERN	__ll_open]

SECTION _DATA
[EXTERN	__filenames]
[EXTERN	_maxfiles]
[EXTERN	__pstreams]
[EXTERN	__dos_errno]
[EXTERN	_errno]
