// File: /workspace/github_c_makefile_star2_O1/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
cmpl $0x2, %edi
jl 0x141b
movl %edi, %eax
movl $0xffffffff, %r14d      # 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 (%r15,%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 %r14d, %r14d
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)
jmp 0x1433
leaq 0x1c16(%rip), %rbx      # 0x3038
xorl %r12d, %r12d
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movb $0x1, -0x2a(%rbp)
movb $0x1, -0x29(%rbp)
testl %r12d, %r12d
je 0x1466
leaq 0x1c05(%rip), %rdi      # 0x3044
leaq 0x1fa7(%rip), %rsi      # 0x33ed
callq 0x11b0
movq %rax, 0x3cee(%rip)      # 0x5140
movl $0x2000, %ecx           # imm = 0x2000
movq %rax, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x1190
cmpb $0x1, 0x3cdb(%rip)      # 0x5148
jne 0x1769
leaq 0x1f28(%rip), %r13      # 0x33a2
movq %r13, %rdi
movl $0x102, %esi            # imm = 0x102
callq 0x1150
testq %rax, %rax
jne 0x14b9
leaq 0x1f3a(%rip), %r13      # 0x33cd
movq %r13, %rdi
movl $0x102, %esi            # imm = 0x102
callq 0x1150
testq %rax, %rax
jne 0x14b9
leaq 0x1f1e(%rip), %r13      # 0x33ca
movq %r13, %rdi
movl $0x102, %esi            # imm = 0x102
callq 0x1150
movq %rax, 0x3cf8(%rip)      # 0x51b8
testq %rax, %rax
je 0x17ba
movq %r13, -0x38(%rbp)
leaq 0x1f01(%rip), %r13      # 0x33d5
movq %rax, %rdi
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3cda(%rip)      # 0x51c0
testq %rax, %rax
je 0x178b
movq 0x3cc2(%rip), %rdi      # 0x51b8
leaq 0x1ee1(%rip), %r13      # 0x33de
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3cbc(%rip)      # 0x51c8
testq %rax, %rax
je 0x178b
movq 0x3c9c(%rip), %rdi      # 0x51b8
leaq 0x1ecc(%rip), %r13      # 0x33ef
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3c9e(%rip)      # 0x51d0
testq %rax, %rax
je 0x178b
movq 0x3c76(%rip), %rdi      # 0x51b8
leaq 0x1eb9(%rip), %r13      # 0x3402
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3c80(%rip)      # 0x51d8
testq %rax, %rax
je 0x178b
movq 0x3c50(%rip), %rdi      # 0x51b8
leaq 0x1ea5(%rip), %r13      # 0x3414
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3c62(%rip)      # 0x51e0
testq %rax, %rax
je 0x178b
movq 0x3c2a(%rip), %rdi      # 0x51b8
leaq 0x1e95(%rip), %r13      # 0x342a
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3bd4(%rip)      # 0x5178
testq %rax, %rax
je 0x178b
movq 0x3c04(%rip), %rdi      # 0x51b8
leaq 0x1e82(%rip), %r13      # 0x343d
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3c1e(%rip)      # 0x51e8
testq %rax, %rax
je 0x178b
movq 0x3bde(%rip), %rdi      # 0x51b8
leaq 0x1e6e(%rip), %r13      # 0x344f
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3c00(%rip)      # 0x51f0
testq %rax, %rax
je 0x178b
movq 0x3bb8(%rip), %rdi      # 0x51b8
leaq 0x1e60(%rip), %r13      # 0x3467
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3be2(%rip)      # 0x51f8
testq %rax, %rax
je 0x178b
movq 0x3b92(%rip), %rdi      # 0x51b8
leaq 0x1e51(%rip), %r13      # 0x347e
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3bc4(%rip)      # 0x5200
testq %rax, %rax
je 0x178b
movq 0x3b6c(%rip), %rdi      # 0x51b8
leaq 0x1e40(%rip), %r13      # 0x3493
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3ba6(%rip)      # 0x5208
testq %rax, %rax
je 0x178b
movq 0x3b46(%rip), %rdi      # 0x51b8
leaq 0x1e2a(%rip), %r13      # 0x34a3
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3b88(%rip)      # 0x5210
testq %rax, %rax
je 0x178b
movq 0x3b20(%rip), %rdi      # 0x51b8
leaq 0x1e13(%rip), %r13      # 0x34b2
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3b6a(%rip)      # 0x5218
testq %rax, %rax
je 0x178b
movq 0x3afa(%rip), %rdi      # 0x51b8
leaq 0x1dff(%rip), %r13      # 0x34c4
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3b4c(%rip)      # 0x5220
testq %rax, %rax
je 0x178b
movq 0x3ad4(%rip), %rdi      # 0x51b8
leaq 0x1d3f(%rip), %r13      # 0x342a
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3a7e(%rip)      # 0x5178
testq %rax, %rax
je 0x178b
movq 0x3aae(%rip), %rdi      # 0x51b8
leaq 0x1dc1(%rip), %r13      # 0x34d2
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3a70(%rip)      # 0x5190
testq %rax, %rax
je 0x178b
movq 0x3a8c(%rip), %rdi      # 0x51b8
leaq 0x1db3(%rip), %r13      # 0x34e6
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3a5e(%rip)      # 0x51a0
testq %rax, %rax
je 0x178b
movq 0x3a6a(%rip), %rdi      # 0x51b8
leaq 0x1da3(%rip), %r13      # 0x34f8
movq %r13, %rsi
callq 0x11e0
movq %rax, 0x3a4c(%rip)      # 0x51b0
testq %rax, %rax
je 0x178b
cmpb $0x0, -0x2a(%rbp)
je 0x17a2
leaq -0x48(%rbp), %rsi
movl $0x1, %edi
callq 0x1090
testl %r12d, %r12d
je 0x17d0
movq 0x3857(%rip), %rsi      # 0x4fe0
jmp 0x17d2
leaq 0x1d6f(%rip), %rdi      # 0x3501
movq %r13, %rsi
movq -0x38(%rbp), %rdx
xorl %eax, %eax
callq 0x10d0
jmp 0x17c6
movq (%r15), %rsi
leaq 0x18a3(%rip), %rdi      # 0x304f
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x10d0
jmp 0x19fe
leaq 0x1f4a(%rip), %rdi      # 0x370b
callq 0x1070
movl $0x1, %ebx
jmp 0x19fe
xorl %esi, %esi
movq 0x3967(%rip), %rdx      # 0x5140
xorl %ecx, %ecx
cmpl $0x2, %r12d
setge %cl
movl %r14d, %edi
callq 0x1120
movq %rax, 0x396f(%rip)      # 0x5160
movq %rbx, %rdi
callq 0x10b0
testl %eax, %eax
js 0x186c
leaq 0x1adf(%rip), %rdi      # 0x32e3
leaq 0x1014(%rip), %rdx      # 0x281f
leaq 0x1042(%rip), %rcx      # 0x2854
leaq -0xe8(%rbp), %rsi
callq 0x1100
testl %eax, %eax
movb -0x29(%rbp), %r14b
jle 0x185e
movl %eax, %ebx
incq %rbx
movq -0xe8(%rbp), %rax
movq -0x10(%rax,%rbx,8), %rdi
addq $0x13, %rdi
callq 0x1a12
testl %eax, %eax
jne 0x185e
movq -0xe8(%rbp), %rax
movq -0x10(%rax,%rbx,8), %rdi
callq 0x1030
decq %rbx
cmpq $0x1, %rbx
jg 0x182b
movq -0xe8(%rbp), %rdi
callq 0x1030
jmp 0x1878
movq %rbx, %rdi
callq 0x1a12
movb -0x29(%rbp), %r14b
movl 0x38e9(%rip), %r9d      # 0x5168
movq 0x389a(%rip), %rsi      # 0x5120
movl 0x38e0(%rip), %edx      # 0x516c
movl 0x38de(%rip), %ecx      # 0x5170
movl 0x38db(%rip), %r8d      # 0x5174
testl %r9d, %r9d
jle 0x18ae
leaq 0x1a40(%rip), %rdi      # 0x32e5
xorl %eax, %eax
callq 0x10d0
jmp 0x18bc
leaq 0x1a84(%rip), %rdi      # 0x3339
xorl %eax, %eax
callq 0x10d0
leaq 0x389d(%rip), %rdi      # 0x5160
callq 0x1080
cmpb $0x1, 0x3879(%rip)      # 0x5148
jne 0x1917
movq 0x38a8(%rip), %rdi      # 0x5180
callq *0x389a(%rip)           # 0x5178
movq 0x38a3(%rip), %rdi      # 0x5188
callq *0x388d(%rip)           # 0x5178
movq 0x38a6(%rip), %rdi      # 0x5198
callq *0x3898(%rip)           # 0x5190
movq 0x38a9(%rip), %rdi      # 0x51a8
callq *0x389b(%rip)           # 0x51a0
callq *0x38a5(%rip)           # 0x51b0
movq 0x38a6(%rip), %rdi      # 0x51b8
callq 0x1200
testb %r14b, %r14b
jne 0x19eb
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 0x1641(%rip), %xmm3     # 0x3008
divsd %xmm3, %xmm0
cvtsi2sd %rsi, %xmm1
divsd %xmm3, %xmm1
cvtsi2sd %rdx, %xmm2
divsd %xmm3, %xmm2
leaq 0x1994(%rip), %rdi      # 0x3378
movb $0x3, %al
callq 0x10d0
movq 0x374e(%rip), %rdi      # 0x5140
testq %rdi, %rdi
je 0x19fc
callq 0x10a0
xorl %ebx, %ebx
movl %ebx, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq