// File: /workspace/github_c_makefile_star2_O0/tvlabs[P]edge264/edge264_test.c
// Function: main
int main(int argc, char *argv[])
{
	// read command-line options
	const char *file_name = "conformance";
	int benchmark = 0;
	int help = 0;
	int n_threads = -1;
	int trace = 0;
	for (int i = 1; i < argc; i++) {
		if (argv[i][0] != '-') {
			file_name = argv[i];
		} else for (int j = 1; argv[i][j]; j++) {
			switch (argv[i][j]) {
				case 'b': benchmark = 1; break;
				case 'd': display = 1; break;
				case 'f': print_failed = 1; break;
				case 'p': print_passed = 1; break;
				case 's': n_threads = 0; break;
				case 'u': print_unsupported = 1; break;
				case 'v': trace = 1; break;
				case 'V': trace = 2; n_threads = 0; break;
				case 'y': enable_yuv = 0; break;
				default: help = 1; break;
			}
		}
	}
	if (trace) {
		trace_file = fopen("trace.yaml", "w");
		setvbuf(trace_file, NULL, _IONBF, BUFSIZ);
	}
	
	// load SDL2 if requested
	if (display && load_SDL2())
		return 1;
	
	// print help if any argument was unknown
	if (help) {
		printf("Usage: " BOLD "%s [video.264|directory] [-hbdfpsuvVy]" RESET "\n"
			"Decodes a video or all videos inside a directory (./conformance by default),\n"
			"comparing their outputs with inferred YUV pairs (.yuv and .1.yuv extensions).\n"
			"-h\tprint this help and exit\n"
			"-b\tbenchmark decoding time and memory usage\n"
			"-d\tenable display of the videos (requires SDL2)\n"
			"-f\tprint names of failed files in directory\n"
			"-p\tprint names of passed files in directory\n"
			"-s\tsingle-threaded operation\n"
			"-u\tprint names of unsupported files in directory\n"
			"-v\tenable output of headers to file trace.yaml (large)\n"
			"-V\tadd output of macroblocks to trace.yaml (very large, implies -vs)\n"
			"-y\tdisable comparison against YUV pairs\n"
			, argv[0]);
		return 0;
	}
	
	struct timespec t0, t1;
	clock_gettime(CLOCK_MONOTONIC, &t0);
	d = edge264_alloc(n_threads, trace ? (void(*)(const char*, void*))fputs : NULL, trace_file, trace > 1);
	
	// check if input is a directory by trying to move into it
	if (chdir(file_name) < 0) {
		decode_file(file_name);
	} else {
		#ifdef _WIN32
			DIR *dp;
			struct dirent *ep;
			dp = opendir(".");
			while ((ep = readdir(dp)) && !decode_file(ep->d_name));
			closedir(dp);
		#else
			struct dirent **entries;
			int n = scandir(".", &entries, flt, cmp);
			while (--n >= 0 && !decode_file(entries[n]->d_name))
				free(entries[n]);
			free(entries);
		#endif
	}
	
	if (count_flag > 0)
		printf("%s%d " GREEN "PASS" RESET ", %d " YELLOW "UNSUPPORTED" RESET ", %d " RED "FAIL" RESET ", %d " BLUE "FLAGGED" RESET "\n", moveup, count_pass, count_unsup, count_fail, count_flag);
	else
		printf("%s%d " GREEN "PASS" RESET ", %d " YELLOW "UNSUPPORTED" RESET ", %d " RED "FAIL" RESET "\n", moveup, count_pass, count_unsup, count_fail);
	edge264_free(&d);
	
	// close SDL if enabled
	if (display) {
		SDL_DestroyTexture(texture0);
		SDL_DestroyTexture(texture1);
		SDL_DestroyRenderer(renderer);
		SDL_DestroyWindow(window);
		SDL_Quit();
		dlclose(sdl2);
	}
	
	// closing information
	if (benchmark) {
		clock_gettime(CLOCK_MONOTONIC, &t1);
		int64_t time_msec = (int64_t)(t1.tv_sec - t0.tv_sec) * 1000 + (t1.tv_nsec - t0.tv_nsec) / 1000000;
		#ifdef _WIN32
			HANDLE p = GetCurrentProcess();
			FILETIME c, e, k, u;
			GetProcessTimes(p, &c, &e, &k, &u);
			int64_t cpu_msec = ((int64_t)u.dwHighDateTime << 32 | u.dwLowDateTime) / 10000;
			PROCESS_MEMORY_COUNTERS m;
			GetProcessMemoryInfo(p, &m, sizeof(m));
			int mem_kb = m.PeakPagefileUsage / 1000;
		#else
			struct rusage rusage;
			getrusage(RUSAGE_SELF, &rusage);
			int64_t cpu_msec = (int64_t)rusage.ru_utime.tv_sec * 1000 + rusage.ru_utime.tv_usec / 1000;
			long mem_kb = rusage.ru_maxrss / 1000;
		#endif
		printf("time: %.3lfs\nCPU: %.3lfs\nmemory: %.3lfMB\n", (double)time_msec / 1000, (double)cpu_msec / 1000, (double)mem_kb / 1000);
	}
	if (trace_file)
		fclose(trace_file);
	return 0;
}

