// File: /workspace/github_c_makefile_star2_O0/serge-404[P]CPM32/cpm.c
// Function: load_program
int load_program( char *pfile)
{
    FILE *fp;
	int ordsize;
#ifdef __linux__
    char* drv="";
#else
    char drv[ _MAX_DRIVE];
#endif	
	char dir[ _MAX_DIR], fname[ _MAX_FNAME], ext[ _MAX_EXT];

   _splitpath( pfile, drv, dir, fname, ext);
#ifdef __linux__
	if ((access(pfile, F_OK) != 0) && uppercase_flag) {
		CharUpperX(fname);
		CharUpperX(ext);
		CharUpperX(scpm);
		CharUpperX(scom);
	}
#endif
	if (orion128) {
		if (stricmp(ext,"ORD")==0) ordfile=1;
		else if (stricmp(ext,"BRU")==0) ordfile=1;
		else if (stricmp(ext,"RKO")==0) ordfile=2;
	} 
	if ( drv[ 0] == '\0' && dir[ 0] == '\0') {
	   if ( ext[ 0] == '\0') {
		   _makepath( filename2, drv, dir, fname, scpm);
		   _searchenv( filename2, CPMPATH, filename);
		   if ( filename[ 0] == '\0') {
			   _makepath( filename2, drv, dir, fname, scom);
			   _searchenv( filename2, CPMPATH, filename);
		   }
	   } else {
		   _makepath( filename2, drv, dir, fname, ext);
		   if (ordfile) _searchenv( filename2, ORDPATH, filename);
		   else  _searchenv( filename2, CPMPATH, filename);
	   }
	   if ( filename[ 0] == '\0') return FALSE;
	   if (( fp = fopen( filename, "rb")) == NULL) return FALSE;
	   _splitpath( filename, drv, dir, fname, ext);
   } else if ( ext[ 0] == '\0'){
	   _makepath( filename, drv, dir, fname, scpm);
	   if (( fp = fopen( filename, "rb")) == NULL) {
		   _makepath( filename, drv, dir, fname, scom);
		   if (( fp = fopen( filename, "rb")) == NULL) return FALSE;
	   }
	   _splitpath( filename, drv, dir, fname, ext);
   } else {
	   if (( fp = fopen( pfile, "rb")) == NULL) return FALSE;
   }
	if (ordfile) {
		if (ordfile==2)											/* ftRko */
			fread( &(mem[0x100]), 1, 77, fp);                     /* skip RKO header */
		ordsize=fread( &(mem[0x100]), 1, 16, fp);
		if (ordsize==16)	{				/* read ordos header */
			ordsize=*((word*)&mem[0x100+10]);
			ordaddr=*((word*)&mem[0x100+8]);
			if (ordsize+ordaddr>=0xf400)
				ordsize=0xf400-ordaddr;
			if (ordsize>0)
				fread( &mem[ordaddr], 1, ordsize, fp);
		}
		else {
			fclose( fp);
			return FALSE;
		}
	}
	else fread( &(mem[0x100]), 1, BDOS_ORG-0x100, fp);
	fclose( fp);
    if ( stricmp( ext, "COM") == 0)
		cpm_version = 0x122;
    cpmdrv0 = cpm_drive[ 0] = (char *)malloc( strlen( drv) + strlen( dir) + 1);
#ifdef __linux__
	strcpy( cpm_drive[ 0], dir);
#else
	_makepath( cpm_drive[ 0], drv, dir, NULL, NULL);
#endif
    return TRUE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x340, %rsp            # imm = 0x340
movq %rdi, -0x10(%rbp)
leaq 0xa8e5(%rip), %rax      # 0x1857b
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
leaq -0x130(%rbp), %rdx
leaq -0x230(%rbp), %rcx
leaq -0x330(%rbp), %r8
callq 0xd6b0
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x2350
cmpl $0x0, %eax
je 0xdd05
cmpl $0x0, 0x10eba1(%rip)    # 0x11c874
je 0xdd05
leaq -0x230(%rbp), %rdi
callq 0xd640
leaq -0x330(%rbp), %rdi
callq 0xd640
leaq 0xd548(%rip), %rdi      # 0x1b23c
callq 0xd640
leaq 0xd541(%rip), %rdi      # 0x1b241
callq 0xd640
cmpl $0x0, 0x10d740(%rip)    # 0x11b44c
je 0xdd7e
leaq -0x330(%rbp), %rdi
leaq 0xa71a(%rip), %rsi      # 0x18436
callq 0xdbb0
cmpl $0x0, %eax
jne 0xdd32
movl $0x1, 0x10d720(%rip)    # 0x11b450
jmp 0xdd7c
leaq -0x330(%rbp), %rdi
leaq 0xa6fa(%rip), %rsi      # 0x1843a
callq 0xdbb0
cmpl $0x0, %eax
jne 0xdd56
movl $0x1, 0x10d6fc(%rip)    # 0x11b450
jmp 0xdd7a
leaq -0x330(%rbp), %rdi
leaq 0xa6da(%rip), %rsi      # 0x1843e
callq 0xdbb0
cmpl $0x0, %eax
jne 0xdd78
movl $0x2, 0x10d6d8(%rip)    # 0x11b450
jmp 0xdd7a
jmp 0xdd7c
jmp 0xdd7e
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0xdf0b
movsbl -0x130(%rbp), %eax
cmpl $0x0, %eax
jne 0xdf0b
movsbl -0x330(%rbp), %eax
cmpl $0x0, %eax
jne 0xde3a
movq -0x28(%rbp), %rsi
leaq -0x130(%rbp), %rdx
leaq -0x230(%rbp), %rcx
leaq 0x10eab9(%rip), %rdi    # 0x11c880
leaq 0xd46e(%rip), %r8       # 0x1b23c
callq 0xd8d0
leaq 0x10eaa6(%rip), %rdi    # 0x11c880
leaq 0xa661(%rip), %rsi      # 0x18442
leaq 0x10ee98(%rip), %rdx    # 0x11cc80
callq 0xdb40
movsbl 0x10ee8c(%rip), %eax    # 0x11cc80
cmpl $0x0, %eax
jne 0xde38
movq -0x28(%rbp), %rsi
leaq -0x130(%rbp), %rdx
leaq -0x230(%rbp), %rcx
leaq 0x10ea6e(%rip), %rdi    # 0x11c880
leaq 0xd428(%rip), %r8       # 0x1b241
callq 0xd8d0
leaq 0x10ea5b(%rip), %rdi    # 0x11c880
leaq 0xa616(%rip), %rsi      # 0x18442
leaq 0x10ee4d(%rip), %rdx    # 0x11cc80
callq 0xdb40
jmp 0xdea0
movq -0x28(%rbp), %rsi
leaq -0x130(%rbp), %rdx
leaq -0x230(%rbp), %rcx
leaq -0x330(%rbp), %r8
leaq 0x10ea26(%rip), %rdi    # 0x11c880
callq 0xd8d0
cmpl $0x0, 0x10d5ea(%rip)    # 0x11b450
je 0xde84
leaq 0x10ea11(%rip), %rdi    # 0x11c880
leaq 0xa5d4(%rip), %rsi      # 0x1844a
leaq 0x10ee03(%rip), %rdx    # 0x11cc80
callq 0xdb40
jmp 0xde9e
leaq 0x10e9f5(%rip), %rdi    # 0x11c880
leaq 0xa5b0(%rip), %rsi      # 0x18442
leaq 0x10ede7(%rip), %rdx    # 0x11cc80
callq 0xdb40
jmp 0xdea0
movsbl 0x10edd9(%rip), %eax    # 0x11cc80
cmpl $0x0, %eax
jne 0xdeb8
movl $0x0, -0x4(%rbp)
jmp 0xe186
leaq 0x10edc1(%rip), %rdi    # 0x11cc80
leaq 0xa58c(%rip), %rsi      # 0x18452
callq 0x2360
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0xdee1
movl $0x0, -0x4(%rbp)
jmp 0xe186
movq -0x28(%rbp), %rsi
leaq -0x130(%rbp), %rdx
leaq -0x230(%rbp), %rcx
leaq -0x330(%rbp), %r8
leaq 0x10ed7f(%rip), %rdi    # 0x11cc80
callq 0xd6b0
jmp 0xdffe
movsbl -0x330(%rbp), %eax
cmpl $0x0, %eax
jne 0xdfd4
movq -0x28(%rbp), %rsi
leaq -0x130(%rbp), %rdx
leaq -0x230(%rbp), %rcx
leaq 0x10ed4c(%rip), %rdi    # 0x11cc80
leaq 0xd301(%rip), %r8       # 0x1b23c
callq 0xd8d0
leaq 0x10ed39(%rip), %rdi    # 0x11cc80
leaq 0xa504(%rip), %rsi      # 0x18452
callq 0x2360
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0xdfad
movq -0x28(%rbp), %rsi
leaq -0x130(%rbp), %rdx
leaq -0x230(%rbp), %rcx
leaq 0x10ed0a(%rip), %rdi    # 0x11cc80
leaq 0xd2c4(%rip), %r8       # 0x1b241
callq 0xd8d0
leaq 0x10ecf7(%rip), %rdi    # 0x11cc80
leaq 0xa4c2(%rip), %rsi      # 0x18452
callq 0x2360
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0xdfab
movl $0x0, -0x4(%rbp)
jmp 0xe186
jmp 0xdfad
movq -0x28(%rbp), %rsi
leaq -0x130(%rbp), %rdx
leaq -0x230(%rbp), %rcx
leaq -0x330(%rbp), %r8
leaq 0x10ecb3(%rip), %rdi    # 0x11cc80
callq 0xd6b0
jmp 0xdffc
movq -0x10(%rbp), %rdi
leaq 0xa473(%rip), %rsi      # 0x18452
callq 0x2360
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0xdffa
movl $0x0, -0x4(%rbp)
jmp 0xe186
jmp 0xdffc
jmp 0xdffe
cmpl $0x0, 0x10d44b(%rip)    # 0x11b450
je 0xe0e4
cmpl $0x2, 0x10d43e(%rip)    # 0x11b450
jne 0xe035
movq 0xd1f5(%rip), %rdi      # 0x1b210
addq $0x100, %rdi            # imm = 0x100
movq -0x18(%rbp), %rcx
movl $0x1, %esi
movl $0x4d, %edx
callq 0x20c0
movq 0xd1d4(%rip), %rdi      # 0x1b210
addq $0x100, %rdi            # imm = 0x100
movq -0x18(%rbp), %rcx
movl $0x1, %esi
movl $0x10, %edx
callq 0x20c0
movl %eax, -0x1c(%rbp)
cmpl $0x10, -0x1c(%rbp)
jne 0xe0cd
movq 0xd1aa(%rip), %rax      # 0x1b210
movzwl 0x10a(%rax), %eax
movl %eax, -0x1c(%rbp)
movq 0xd199(%rip), %rax      # 0x1b210
movzwl 0x108(%rax), %eax
movl %eax, 0x10d3d0(%rip)    # 0x11b454
movl -0x1c(%rbp), %eax
addl 0x10d3c7(%rip), %eax    # 0x11b454
cmpl $0xf400, %eax           # imm = 0xF400
jl 0xe0a2
movl $0xf400, %eax           # imm = 0xF400
subl 0x10d3b5(%rip), %eax    # 0x11b454
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jle 0xe0cb
movq 0xd161(%rip), %rdi      # 0x1b210
movslq 0x10d39e(%rip), %rax    # 0x11b454
addq %rax, %rdi
movslq -0x1c(%rbp), %rdx
movq -0x18(%rbp), %rcx
movl $0x1, %esi
callq 0x20c0
jmp 0xe0e2
movq -0x18(%rbp), %rdi
callq 0x20d0
movl $0x0, -0x4(%rbp)
jmp 0xe186
jmp 0xe105
movq 0xd125(%rip), %rdi      # 0x1b210
addq $0x100, %rdi            # imm = 0x100
movq -0x18(%rbp), %rcx
movl $0x1, %esi
movl $0xfe00, %edx           # imm = 0xFE00
callq 0x20c0
movq -0x18(%rbp), %rdi
callq 0x20d0
leaq -0x330(%rbp), %rdi
leaq 0xa339(%rip), %rsi      # 0x18455
callq 0xdbb0
cmpl $0x0, %eax
jne 0xe12f
movw $0x122, 0xd0fd(%rip)    # imm = 0x122
movq -0x28(%rbp), %rdi
callq 0x20f0
movq %rax, -0x338(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x20f0
movq -0x338(%rbp), %rdi
addq %rax, %rdi
addq $0x1, %rdi
callq 0x22b0
movq %rax, 0x10d47b(%rip)    # 0x11b5e0
movq %rax, 0x10d354(%rip)    # 0x11b4c0
movq 0x10d46d(%rip), %rdi    # 0x11b5e0
leaq -0x130(%rbp), %rsi
callq 0x2090
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x340, %rsp            # imm = 0x340
popq %rbp
retq
nopw %cs:(%rax,%rax)