// File: /workspace/github_c_makefile_star2_O3/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:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rsi, %r14
cmpl $0x2, %edi
jl 0x1465
movl %edi, %eax
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
xorl %ecx, %ecx
leaq 0x1ceb(%rip), %rbx      # 0x3038
movl $0x1, %edx
leaq 0x1cb7(%rip), %rsi      # 0x3010
xorl %r12d, %r12d
xorl %edi, %edi
movq (%r14,%rdx,8), %r8
cmpb $0x2d, (%r8)
jne 0x13fe
incq %r8
movzbl (%r8), %r9d
cmpl $0x63, %r9d
jle 0x1396
leal -0x70(%r9), %r10d
cmpl $0x9, %r10d
ja 0x13b4
movslq (%rsi,%r10,4), %r9
addq %rsi, %r9
jmpq *%r9
movb $0x1, 0x3dbc(%rip)      # 0x5150
jmp 0x136c
cmpl $0x56, %r9d
je 0x13a9
cmpl $0x62, %r9d
jne 0x13c9
movl $0x1, %ecx
jmp 0x136c
movl $0x2, %r12d
xorl %r15d, %r15d
jmp 0x136c
cmpl $0x66, %r9d
je 0x13f2
cmpl $0x64, %r9d
jne 0x13ce
movb $0x1, 0x3d81(%rip)      # 0x5148
jmp 0x136c
testl %r9d, %r9d
je 0x1401
movl $0x1, %edi
jmp 0x136c
movb $0x1, 0x3d78(%rip)      # 0x5154
jmp 0x136c
movb $0x1, 0x3d73(%rip)      # 0x5158
jmp 0x136c
movl $0x1, %r12d
jmp 0x136c
movb $0x1, 0x3d53(%rip)      # 0x514c
jmp 0x136c
movq %r8, %rbx
incq %rdx
cmpq %rax, %rdx
jne 0x135e
testl %edi, %edi
sete -0x2a(%rbp)
testl %ecx, %ecx
sete -0x29(%rbp)
testl %r12d, %r12d
je 0x148b
leaq 0x1c1f(%rip), %rdi      # 0x3044
leaq 0x1fc1(%rip), %rsi      # 0x33ed
callq 0x11b0
movq %rax, 0x3d08(%rip)      # 0x5140
movl $0x2000, %ecx           # imm = 0x2000
movq %rax, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x1190
xorl %eax, %eax
cmpl $0x2, %r12d
setge %al
movl %eax, -0x30(%rbp)
movq 0x3b81(%rip), %rax      # 0x4fe0
movq %rax, -0x38(%rbp)
jmp 0x149a
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movq $0x0, -0x38(%rbp)
movb $0x1, -0x29(%rbp)
leaq 0x1bba(%rip), %rbx      # 0x3038
movl $0x0, -0x30(%rbp)
movb $0x1, -0x2a(%rbp)
jmp 0x149a
movq $0x0, -0x38(%rbp)
movl $0x0, -0x30(%rbp)
cmpb $0x1, 0x3ca7(%rip)      # 0x5148
jne 0x178c
leaq 0x1ef4(%rip), %r12      # 0x33a2
movq %r12, %rdi
movl $0x102, %esi            # imm = 0x102
callq 0x1150
testq %rax, %rax
jne 0x14dd
leaq 0x1f06(%rip), %r12      # 0x33cd
movq %r12, %rdi
movl $0x102, %esi            # imm = 0x102
callq 0x1150
testq %rax, %rax
je 0x1a1c
movq %rax, 0x3cd4(%rip)      # 0x51b8
leaq 0x1eea(%rip), %r13      # 0x33d5
movq %rax, %rdi
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3cc3(%rip)      # 0x51c0
testq %rax, %rax
je 0x1840
movq 0x3cab(%rip), %rdi      # 0x51b8
leaq 0x1eca(%rip), %r13      # 0x33de
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3ca5(%rip)      # 0x51c8
testq %rax, %rax
je 0x1840
movq 0x3c85(%rip), %rdi      # 0x51b8
leaq 0x1eb5(%rip), %r13      # 0x33ef
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3c87(%rip)      # 0x51d0
testq %rax, %rax
je 0x1840
movq 0x3c5f(%rip), %rdi      # 0x51b8
leaq 0x1ea2(%rip), %r13      # 0x3402
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3c69(%rip)      # 0x51d8
testq %rax, %rax
je 0x1840
movq 0x3c39(%rip), %rdi      # 0x51b8
leaq 0x1e8e(%rip), %r13      # 0x3414
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3c4b(%rip)      # 0x51e0
testq %rax, %rax
je 0x1840
movq 0x3c13(%rip), %rdi      # 0x51b8
leaq 0x1e7e(%rip), %r13      # 0x342a
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3bbd(%rip)      # 0x5178
testq %rax, %rax
je 0x1840
movq 0x3bed(%rip), %rdi      # 0x51b8
leaq 0x1e6b(%rip), %r13      # 0x343d
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3c07(%rip)      # 0x51e8
testq %rax, %rax
je 0x1840
movq 0x3bc7(%rip), %rdi      # 0x51b8
leaq 0x1e57(%rip), %r13      # 0x344f
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3be9(%rip)      # 0x51f0
testq %rax, %rax
je 0x1840
movq 0x3ba1(%rip), %rdi      # 0x51b8
leaq 0x1e49(%rip), %r13      # 0x3467
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3bcb(%rip)      # 0x51f8
testq %rax, %rax
je 0x1840
movq 0x3b7b(%rip), %rdi      # 0x51b8
leaq 0x1e3a(%rip), %r13      # 0x347e
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3bad(%rip)      # 0x5200
testq %rax, %rax
je 0x1840
movq 0x3b55(%rip), %rdi      # 0x51b8
leaq 0x1e29(%rip), %r13      # 0x3493
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3b8f(%rip)      # 0x5208
testq %rax, %rax
je 0x1840
movq 0x3b2f(%rip), %rdi      # 0x51b8
leaq 0x1e13(%rip), %r13      # 0x34a3
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3b71(%rip)      # 0x5210
testq %rax, %rax
je 0x1840
movq 0x3b09(%rip), %rdi      # 0x51b8
leaq 0x1dfc(%rip), %r13      # 0x34b2
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3b53(%rip)      # 0x5218
testq %rax, %rax
je 0x1840
movq 0x3ae3(%rip), %rdi      # 0x51b8
leaq 0x1de8(%rip), %r13      # 0x34c4
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3b35(%rip)      # 0x5220
testq %rax, %rax
je 0x1840
movq 0x3abd(%rip), %rdi      # 0x51b8
leaq 0x1d28(%rip), %r13      # 0x342a
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3a67(%rip)      # 0x5178
testq %rax, %rax
je 0x1840
movq 0x3a97(%rip), %rdi      # 0x51b8
leaq 0x1daa(%rip), %r13      # 0x34d2
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3a59(%rip)      # 0x5190
testq %rax, %rax
je 0x1840
movq 0x3a71(%rip), %rdi      # 0x51b8
leaq 0x1d98(%rip), %r13      # 0x34e6
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3a43(%rip)      # 0x51a0
testq %rax, %rax
je 0x1840
movq 0x3a4b(%rip), %rdi      # 0x51b8
leaq 0x1d84(%rip), %r13      # 0x34f8
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3a2d(%rip)      # 0x51b0
testq %rax, %rax
je 0x1840
cmpb $0x0, -0x2a(%rbp)
je 0x185e
leaq -0x48(%rbp), %rsi
movl $0x1, %edi
callq 0x1090
movq 0x3995(%rip), %rdx      # 0x5140
movl %r15d, %edi
movq -0x38(%rbp), %rsi
movl -0x30(%rbp), %ecx
callq 0x1120
movq %rax, 0x399f(%rip)      # 0x5160
movq %rbx, %rdi
callq 0x10b0
testl %eax, %eax
js 0x1876
leaq 0x1b0b(%rip), %rdi      # 0x32e3
leaq 0x105b(%rip), %rdx      # 0x283a
leaq 0x1089(%rip), %rcx      # 0x286f
leaq -0xe8(%rbp), %rsi
callq 0x1100
testl %eax, %eax
movb -0x29(%rbp), %r14b
jle 0x1832
movl %eax, %ebx
incq %rbx
movq -0xe8(%rbp), %rax
movq -0x10(%rax,%rbx,8), %rdi
addq $0x13, %rdi
callq 0x1a51
testl %eax, %eax
jne 0x1832
movq -0xe8(%rbp), %rax
movq -0x10(%rax,%rbx,8), %rdi
callq 0x1030
decq %rbx
cmpq $0x1, %rbx
ja 0x17ff
movq -0xe8(%rbp), %rdi
callq 0x1030
jmp 0x1882
leaq 0x1cba(%rip), %rdi      # 0x3501
movq %r13, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x10d0
movl $0x1, %ebx
jmp 0x1a08
movq (%r14), %rsi
leaq 0x17e7(%rip), %rdi      # 0x304f
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x10d0
jmp 0x1a08
movq %rbx, %rdi
callq 0x1a51
movb -0x29(%rbp), %r14b
movl 0x38df(%rip), %r9d      # 0x5168
movq 0x3890(%rip), %rsi      # 0x5120
movl 0x38d6(%rip), %edx      # 0x516c
movl 0x38d4(%rip), %ecx      # 0x5170
movl 0x38d1(%rip), %r8d      # 0x5174
testl %r9d, %r9d
jle 0x18b8
leaq 0x1a36(%rip), %rdi      # 0x32e5
xorl %eax, %eax
callq 0x10d0
jmp 0x18c6
leaq 0x1a7a(%rip), %rdi      # 0x3339
xorl %eax, %eax
callq 0x10d0
leaq 0x3893(%rip), %rdi      # 0x5160
callq 0x1080
cmpb $0x1, 0x386f(%rip)      # 0x5148
jne 0x1921
movq 0x389e(%rip), %rdi      # 0x5180
callq *0x3890(%rip)           # 0x5178
movq 0x3899(%rip), %rdi      # 0x5188
callq *0x3883(%rip)           # 0x5178
movq 0x389c(%rip), %rdi      # 0x5198
callq *0x388e(%rip)           # 0x5190
movq 0x389f(%rip), %rdi      # 0x51a8
callq *0x3891(%rip)           # 0x51a0
callq *0x389b(%rip)           # 0x51b0
movq 0x389c(%rip), %rdi      # 0x51b8
callq 0x1200
testb %r14b, %r14b
jne 0x19f5
leaq -0x58(%rbp), %rbx
movl $0x1, %edi
movq %rbx, %rsi
callq 0x1090
movq (%rbx), %rcx
movq 0x8(%rbx), %rax
subq -0x48(%rbp), %rcx
imulq $0x3e8, %rcx, %rcx      # imm = 0x3E8
subq -0x40(%rbp), %rax
movabsq $0x431bde82d7b634db, %rdx # imm = 0x431BDE82D7B634DB
imulq %rdx
movq %rdx, %rbx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x12, %rbx
addq %rax, %rbx
addq %rcx, %rbx
leaq -0xe8(%rbp), %r14
xorl %edi, %edi
movq %r14, %rsi
callq 0x11c0
imulq $0x3e8, (%r14), %rdi    # imm = 0x3E8
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
movq %rcx, %rax
imulq 0x8(%r14)
movq %rdx, %rsi
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rsi
addq %rax, %rsi
movq %rcx, %rax
imulq 0x20(%r14)
addq %rdi, %rsi
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
cvtsi2sd %rbx, %xmm0
movsd 0x1637(%rip), %xmm3     # 0x3008
divsd %xmm3, %xmm0
cvtsi2sd %rsi, %xmm1
divsd %xmm3, %xmm1
cvtsi2sd %rdx, %xmm2
divsd %xmm3, %xmm2
leaq 0x198a(%rip), %rdi      # 0x3378
movb $0x3, %al
callq 0x10d0
movq 0x3744(%rip), %rdi      # 0x5140
testq %rdi, %rdi
je 0x1a06
callq 0x10a0
xorl %ebx, %ebx
movl %ebx, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x19a7(%rip), %r12      # 0x33ca
movq %r12, %rdi
movl $0x102, %esi            # imm = 0x102
callq 0x1150
movq %rax, 0x3781(%rip)      # 0x51b8
testq %rax, %rax
jne 0x14e4
leaq 0x1cc4(%rip), %rdi      # 0x370b
callq 0x1070
jmp 0x1854