// Assembly:
subq $0x128, %rsp            # imm = 0x128
movl $0x0, 0x124(%rsp)
movl %edi, 0x120(%rsp)
movq %rsi, 0x118(%rsp)
leaq 0x2d78(%rip), %rax      # 0x40a0
movq %rax, 0x110(%rsp)
movl $0x0, 0x10c(%rsp)
movl $0x0, 0x108(%rsp)
movl $0xffffffff, 0x104(%rsp) # imm = 0xFFFFFFFF
movl $0x0, 0x100(%rsp)
movl $0x1, 0xfc(%rsp)
movl 0xfc(%rsp), %eax
cmpl 0x120(%rsp), %eax
jge 0x14e9
movq 0x118(%rsp), %rax
movslq 0xfc(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0x13b8
movq 0x118(%rsp), %rax
movslq 0xfc(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x110(%rsp)
jmp 0x14d1
movl $0x1, 0xf8(%rsp)
movq 0x118(%rsp), %rax
movslq 0xfc(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0xf8(%rsp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x14cf
movq 0x118(%rsp), %rax
movslq 0xfc(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0xf8(%rsp), %rcx
movsbl (%rax,%rcx), %eax
addl $-0x56, %eax
movl %eax, %ecx
movq %rcx, 0x18(%rsp)
subl $0x23, %eax
ja 0x14ac
movq 0x18(%rsp), %rax
leaq 0x2be8(%rip), %rcx      # 0x4010
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x1, 0x10c(%rsp)
jmp 0x14b7
movl $0x1, 0x4cf0(%rip)      # 0x6138
jmp 0x14b7
movl $0x1, 0x4ce8(%rip)      # 0x613c
jmp 0x14b7
movl $0x1, 0x4ce0(%rip)      # 0x6140
jmp 0x14b7
movl $0x0, 0x104(%rsp)
jmp 0x14b7
movl $0x1, 0x4ccb(%rip)      # 0x6144
jmp 0x14b7
movl $0x1, 0x100(%rsp)
jmp 0x14b7
movl $0x2, 0x100(%rsp)
movl $0x0, 0x104(%rsp)
jmp 0x14b7
movl $0x0, 0x4c66(%rip)      # 0x6110
jmp 0x14b7
movl $0x1, 0x108(%rsp)
jmp 0x14b9
movl 0xf8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf8(%rsp)
jmp 0x13c3
jmp 0x14d1
jmp 0x14d3
movl 0xfc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xfc(%rsp)
jmp 0x1367
cmpl $0x0, 0x100(%rsp)
je 0x1527
leaq 0x2bb2(%rip), %rdi      # 0x40ac
leaq 0x2fde(%rip), %rsi      # 0x44df
callq 0x1190
movq %rax, 0x4c23(%rip)      # 0x6130
movq 0x4c1c(%rip), %rdi      # 0x6130
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
movl $0x2000, %ecx           # imm = 0x2000
callq 0x1170
cmpl $0x0, 0x4c0a(%rip)      # 0x6138
je 0x154a
callq 0x1890
cmpl $0x0, %eax
je 0x154a
movl $0x1, 0x124(%rsp)
jmp 0x187e
cmpl $0x0, 0x108(%rsp)
je 0x157d
movq 0x118(%rsp), %rax
movq (%rax), %rsi
leaq 0x2b51(%rip), %rdi      # 0x40b7
movb $0x0, %al
callq 0x10b0
movl $0x0, 0x124(%rsp)
jmp 0x187e
movl $0x1, %edi
leaq 0xe8(%rsp), %rsi
callq 0x1070
movl 0x104(%rsp), %edi
movl 0x100(%rsp), %ecx
xorl %eax, %eax
movl %eax, %esi
movq 0x4a38(%rip), %rax      # 0x5fe0
cmpl $0x0, %ecx
cmovneq %rax, %rsi
movq 0x4b7a(%rip), %rdx      # 0x6130
cmpl $0x1, 0x100(%rsp)
setg %al
andb $0x1, %al
movzbl %al, %ecx
callq 0x1100
movq %rax, 0x4b76(%rip)      # 0x6148
movq 0x110(%rsp), %rdi
callq 0x1090
cmpl $0x0, %eax
jge 0x15f6
movq 0x110(%rsp), %rdi
callq 0x1ce0
jmp 0x1696
leaq 0x2d4e(%rip), %rdi      # 0x434b
leaq 0xd0(%rsp), %rsi
leaq 0xda4(%rip), %rdx       # 0x23b0
leaq 0xdfd(%rip), %rcx       # 0x2410
callq 0x10e0
movl %eax, 0xcc(%rsp)
movl 0xcc(%rsp), %ecx
addl $-0x1, %ecx
movl %ecx, 0xcc(%rsp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0x17(%rsp)
jl 0x1664
movq 0xd0(%rsp), %rax
movslq 0xcc(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
addq $0x13, %rdi
callq 0x1ce0
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, 0x17(%rsp)
movb 0x17(%rsp), %al
testb $0x1, %al
jne 0x166e
jmp 0x1689
movq 0xd0(%rsp), %rax
movslq 0xcc(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1030
jmp 0x161f
movq 0xd0(%rsp), %rdi
callq 0x1030
cmpl $0x0, 0x4ab3(%rip)      # 0x6150
jle 0x16d0
movq 0x4a72(%rip), %rsi      # 0x6118
movl 0x4aa8(%rip), %edx      # 0x6154
movl 0x4aa6(%rip), %ecx      # 0x6158
movl 0x4aa3(%rip), %r8d      # 0x615c
movl 0x4a90(%rip), %r9d      # 0x6150
leaq 0x2c86(%rip), %rdi      # 0x434d
movb $0x0, %al
callq 0x10b0
jmp 0x16f8
movq 0x4a41(%rip), %rsi      # 0x6118
movl 0x4a77(%rip), %edx      # 0x6154
movl 0x4a75(%rip), %ecx      # 0x6158
movl 0x4a72(%rip), %r8d      # 0x615c
leaq 0x2cb0(%rip), %rdi      # 0x43a1
movb $0x0, %al
callq 0x10b0
leaq 0x4a49(%rip), %rdi      # 0x6148
callq 0x1060
cmpl $0x0, 0x4a2d(%rip)      # 0x6138
je 0x175f
movq 0x4a4c(%rip), %rax      # 0x6160
movq 0x4a4d(%rip), %rdi      # 0x6168
callq *%rax
movq 0x4a3c(%rip), %rax      # 0x6160
movq 0x4a45(%rip), %rdi      # 0x6170
callq *%rax
movq 0x4a44(%rip), %rax      # 0x6178
movq 0x4a45(%rip), %rdi      # 0x6180
callq *%rax
movq 0x4a44(%rip), %rax      # 0x6188
movq 0x4a45(%rip), %rdi      # 0x6190
callq *%rax
callq *0x4a45(%rip)           # 0x6198
movq 0x4a46(%rip), %rdi      # 0x61a0
callq 0x11e0
cmpl $0x0, 0x10c(%rsp)
je 0x185d
movl $0x1, %edi
leaq 0xd8(%rsp), %rsi
callq 0x1070
movq 0xd8(%rsp), %rax
subq 0xe8(%rsp), %rax
imulq $0x3e8, %rax, %rax      # imm = 0x3E8
movq %rax, (%rsp)
movq 0xe0(%rsp), %rax
subq 0xf0(%rsp), %rax
movl $0xf4240, %ecx          # imm = 0xF4240
cqto
idivq %rcx
movq %rax, %rcx
movq (%rsp), %rax
addq %rcx, %rax
movq %rax, 0xc0(%rsp)
xorl %edi, %edi
leaq 0x30(%rsp), %rsi
callq 0x11a0
imulq $0x3e8, 0x30(%rsp), %rax # imm = 0x3E8
movq %rax, 0x8(%rsp)
movq 0x38(%rsp), %rax
movl $0x3e8, %ecx            # imm = 0x3E8
cqto
idivq %rcx
movq %rax, %rcx
movq 0x8(%rsp), %rax
addq %rcx, %rax
movq %rax, 0x28(%rsp)
movq 0x50(%rsp), %rax
movl $0x3e8, %ecx            # imm = 0x3E8
cqto
idivq %rcx
movq %rax, 0x20(%rsp)
vcvtsi2sdq 0xc0(%rsp), %xmm0, %xmm0
vmovsd 0x27e3(%rip), %xmm1     # 0x4008
vdivsd %xmm1, %xmm0, %xmm0
vcvtsi2sdq 0x28(%rsp), %xmm1, %xmm1
vmovsd 0x27d0(%rip), %xmm2     # 0x4008
vdivsd %xmm2, %xmm1, %xmm1
vcvtsi2sdq 0x20(%rsp), %xmm2, %xmm2
vmovsd 0x27bd(%rip), %xmm3     # 0x4008
vdivsd %xmm3, %xmm2, %xmm2
leaq 0x2b8a(%rip), %rdi      # 0x43e0
movb $0x3, %al
callq 0x10b0
cmpq $0x0, 0x48cb(%rip)      # 0x6130
je 0x1873
movq 0x48c2(%rip), %rdi      # 0x6130
callq 0x1080
movl $0x0, 0x124(%rsp)
movl 0x124(%rsp), %eax
addq $0x128, %rsp            # imm = 0x128
retq
nopl (%rax)