// File: /workspace/github_c_makefile_star2_O0/derhass[P]glx_hook/glx_hook.c
// Function: swapbuffer_omission_do_swap
static int
swapbuffer_omission_do_swap(GH_swapbuffer_omission_t *swo)
{
	int do_swap;
	if (swo->min_swap_time > 0) {
		unsigned int i,idx;
		uint64_t cpu = 0;
		uint64_t gpu = 0;
		uint64_t val;
		timestamp_set(&swo->prev_frame_ts[swo->cur_pos][1],&swo->prev_frames[swo->cur_pos][1], GH_FRAMETIME_CPU_GPU);
		if (++swo->cur_pos >= swo->measure_frames_tot) {
			swo->cur_pos = 0;
		}
		idx = swo->cur_pos;

		for (i=0; i<swo->measure_frames_avg; i++) {
			cpu += (swo->prev_frames[idx][1].cpu - swo->prev_frames[idx][0].cpu);
			gpu += (swo->prev_frames[idx][1].gpu - swo->prev_frames[idx][0].gpu);
			if (++idx >= swo->measure_frames_tot) {
				idx = 0;
			}
		}
		cpu /= swo->measure_frames_avg;
		gpu /= swo->measure_frames_avg;
		switch (swo->measure_mode) {
			case 1:
				val=cpu;
				break;
			case 2:
				val=gpu;
				break;
			default:
				val = (cpu>gpu)?cpu:gpu;
		}
		if (val < 1000) {
			val = 1000;
		}
		int interval  = (int)(swo->min_swap_time/val);
		if (interval < swo->limits[0]) {
			interval = swo->limits[0];
		}
		if (interval > swo->limits[1]) {
			interval = swo->limits[1];
		}
		swo->prev_intervals[swo->cur_pos]=interval;
		idx = swo->cur_pos + swo->measure_frames_tot - swo->measure_frames_avg + 1;
		for (i=0; i<(swo->measure_frames_avg-1); i++) {
			if (idx >= swo->measure_frames_tot) {
				idx -= swo->measure_frames_tot;
			}
			interval += swo->prev_intervals[idx++];
		}
		swo->swapbuffers = interval / swo->measure_frames_avg;

		/*printf("XXX %d %d cpu: %lu, gpu: %lu\n", swo->swapbuffers, interval, cpu, gpu);*/
	}
	do_swap = (++swo->swapbuffer_cnt >= swo->swapbuffers);
	return do_swap;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jbe 0x5087
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rdi
addq $0x28, %rdi
movq -0x8(%rbp), %rax
movl 0x768(%rax), %eax
shlq $0x6, %rax
addq %rax, %rdi
addq $0x20, %rdi
movq -0x8(%rbp), %rsi
addq $0x428, %rsi            # imm = 0x428
movq -0x8(%rbp), %rax
movl 0x768(%rax), %eax
imulq $0x30, %rax, %rax
addq %rax, %rsi
addq $0x18, %rsi
movl $0x2, %edx
callq 0x7cb0
movq -0x8(%rbp), %rcx
movl 0x768(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x768(%rcx)
movq -0x8(%rbp), %rcx
cmpl 0x76c(%rcx), %eax
jb 0x4e2f
movq -0x8(%rbp), %rax
movl $0x0, 0x768(%rax)
movq -0x8(%rbp), %rax
movl 0x768(%rax), %eax
movl %eax, -0x14(%rbp)
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x770(%rcx), %eax
jae 0x4ef3
movq -0x8(%rbp), %rax
addq $0x428, %rax            # imm = 0x428
movl -0x14(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
addq $0x428, %rcx            # imm = 0x428
movl -0x14(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
subq (%rcx), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
addq $0x428, %rax            # imm = 0x428
movl -0x14(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x28(%rax), %rax
movq -0x8(%rbp), %rcx
addq $0x428, %rcx            # imm = 0x428
movl -0x14(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
subq 0x10(%rcx), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rcx
cmpl 0x76c(%rcx), %eax
jb 0x4ee3
movl $0x0, -0x14(%rbp)
jmp 0x4ee5
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x4e43
movq -0x8(%rbp), %rax
movl 0x770(%rax), %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
xorl %edx, %edx
movq %rdx, -0x40(%rbp)
divq %rcx
movq -0x40(%rbp), %rdx
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movl 0x770(%rax), %eax
movl %eax, %ecx
movq -0x28(%rbp), %rax
divq %rcx
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x38(%rbp)
subl $0x1, %eax
je 0x4f46
jmp 0x4f3c
movl -0x38(%rbp), %eax
subl $0x2, %eax
je 0x4f50
jmp 0x4f5a
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x4f7e
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x4f7e
movq -0x20(%rbp), %rax
cmpq -0x28(%rbp), %rax
jbe 0x4f6e
movq -0x20(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x4f76
movq -0x28(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x3e8, -0x30(%rbp)     # imm = 0x3E8
jae 0x4f90
movq $0x3e8, -0x30(%rbp)     # imm = 0x3E8
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x4fb9
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jle 0x4fcf
movq -0x8(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %edx
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x768(%rcx), %ecx
movl %edx, 0x728(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movl 0x768(%rax), %eax
movq -0x8(%rbp), %rcx
addl 0x76c(%rcx), %eax
movq -0x8(%rbp), %rcx
subl 0x770(%rcx), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x770(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jae 0x5070
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x76c(%rcx), %eax
jb 0x5047
movq -0x8(%rbp), %rax
movl 0x76c(%rax), %ecx
movl -0x14(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movl %ecx, %ecx
movl 0x728(%rax,%rcx,4), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x5012
movl -0x34(%rbp), %eax
movq -0x8(%rbp), %rcx
xorl %edx, %edx
divl 0x770(%rcx)
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rcx
movl 0x4(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x4(%rcx)
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
setge %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop