// File: /workspace/github_c_makefile_star2_O2/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, %r15
movslq %edi, %rax
leaq 0x1cfb(%rip), %r11      # 0x3038
pushq $-0x1
popq %r14
xorl %ebx, %ebx
pushq $0x1
popq %rcx
pushq $0x1
popq %rdx
pushq $0x2
popq %rsi
leaq 0x1cbd(%rip), %rdi      # 0x3010
xorl %r13d, %r13d
xorl %r12d, %r12d
cmpq %rax, %rcx
jge 0x13fb
movq (%r15,%rcx,8), %r8
cmpb $0x2d, (%r8)
jne 0x13f0
incq %r8
movzbl (%r8), %r9d
leal -0x70(%r9), %r10d
cmpl $0x9, %r10d
ja 0x1394
movslq (%rdi,%r10,4), %r9
addq %rdi, %r9
jmpq *%r9
movb $0x1, 0x3dbe(%rip)      # 0x5150
jmp 0x1370
cmpl $0x56, %r9d
je 0x13e3
cmpl $0x62, %r9d
je 0x13eb
cmpl $0x64, %r9d
je 0x13d1
cmpl $0x66, %r9d
je 0x13da
testl %r9d, %r9d
je 0x13f3
movl %edx, %ebx
jmp 0x1370
xorl %r14d, %r14d
jmp 0x1370
movl %edx, %r13d
jmp 0x1370
movb $0x1, 0x3d8e(%rip)      # 0x5154
jmp 0x1370
movb $0x1, 0x3d89(%rip)      # 0x5158
jmp 0x1370
movb $0x1, 0x3d70(%rip)      # 0x5148
jmp 0x1370
movb $0x1, 0x3d6b(%rip)      # 0x514c
jmp 0x1370
xorl %r14d, %r14d
movl %esi, %r13d
jmp 0x1370
movl %edx, %r12d
jmp 0x1370
movq %r8, %r11
incq %rcx
jmp 0x1359
movq %r11, -0x40(%rbp)
testl %r13d, %r13d
je 0x1430
leaq 0x1c39(%rip), %rdi      # 0x3044
leaq 0x1fdb(%rip), %rsi      # 0x33ed
callq 0x11b0
movq %rax, 0x3d22(%rip)      # 0x5140
pushq $0x2
popq %rdx
movl $0x2000, %ecx           # imm = 0x2000
movq %rax, %rdi
xorl %esi, %esi
callq 0x1190
cmpb $0x1, 0x3d11(%rip)      # 0x5148
jne 0x172a
leaq 0x1f5e(%rip), %rdi      # 0x33a2
movq %rdi, -0x38(%rbp)
movl $0x102, %esi            # imm = 0x102
callq 0x1150
testq %rax, %rax
jne 0x1475
leaq 0x1f6f(%rip), %rdi      # 0x33cd
movq %rdi, -0x38(%rbp)
movl $0x102, %esi            # imm = 0x102
callq 0x1150
testq %rax, %rax
je 0x1989
movq %rax, 0x3d3c(%rip)      # 0x51b8
leaq 0x1f52(%rip), %rsi      # 0x33d5
movq %rax, %rdi
movq %rsi, -0x30(%rbp)
callq 0x11e0
movq %rax, 0x3d2a(%rip)      # 0x51c0
testq %rax, %rax
je 0x1746
movq 0x3d12(%rip), %rdi      # 0x51b8
leaq 0x1f31(%rip), %rsi      # 0x33de
movq %rsi, -0x30(%rbp)
callq 0x11e0
movq %rax, 0x3d0b(%rip)      # 0x51c8
testq %rax, %rax
je 0x1746
movq 0x3ceb(%rip), %rdi      # 0x51b8
leaq 0x1f1b(%rip), %rsi      # 0x33ef
movq %rsi, -0x30(%rbp)
callq 0x11e0
movq %rax, 0x3cec(%rip)      # 0x51d0
testq %rax, %rax
je 0x1746
movq 0x3cc4(%rip), %rdi      # 0x51b8
leaq 0x1f07(%rip), %rsi      # 0x3402
movq %rsi, -0x30(%rbp)
callq 0x11e0
movq %rax, 0x3ccd(%rip)      # 0x51d8
testq %rax, %rax
je 0x1746
movq 0x3c9d(%rip), %rdi      # 0x51b8
leaq 0x1ef2(%rip), %rsi      # 0x3414
movq %rsi, -0x30(%rbp)
callq 0x11e0
movq %rax, 0x3cae(%rip)      # 0x51e0
testq %rax, %rax
je 0x1746
movq 0x3c76(%rip), %rdi      # 0x51b8
leaq 0x1ee1(%rip), %rsi      # 0x342a
movq %rsi, -0x30(%rbp)
callq 0x11e0
movq %rax, 0x3c1f(%rip)      # 0x5178
testq %rax, %rax
je 0x1746
movq 0x3c4f(%rip), %rdi      # 0x51b8
leaq 0x1ecd(%rip), %rsi      # 0x343d
movq %rsi, -0x30(%rbp)
callq 0x11e0
movq %rax, 0x3c68(%rip)      # 0x51e8
testq %rax, %rax
je 0x1746
movq 0x3c28(%rip), %rdi      # 0x51b8
leaq 0x1eb8(%rip), %rsi      # 0x344f
movq %rsi, -0x30(%rbp)
callq 0x11e0
movq %rax, 0x3c49(%rip)      # 0x51f0
testq %rax, %rax
je 0x1746
movq 0x3c01(%rip), %rdi      # 0x51b8
leaq 0x1ea9(%rip), %rsi      # 0x3467
movq %rsi, -0x30(%rbp)
callq 0x11e0
movq %rax, 0x3c2a(%rip)      # 0x51f8
testq %rax, %rax
je 0x1746
movq 0x3bda(%rip), %rdi      # 0x51b8
leaq 0x1e99(%rip), %rsi      # 0x347e
movq %rsi, -0x30(%rbp)
callq 0x11e0
movq %rax, 0x3c0b(%rip)      # 0x5200
testq %rax, %rax
je 0x1746
movq 0x3bb3(%rip), %rdi      # 0x51b8
leaq 0x1e87(%rip), %rsi      # 0x3493
movq %rsi, -0x30(%rbp)
callq 0x11e0
movq %rax, 0x3bec(%rip)      # 0x5208
testq %rax, %rax
je 0x1746
movq 0x3b8c(%rip), %rdi      # 0x51b8
leaq 0x1e70(%rip), %rsi      # 0x34a3
movq %rsi, -0x30(%rbp)
callq 0x11e0
movq %rax, 0x3bcd(%rip)      # 0x5210
testq %rax, %rax
je 0x1746
movq 0x3b65(%rip), %rdi      # 0x51b8
leaq 0x1e58(%rip), %rsi      # 0x34b2
movq %rsi, -0x30(%rbp)
callq 0x11e0
movq %rax, 0x3bae(%rip)      # 0x5218
testq %rax, %rax
je 0x1746
movq 0x3b3e(%rip), %rdi      # 0x51b8
leaq 0x1e43(%rip), %rsi      # 0x34c4
movq %rsi, -0x30(%rbp)
callq 0x11e0
movq %rax, 0x3b8f(%rip)      # 0x5220
testq %rax, %rax
je 0x1746
movq 0x3b17(%rip), %rdi      # 0x51b8
leaq 0x1d82(%rip), %rsi      # 0x342a
movq %rsi, -0x30(%rbp)
callq 0x11e0
movq %rax, 0x3ac0(%rip)      # 0x5178
testq %rax, %rax
je 0x1746
movq 0x3af0(%rip), %rdi      # 0x51b8
leaq 0x1e03(%rip), %rsi      # 0x34d2
movq %rsi, -0x30(%rbp)
callq 0x11e0
movq %rax, 0x3ab1(%rip)      # 0x5190
testq %rax, %rax
je 0x1746
movq 0x3acd(%rip), %rdi      # 0x51b8
leaq 0x1df4(%rip), %rsi      # 0x34e6
movq %rsi, -0x30(%rbp)
callq 0x11e0
movq %rax, 0x3a9e(%rip)      # 0x51a0
testq %rax, %rax
je 0x1746
movq 0x3aaa(%rip), %rdi      # 0x51b8
leaq 0x1de3(%rip), %rsi      # 0x34f8
movq %rsi, -0x30(%rbp)
callq 0x11e0
movq %rax, 0x3a8b(%rip)      # 0x51b0
testq %rax, %rax
je 0x1746
testl %ebx, %ebx
je 0x1764
movq (%r15), %rsi
leaq 0x1917(%rip), %rdi      # 0x304f
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x10d0
jmp 0x1975
leaq 0x1db4(%rip), %rdi      # 0x3501
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
xorl %eax, %eax
callq 0x10d0
pushq $0x1
popq %rbx
jmp 0x1975
pushq $0x1
popq %rdi
leaq -0x50(%rbp), %rsi
callq 0x1090
testl %r13d, %r13d
je 0x177e
movq 0x3864(%rip), %rsi      # 0x4fe0
jmp 0x1780
xorl %esi, %esi
movq 0x39b9(%rip), %rdx      # 0x5140
xorl %ecx, %ecx
cmpl $0x2, %r13d
setge %cl
movl %r14d, %edi
callq 0x1120
movq %rax, 0x39c1(%rip)      # 0x5160
movq -0x40(%rbp), %rbx
movq %rbx, %rdi
callq 0x10b0
testl %eax, %eax
js 0x1813
leaq 0x1b2d(%rip), %rdi      # 0x32e3
leaq 0xf99(%rip), %rdx       # 0x2756
leaq 0xfc5(%rip), %rcx       # 0x2789
leaq -0xf0(%rbp), %rsi
callq 0x1100
movl %eax, %ebx
testl %ebx, %ebx
jle 0x1805
movq -0xf0(%rbp), %rax
movq -0x8(%rax,%rbx,8), %rdi
addq $0x13, %rdi
callq 0x19bf
testl %eax, %eax
jne 0x1805
movq -0xf0(%rbp), %rax
movq -0x8(%rax,%rbx,8), %rdi
callq 0x1030
decq %rbx
jmp 0x17d2
movq -0xf0(%rbp), %rdi
callq 0x1030
jmp 0x181b
movq %rbx, %rdi
callq 0x19bf
movl 0x3946(%rip), %r9d      # 0x5168
movq 0x38f7(%rip), %rsi      # 0x5120
movl 0x393d(%rip), %edx      # 0x516c
movl 0x393b(%rip), %ecx      # 0x5170
movl 0x3938(%rip), %r8d      # 0x5174
testl %r9d, %r9d
jle 0x1851
leaq 0x1a9d(%rip), %rdi      # 0x32e5
xorl %eax, %eax
callq 0x10d0
jmp 0x185f
leaq 0x1ae1(%rip), %rdi      # 0x3339
xorl %eax, %eax
callq 0x10d0
leaq 0x38fa(%rip), %rdi      # 0x5160
callq 0x1080
cmpb $0x1, 0x38d6(%rip)      # 0x5148
jne 0x18ba
movq 0x3905(%rip), %rdi      # 0x5180
callq *0x38f7(%rip)           # 0x5178
movq 0x3900(%rip), %rdi      # 0x5188
callq *0x38ea(%rip)           # 0x5178
movq 0x3903(%rip), %rdi      # 0x5198
callq *0x38f5(%rip)           # 0x5190
movq 0x3906(%rip), %rdi      # 0x51a8
callq *0x38f8(%rip)           # 0x51a0
callq *0x3902(%rip)           # 0x51b0
movq 0x3903(%rip), %rdi      # 0x51b8
callq 0x1200
testl %r12d, %r12d
je 0x1962
pushq $0x1
popq %rdi
leaq -0x60(%rbp), %rbx
movq %rbx, %rsi
callq 0x1090
movq (%rbx), %rcx
movq 0x8(%rbx), %rax
subq -0x50(%rbp), %rcx
imulq $0x3e8, %rcx, %rcx      # imm = 0x3E8
subq -0x48(%rbp), %rax
movl $0xf4240, %esi          # imm = 0xF4240
cqto
idivq %rsi
movq %rax, %rbx
addq %rcx, %rbx
leaq -0xf0(%rbp), %r14
xorl %edi, %edi
movq %r14, %rsi
callq 0x11c0
imulq $0x3e8, (%r14), %rdi    # imm = 0x3E8
movq 0x8(%r14), %rax
movq 0x20(%r14), %rcx
movl $0x3e8, %r8d            # imm = 0x3E8
cqto
idivq %r8
movq %rax, %rsi
addq %rdi, %rsi
movq %rcx, %rax
cqto
idivq %r8
cvtsi2sd %rbx, %xmm0
movsd 0x16ca(%rip), %xmm3     # 0x3008
divsd %xmm3, %xmm0
cvtsi2sd %rsi, %xmm1
divsd %xmm3, %xmm1
cvtsi2sd %rax, %xmm2
divsd %xmm3, %xmm2
leaq 0x1a1d(%rip), %rdi      # 0x3378
movb $0x3, %al
callq 0x10d0
movq 0x37d7(%rip), %rdi      # 0x5140
testq %rdi, %rdi
je 0x1973
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 0x1a3a(%rip), %rdi      # 0x33ca
movq %rdi, -0x38(%rbp)
movl $0x102, %esi            # imm = 0x102
callq 0x1150
movq %rax, 0x3813(%rip)      # 0x51b8
testq %rax, %rax
jne 0x147c
leaq 0x1d56(%rip), %rdi      # 0x370b
callq 0x1070
jmp 0x175c