// File: /workspace/github_c_makefile_star2_O0/Joy-Division[P]tools-zoe/wvx-extract.c
// Function: main
int main( int argc, char **argv ) {
	
	char dirname[512] = {0};
	unsigned char temp[4];
	unsigned int numSamples, tableSize, game;
	FILE *f;
	
	if( argc < 3 ) {
		printf("Not enough args!\nUse: %s WVX-file game\n", argv[0]);
		printf("supported games are:\n%d (MGS1)\n%d (ZoE1 and MGS2HD)\n", mgs1, zoe1);
		return 1;
	}
	
	game = strtoul(argv[2], NULL, 10);
	if(!(game<NUMWVXGAMES)) {
		printf("Unsupported game %d!\nRun without args to see supported types.\n", game);
		return 1;
	}
	
	if( !(f = fopen( argv[1], "rb" ))) {
		printf("Couldnt open file %s\n", argv[1]);
		return 1;
	}
	
	sprintf( dirname, "%s-Samples", argv[1] );
	createDirectory(dirname);
	fseek( f, 4, SEEK_SET );
	fread( temp, 4, 1, f );
	tableSize = temp[0] << 24 | temp[1] << 16 | temp[2] << 8 | temp[3];
	numSamples = tableSize/0x10;
	printf( "%d samples in sample table\n", numSamples );
	
	
	processWvx(f, 0, dirname, numSamples, game);
	
	printf("Done.\n");
	fclose(f);
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x210(%rbp), %rdi
xorl %esi, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x1080
cmpl $0x3, -0x8(%rbp)
jge 0x1608
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0xa75(%rip), %rdi       # 0x2055
movb $0x0, %al
callq 0x1070
leaq 0xa8f(%rip), %rdi       # 0x207d
xorl %esi, %esi
movl $0x1, %edx
movb $0x0, %al
callq 0x1070
movl $0x1, -0x4(%rbp)
jmp 0x1785
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x10b0
movl %eax, -0x220(%rbp)
cmpl $0x2, -0x220(%rbp)
jb 0x164d
movl -0x220(%rbp), %esi
leaq 0xa78(%rip), %rdi       # 0x20b2
movb $0x0, %al
callq 0x1070
movl $0x1, -0x4(%rbp)
jmp 0x1785
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xa95(%rip), %rsi       # 0x20f1
callq 0x10a0
movq %rax, -0x228(%rbp)
cmpq $0x0, %rax
jne 0x1690
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x9a0(%rip), %rdi       # 0x201d
movb $0x0, %al
callq 0x1070
movl $0x1, -0x4(%rbp)
jmp 0x1785
leaq -0x210(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0xa4e(%rip), %rsi       # 0x20f4
movb $0x0, %al
callq 0x10c0
leaq -0x210(%rbp), %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x1040
movq -0x228(%rbp), %rdi
movl $0x4, %esi
xorl %edx, %edx
callq 0x1090
leaq -0x214(%rbp), %rdi
movq -0x228(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x1050
movzbl -0x214(%rbp), %eax
shll $0x18, %eax
movzbl -0x213(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movzbl -0x212(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movzbl -0x211(%rbp), %ecx
orl %ecx, %eax
movl %eax, -0x21c(%rbp)
movl -0x21c(%rbp), %eax
shrl $0x4, %eax
movl %eax, -0x218(%rbp)
movl -0x218(%rbp), %esi
leaq 0x9c4(%rip), %rdi       # 0x20ff
movb $0x0, %al
callq 0x1070
movq -0x228(%rbp), %rdi
leaq -0x210(%rbp), %rdx
movl -0x218(%rbp), %ecx
movl -0x220(%rbp), %r8d
xorl %esi, %esi
callq 0x12e0
leaq 0x9b0(%rip), %rdi       # 0x211b
movb $0x0, %al
callq 0x1070
movq -0x228(%rbp), %rdi
callq 0x1060
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq