// File: /workspace/github_c_makefile_star2_O0/Mikejmoffitt[P]romtools/binvert/binvert.c
// Function: main
int main(int argc, char **argv)
{
	FILE *fi, *fo;
	size_t fsize;
	char *buf;

	if (argc < 3)
	{
		printf("Usage: %s in_fname out_fname\n", argv[0]);
		return 0;
	}

	fi = fopen(argv[1], "rb");
	if (!fi)
	{
		fprintf(stderr, "Couldn't open %s for reading.\n",
		        argv[1]);
		return 1;
	}

	fseek(fi, 0L, SEEK_END);
	fsize = ftell(fi);
	fseek(fi, 0L, SEEK_SET);

	buf = (char *)malloc(sizeof(char) * fsize);
	if (!buf)
	{
		fprintf(stderr, "Couldn't allocate %zu for buffer.\n", fsize);
		fclose(fi);
		return 1;
	}

	fo = fopen(argv[2], "wb");
	if (!fo)
	{
		fclose(fi);
		free(buf);
		fprintf(stderr, "Couldn't open %s for writing.\n", argv[2]);
		return 1;
	}

	for (size_t i = 0; i < fsize; i++)
	{
		buf[fsize - i - 1] = fgetc(fi);
	}

	fwrite((void *)buf, fsize, 1, fo);

	printf("Wrote %zu ($%X) bytes to %s.\n", fsize, (int)fsize, argv[2]);

	fclose(fi);
	fclose(fo);
	free(buf);
}

// Assembly:
subq $0x38, %rsp
movl $0x0, 0x34(%rsp)
movl %edi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
cmpl $0x3, 0x30(%rsp)
jge 0x120f
movq 0x28(%rsp), %rax
movq (%rax), %rsi
leaq 0xe09(%rip), %rdi       # 0x2004
movb $0x0, %al
callq 0x1050
movl $0x0, 0x34(%rsp)
jmp 0x13e0
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0xe03(%rip), %rsi       # 0x2022
callq 0x10b0
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
jne 0x125f
movq 0x2dc0(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdx
leaq 0xdda(%rip), %rsi       # 0x2025
movb $0x0, %al
callq 0x1070
movl $0x1, 0x34(%rsp)
jmp 0x13e0
movq 0x20(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x10a0
movq 0x20(%rsp), %rdi
callq 0x1080
movq %rax, 0x10(%rsp)
movq 0x20(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x10a0
movq 0x10(%rsp), %rdi
shlq $0x0, %rdi
callq 0x1090
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x8(%rsp)
jne 0x12e0
movq 0x2d45(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq 0x10(%rsp), %rdx
leaq 0xd82(%rip), %rsi       # 0x2044
movb $0x0, %al
callq 0x1070
movq 0x20(%rsp), %rdi
callq 0x1040
movl $0x1, 0x34(%rsp)
jmp 0x13e0
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rdi
leaq 0xd77(%rip), %rsi       # 0x2067
callq 0x10b0
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
jne 0x1344
movq 0x20(%rsp), %rdi
callq 0x1040
movq 0x8(%rsp), %rdi
callq 0x1030
movq 0x2cdb(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rdx
leaq 0xd3a(%rip), %rsi       # 0x206a
movb $0x0, %al
callq 0x1070
movl $0x1, 0x34(%rsp)
jmp 0x13e0
movq $0x0, (%rsp)
movq (%rsp), %rax
cmpq 0x10(%rsp), %rax
jae 0x1386
movq 0x20(%rsp), %rdi
callq 0x1060
movb %al, %dl
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
subq (%rsp), %rcx
subq $0x1, %rcx
movb %dl, (%rax,%rcx)
movq (%rsp), %rax
addq $0x1, %rax
movq %rax, (%rsp)
jmp 0x134c
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
movl $0x1, %edx
callq 0x10c0
movq 0x10(%rsp), %rsi
movq 0x10(%rsp), %rax
movl %eax, %edx
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rcx
leaq 0xcce(%rip), %rdi       # 0x2089
movb $0x0, %al
callq 0x1050
movq 0x20(%rsp), %rdi
callq 0x1040
movq 0x18(%rsp), %rdi
callq 0x1040
movq 0x8(%rsp), %rdi
callq 0x1030
movl 0x34(%rsp), %eax
addq $0x38, %rsp
retq