// File: /workspace/github_c_makefile_star2_O1/derhass[P]glx_hook/glx_hook.c
// Function: frametimes_init
static void
frametimes_init(GH_frametimes *ft, GH_frametime_mode mode, unsigned int delay, unsigned int num_timestamps, unsigned int num_results, unsigned int ctx_num)
{
	ft->cur_pos=0;
	ft->cur_result=0;
	ft->frame=0;
	ft->dump=NULL;

	if (mode >= GH_FRAMETIME_CPU_GPU) {
		if (frametimes_gl_init()) {
			GH_verbose(GH_MSG_WARNING, "GPU timer queries not available, using CPU only\n");
			mode = GH_FRAMETIME_CPU;
		}
	}

	if (mode && delay && num_timestamps && num_results) {
		ft->mode=mode;
		ft->delay=delay;
		ft->num_timestamps=num_timestamps;
		ft->num_results=num_results;
		if ((ft->frametime=malloc(sizeof(*ft->frametime) * (num_results+1) * num_timestamps))) {
			if ((ft->timestamp=malloc(sizeof(*ft->timestamp) * delay * num_timestamps))) {
				unsigned int i;
				GH_verbose(GH_MSG_DEBUG, "enabling frametime measurements mode %d,  %u x %u timestamps\n",
						(int)mode, delay, num_timestamps);
				for (i=0; i<delay * num_timestamps; i++) {
					timestamp_init(&ft->timestamp[i]);
				}
			} else {
				GH_verbose(GH_MSG_WARNING, "failed to allocate memory for %u x %u timestamps, "
						"disbaling timestamps\n",
						delay, num_timestamps);
				mode=GH_FRAMETIME_NONE;
			}
		} else {
			GH_verbose(GH_MSG_WARNING, "failed to allocate memory for %u x %u frametime results, "
					"disbaling timestamps\n",
					num_results, num_timestamps);
			mode=GH_FRAMETIME_NONE;
		}
	}

	if (!mode || !delay || !num_timestamps || !num_results) {
		ft->mode=GH_FRAMETIME_NONE;
		ft->delay=0;
		ft->num_timestamps=0;
		ft->num_results=0;
		ft->timestamp=NULL;
		ft->frametime=NULL;
	}

	if (ft->mode) {
		const char *file=get_envs("GH_FRAMETIME_FILE","glx_hook_frametimes-ctx%c.csv");
		if (file) {
			char buf[PATH_MAX];
			parse_name(buf, sizeof(buf), file, ctx_num);
			ft->dump=fopen(buf,"wt");
		}
		if (!ft->dump) {
			ft->dump=stderr;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1018, %rsp           # imm = 0x1018
movl %r9d, 0xc(%rsp)
movl %r8d, %r12d
movl %ecx, %r15d
movl %edx, %r14d
movl %esi, %r13d
movq %rdi, %rbx
movl $0x0, 0x18(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rdi)
cmpl $0x2, %esi
jb 0x6187
leaq 0x529c(%rip), %rdi      # 0xb170
callq 0x21a0
cmpq $0x0, 0x53ef(%rip)      # 0xb2d0
jne 0x5f2e
leaq 0x5286(%rip), %rdi      # 0xb170
callq 0x2120
leaq 0x1f88(%rip), %rdi      # 0x7e7e
callq 0x5d53
movq %rax, %rbp
leaq 0x1691(%rip), %rsi      # 0x7596
movl $0x4, %edi
leaq 0x1f6d(%rip), %rdx      # 0x7e7e
movq %rax, %rcx
xorl %eax, %eax
callq 0x2c88
leaq 0x524e(%rip), %rdi      # 0xb170
callq 0x21a0
movq %rbp, 0x53a2(%rip)      # 0xb2d0
leaq 0x523b(%rip), %rdi      # 0xb170
callq 0x2120
cmpq $0x0, 0x538e(%rip)      # 0xb2d0
je 0x6139
leaq 0x5221(%rip), %rdi      # 0xb170
callq 0x21a0
cmpq $0x0, 0x537c(%rip)      # 0xb2d8
jne 0x5fa9
leaq 0x520b(%rip), %rdi      # 0xb170
callq 0x2120
leaq 0x1f2d(%rip), %rdi      # 0x7e9e
callq 0x5d53
movq %rax, %rbp
leaq 0x1616(%rip), %rsi      # 0x7596
movl $0x4, %edi
leaq 0x1f12(%rip), %rdx      # 0x7e9e
movq %rax, %rcx
xorl %eax, %eax
callq 0x2c88
leaq 0x51d3(%rip), %rdi      # 0xb170
callq 0x21a0
movq %rbp, 0x532f(%rip)      # 0xb2d8
leaq 0x51c0(%rip), %rdi      # 0xb170
callq 0x2120
cmpq $0x0, 0x531b(%rip)      # 0xb2d8
je 0x6142
leaq 0x51a6(%rip), %rdi      # 0xb170
callq 0x21a0
cmpq $0x0, 0x5309(%rip)      # 0xb2e0
jne 0x6024
leaq 0x5190(%rip), %rdi      # 0xb170
callq 0x2120
leaq 0x1ec2(%rip), %rdi      # 0x7eae
callq 0x5d53
movq %rax, %rbp
leaq 0x159b(%rip), %rsi      # 0x7596
movl $0x4, %edi
leaq 0x1ea7(%rip), %rdx      # 0x7eae
movq %rax, %rcx
xorl %eax, %eax
callq 0x2c88
leaq 0x5158(%rip), %rdi      # 0xb170
callq 0x21a0
movq %rbp, 0x52bc(%rip)      # 0xb2e0
leaq 0x5145(%rip), %rdi      # 0xb170
callq 0x2120
cmpq $0x0, 0x52a8(%rip)      # 0xb2e0
je 0x614b
leaq 0x512b(%rip), %rdi      # 0xb170
callq 0x21a0
cmpq $0x0, 0x5296(%rip)      # 0xb2e8
jne 0x609f
leaq 0x5115(%rip), %rdi      # 0xb170
callq 0x2120
leaq 0x1e57(%rip), %rdi      # 0x7ebe
callq 0x5d53
movq %rax, %rbp
leaq 0x1520(%rip), %rsi      # 0x7596
movl $0x4, %edi
leaq 0x1e3c(%rip), %rdx      # 0x7ebe
movq %rax, %rcx
xorl %eax, %eax
callq 0x2c88
leaq 0x50dd(%rip), %rdi      # 0xb170
callq 0x21a0
movq %rbp, 0x5249(%rip)      # 0xb2e8
leaq 0x50ca(%rip), %rdi      # 0xb170
callq 0x2120
cmpq $0x0, 0x5235(%rip)      # 0xb2e8
je 0x6154
leaq 0x50b0(%rip), %rdi      # 0xb170
callq 0x21a0
cmpq $0x0, 0x5223(%rip)      # 0xb2f0
jne 0x611a
leaq 0x509a(%rip), %rdi      # 0xb170
callq 0x2120
leaq 0x1deb(%rip), %rdi      # 0x7ecd
callq 0x5d53
movq %rax, %rbp
leaq 0x14a5(%rip), %rsi      # 0x7596
movl $0x4, %edi
leaq 0x1dd0(%rip), %rdx      # 0x7ecd
movq %rax, %rcx
xorl %eax, %eax
callq 0x2c88
leaq 0x5062(%rip), %rdi      # 0xb170
callq 0x21a0
movq %rbp, 0x51d6(%rip)      # 0xb2f0
leaq 0x504f(%rip), %rdi      # 0xb170
callq 0x2120
cmpq $0x0, 0x51c2(%rip)      # 0xb2f0
jne 0x6187
leaq 0x1d96(%rip), %rdx      # 0x7ecd
jmp 0x615b
leaq 0x1d3e(%rip), %rdx      # 0x7e7e
jmp 0x615b
leaq 0x1d55(%rip), %rdx      # 0x7e9e
jmp 0x615b
leaq 0x1d5c(%rip), %rdx      # 0x7eae
jmp 0x615b
leaq 0x1d63(%rip), %rdx      # 0x7ebe
leaq 0x1d29(%rip), %rsi      # 0x7e8b
movl $0x2, %edi
xorl %eax, %eax
callq 0x2c88
leaq 0x1bd0(%rip), %rsi      # 0x7d45
movl $0x2, %edi
xorl %eax, %eax
callq 0x2c88
movl $0x1, %r13d
testl %r12d, %r12d
je 0x6275
testl %r15d, %r15d
je 0x6275
testl %r14d, %r14d
je 0x6275
testl %r13d, %r13d
je 0x6275
movl %r13d, (%rbx)
movl %r14d, 0x4(%rbx)
movl %r15d, 0x8(%rbx)
movl %r12d, 0xc(%rbx)
leal 0x1(%r12), %eax
movl %r15d, %ebp
imulq %rbp, %rax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rdi
callq 0x2130
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x6245
movl %r14d, %edi
imulq %rbp, %rdi
shlq $0x5, %rdi
callq 0x2130
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x6259
leaq 0x1b7a(%rip), %rsi      # 0x7d76
movl $0x4, %edi
movl %r13d, %edx
movl %r14d, %ecx
movl %r15d, %r8d
xorl %eax, %eax
callq 0x2c88
movl %r15d, %eax
imull %r14d, %eax
movl $0x1, %r13d
testl %eax, %eax
je 0x6275
movl %eax, %eax
shlq $0x5, %rax
xorl %ecx, %ecx
xorps %xmm0, %xmm0
movq 0x10(%rbx), %rdx
movups %xmm0, 0xc(%rdx,%rcx)
movups %xmm0, (%rdx,%rcx)
addq $0x20, %rcx
cmpq %rcx, %rax
jne 0x622d
jmp 0x6275
leaq 0x1bb0(%rip), %rsi      # 0x7dfc
xorl %r13d, %r13d
movl $0x2, %edi
movl %r12d, %edx
jmp 0x626b
leaq 0x1b54(%rip), %rsi      # 0x7db4
xorl %r13d, %r13d
movl $0x2, %edi
movl %r14d, %edx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x2c88
testl %r12d, %r12d
je 0x6289
testl %r15d, %r15d
je 0x6289
testl %r14d, %r14d
je 0x6289
testl %r13d, %r13d
jne 0x6299
xorl %eax, %eax
movq %rax, 0x20(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq %rax, 0x10(%rbx)
cmpl $0x0, (%rbx)
je 0x62ef
leaq 0x1ba6(%rip), %rdi      # 0x7e4b
callq 0x2030
testq %rax, %rax
leaq 0x1ba9(%rip), %rsi      # 0x7e5d
cmovneq %rax, %rsi
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movl 0xc(%rsp), %edx
callq 0x5b9d
leaq 0x1bab(%rip), %rsi      # 0x7e7b
movq %r14, %rdi
callq 0x2150
movq %rax, 0x30(%rbx)
testq %rax, %rax
jne 0x62ef
movq 0x4d08(%rip), %rax      # 0xaff0
movq (%rax), %rax
movq %rax, 0x30(%rbx)
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq