// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x1030, %rsp           # imm = 0x1030
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movl %r9d, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movl $0x0, 0x18(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x28(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x2c(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x30(%rax)
cmpl $0x2, -0xc(%rbp)
jb 0x6899
callq 0x6f70
cmpl $0x0, %eax
je 0x6897
movl $0x2, %edi
leaq 0x34cc(%rip), %rsi      # 0x9d55
movb $0x0, %al
callq 0x3020
movl $0x1, -0xc(%rbp)
jmp 0x6899
cmpl $0x0, -0xc(%rbp)
je 0x69cf
cmpl $0x0, -0x10(%rbp)
je 0x69cf
cmpl $0x0, -0x14(%rbp)
je 0x69cf
cmpl $0x0, -0x18(%rbp)
je 0x69cf
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
movl -0x10(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x14(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x18(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
imulq $0x18, %rax, %rdi
movl -0x14(%rbp), %eax
imulq %rax, %rdi
callq 0x2140
movq -0x8(%rbp), %rcx
movq %rax, 0x20(%rcx)
cmpq $0x0, %rax
je 0x69ad
movl -0x10(%rbp), %eax
movl %eax, %edi
shlq $0x5, %rdi
movl -0x14(%rbp), %eax
imulq %rax, %rdi
callq 0x2140
movq -0x8(%rbp), %rcx
movq %rax, 0x10(%rcx)
cmpq $0x0, %rax
je 0x698b
movl -0xc(%rbp), %edx
movl -0x10(%rbp), %ecx
movl -0x14(%rbp), %r8d
movl $0x4, %edi
leaq 0x343b(%rip), %rsi      # 0x9d86
movb $0x0, %al
callq 0x3020
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movl -0x10(%rbp), %ecx
imull -0x14(%rbp), %ecx
cmpl %ecx, %eax
jae 0x6989
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x20(%rbp), %eax
shlq $0x5, %rax
addq %rax, %rdi
callq 0x6f30
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x6959
jmp 0x69ab
movl -0x10(%rbp), %edx
movl -0x14(%rbp), %ecx
movl $0x2, %edi
leaq 0x3427(%rip), %rsi      # 0x9dc4
movb $0x0, %al
callq 0x3020
movl $0x0, -0xc(%rbp)
jmp 0x69cd
movl -0x18(%rbp), %edx
movl -0x14(%rbp), %ecx
movl $0x2, %edi
leaq 0x344d(%rip), %rsi      # 0x9e0c
movb $0x0, %al
callq 0x3020
movl $0x0, -0xc(%rbp)
jmp 0x69cf
cmpl $0x0, -0xc(%rbp)
je 0x69e7
cmpl $0x0, -0x10(%rbp)
je 0x69e7
cmpl $0x0, -0x14(%rbp)
je 0x69e7
cmpl $0x0, -0x18(%rbp)
jne 0x6a2a
movq -0x8(%rbp), %rax
movl $0x0, (%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0xc(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x8(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6aa6
leaq 0x3421(%rip), %rdi      # 0x9e5b
leaq 0x342c(%rip), %rsi      # 0x9e6d
callq 0x6610
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x6a87
leaq -0x1030(%rbp), %rdi
movq -0x28(%rbp), %rdx
movl -0x1c(%rbp), %ecx
movl $0x1000, %esi           # imm = 0x1000
callq 0x5520
leaq -0x1030(%rbp), %rdi
leaq 0x3414(%rip), %rsi      # 0x9e8b
callq 0x2160
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x6aa4
movq 0x655f(%rip), %rax      # 0xcff8
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x30(%rax)
jmp 0x6aa6
addq $0x1030, %rsp           # imm = 0x1030
popq %rbp
retq
nop