// File: /workspace/github_c_makefile_star2_O0/jkbenaim[P]psfrag/psfrag.c
// Function: cmd_extract_aux
char *_cmd_extract_aux(int argc, char **argv, bool all)
{
	__label__ out_return, out_dbclose, out_unmap, out_finalize;
	char *msg = NULL;
	int rc;
	struct MappedFile_s m, outfile;
	int num, addr, size;
	char *outname = NULL;
	char pcode[6];

	switch (argc) {
	case 0 ... 2:
		msg = "must specify a Pokemon Stadium rom";
		goto out_return;
		break;
	case 3:
		if (!all) {
			msg = "must specify a fragment number";
			goto out_return;
		}
		break;
	default:
		break;
	}

	rc = DB_Init(&db, ":memory:");
	if (rc != SQLITE_OK) {
		msg = "DB_Init oopsed";
		goto out_return;
	}

	m = MappedFile_Open(argv[2], false);
	if (m.data == NULL) {
		msg = "couldn't open rom";
		goto out_dbclose;
	}

	if (m.size < (1048576 + 4096)) {
		msg = "rom too small";
		goto out_unmap;
	}

	get_pcode(pcode, m.data);
	rc = DB_FragSearch(db, m.data, m.size);
	if (rc != SQLITE_OK) {
		msg = "DB_FragSearch oopsed";
		goto out_unmap;
	}

	sqlite3_stmt *stmt = NULL;
	if (all) {
		rc = sqlite3_prepare_v2(
			db,
			"select num,addr,romsize from frags order by num;",
			-1, &stmt, NULL
		);
		if (rc != SQLITE_OK) {
			msg = "error in prepare (all)";
			goto out_finalize;
		}
	} else {
		num = atoi(argv[3]);
		rc = sqlite3_prepare_v2(
			db,
			"select num,addr,romsize from frags where num=?;",
			-1, &stmt, NULL
		);
		if (rc != SQLITE_OK) {
			msg = "error in prepare (one)";
			goto out_finalize;
		}
		rc = sqlite3_bind_int(stmt, 1, num);
		if (rc != SQLITE_OK) {
			msg = "error in bind";
			goto out_finalize;
		}
	}

	if (!all and (DB_GetAddrForNum(db, num) == -1)) {
		msg = "no fragment by that number";
		goto out_finalize;
	}

	while (SQLITE_DONE != (rc=sqlite3_step(stmt))) switch (rc) {
	case SQLITE_BUSY:
		break;
	case SQLITE_ERROR:
		msg = "sqlite3_step returned SQLITE_ERROR";
		goto out_finalize;
		break;
	case SQLITE_MISUSE:
		msg = "sqlite3_step returned SQLITE_MISUSE";
		goto out_finalize;
		break;
	default:
		msg = "sqlite3_step returned some other error";
		goto out_finalize;
		break;
	case SQLITE_ROW:
		num  = sqlite3_column_int(stmt, 0);
		addr = sqlite3_column_int(stmt, 1);
		size = sqlite3_column_int(stmt, 2);
		rc = asprintf(&outname, "%s-frag%03d.bin", pcode, num);
		if (rc == -1) {
			msg = "asprintf failed";
			goto out_finalize;
		}
		outfile = MappedFile_Create(outname, size);
		if (!outfile.data) {
			free(outname);
			msg = "couldn't open outfile";
			goto out_finalize;
		}
		memcpy(outfile.data, m.data + addr, size);
		free(outname);
		MappedFile_Close(outfile);
		break;
	}


out_finalize:
	sqlite3_finalize(stmt);
out_unmap:
	MappedFile_Close(m);
out_dbclose:
	DB_Close(db);
out_return:
	if (msg) {
		return msg;
	} else {
		return NULL;
	}

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movb %dl, %al
movl %edi, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x78(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0xbc(%rbp)
subl $0x3, %eax
jb 0x95d6
jmp 0x95c9
movl -0xbc(%rbp), %eax
subl $0x3, %eax
je 0x95e6
jmp 0x95fe
leaq 0xace34(%rip), %rax     # 0xb6411
movq %rax, -0x28(%rbp)
jmp 0x9991
testb $0x1, -0x19(%rbp)
jne 0x95fc
leaq 0xace62(%rip), %rax     # 0xb6455
movq %rax, -0x28(%rbp)
jmp 0x9991
jmp 0x9600
jmp 0x9600
leaq 0xd3d11(%rip), %rdi     # 0xdd318
leaq 0xacdb6(%rip), %rsi     # 0xb63c4
callq 0x9aa0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x962c
leaq 0xacdaa(%rip), %rax     # 0xb63cd
movq %rax, -0x28(%rbp)
jmp 0x9991
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
leaq -0x98(%rbp), %rdi
xorl %edx, %edx
callq 0xa410
movq -0x98(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x967a
leaq 0xacd6b(%rip), %rax     # 0xb63dc
movq %rax, -0x28(%rbp)
jmp 0x9985
cmpq $0x101000, -0x40(%rbp)  # imm = 0x101000
jae 0x9694
leaq 0xacd63(%rip), %rax     # 0xb63ee
movq %rax, -0x28(%rbp)
jmp 0x9963
leaq -0x7e(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0xa540
movq 0xd3c70(%rip), %rdi     # 0xdd318
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0xa020
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x96ce
leaq 0xacd37(%rip), %rax     # 0xb63fc
movq %rax, -0x28(%rbp)
jmp 0x9963
movq $0x0, -0xa0(%rbp)
testb $0x1, -0x19(%rbp)
je 0x971e
movq 0xd3c32(%rip), %rdi     # 0xdd318
leaq 0xad0b3(%rip), %rsi     # 0xb67a0
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
leaq -0xa0(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0x18820
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x971c
leaq 0xad0be(%rip), %rax     # 0xb67d1
movq %rax, -0x28(%rbp)
jmp 0x9957
jmp 0x979a
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x82c0
movl %eax, -0x64(%rbp)
movq 0xd3be3(%rip), %rdi     # 0xdd318
leaq 0xad0ac(%rip), %rsi     # 0xb67e8
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
leaq -0xa0(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0x18820
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x976b
leaq 0xad0b6(%rip), %rax     # 0xb6818
movq %rax, -0x28(%rbp)
jmp 0x9957
movq -0xa0(%rbp), %rdi
movl -0x64(%rbp), %edx
movl $0x1, %esi
callq 0x15330
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x9798
leaq 0xad0a0(%rip), %rax     # 0xb682f
movq %rax, -0x28(%rbp)
jmp 0x9957
jmp 0x979a
testb $0x1, -0x19(%rbp)
jne 0x97c4
movq 0xd3b71(%rip), %rdi     # 0xdd318
movl -0x64(%rbp), %esi
callq 0x9f00
cmpl $-0x1, %eax
jne 0x97c4
leaq 0xaccb9(%rip), %rax     # 0xb6474
movq %rax, -0x28(%rbp)
jmp 0x9957
jmp 0x97c6
movq -0xa0(%rbp), %rdi
callq 0x14020
movl %eax, %ecx
movl %ecx, -0x2c(%rbp)
movl $0x65, %eax
cmpl %ecx, %eax
je 0x9955
movl -0x2c(%rbp), %eax
movl %eax, -0xc0(%rbp)
subl $0x1, %eax
je 0x9820
jmp 0x97f4
movl -0xc0(%rbp), %eax
subl $0x5, %eax
je 0x981b
jmp 0x9801
movl -0xc0(%rbp), %eax
subl $0x15, %eax
je 0x9830
jmp 0x980e
movl -0xc0(%rbp), %eax
subl $0x64, %eax
je 0x9850
jmp 0x9840
jmp 0x9950
leaq 0xacad9(%rip), %rax     # 0xb6300
movq %rax, -0x28(%rbp)
jmp 0x9957
leaq 0xacaec(%rip), %rax     # 0xb6323
movq %rax, -0x28(%rbp)
jmp 0x9957
leaq 0xacb00(%rip), %rax     # 0xb6347
movq %rax, -0x28(%rbp)
jmp 0x9957
movq -0xa0(%rbp), %rdi
xorl %esi, %esi
callq 0x14bf0
movl %eax, -0x64(%rbp)
movq -0xa0(%rbp), %rdi
movl $0x1, %esi
callq 0x14bf0
movl %eax, -0x68(%rbp)
movq -0xa0(%rbp), %rdi
movl $0x2, %esi
callq 0x14bf0
movl %eax, -0x6c(%rbp)
leaq -0x7e(%rbp), %rdx
movl -0x64(%rbp), %ecx
leaq -0x78(%rbp), %rdi
leaq 0xacbf4(%rip), %rsi     # 0xb648f
movb $0x0, %al
callq 0x8240
movl %eax, -0x2c(%rbp)
cmpl $-0x1, -0x2c(%rbp)
jne 0x98bb
leaq 0xacf8b(%rip), %rax     # 0xb683d
movq %rax, -0x28(%rbp)
jmp 0x9957
movq -0x78(%rbp), %rsi
movslq -0x6c(%rbp), %rdx
leaq -0xb8(%rbp), %rdi
callq 0xa300
movq -0xb8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x990d
movq -0x78(%rbp), %rdi
callq 0x8050
leaq 0xacb98(%rip), %rax     # 0xb649f
movq %rax, -0x28(%rbp)
jmp 0x9957
movq -0x60(%rbp), %rdi
movq -0x48(%rbp), %rsi
movslq -0x68(%rbp), %rax
addq %rax, %rsi
movslq -0x6c(%rbp), %rdx
callq 0x81d0
movq -0x78(%rbp), %rdi
callq 0x8050
leaq -0x60(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0xa510
jmp 0x97c6
jmp 0x9957
movq -0xa0(%rbp), %rdi
callq 0x12580
leaq -0x48(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0xa510
movq 0xd398c(%rip), %rdi     # 0xdd318
callq 0x9b20
cmpq $0x0, -0x28(%rbp)
je 0x99a2
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x99aa
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq
nopw (%rax,%rax)