// File: /workspace/github_c_makefile_star2_O0/derhass[P]glx_hook/glx_hook.c
// Function: latency_init
static void
latency_init(GH_latency *lat, int latency, int manual_wait, unsigned gl_wait_timeout_usecs, unsigned int gl_wait_interval_usecs, unsigned int self_wait_interval_usecs)
{
	lat->latency=latency;
	lat->sync_object=NULL;
	lat->cur_pos=0;
	lat->flags=0;
	lat->gl_wait_timeout=(GLuint64)gl_wait_timeout_usecs * (GLuint64)1000;
	lat->gl_wait_interval=(GLuint64)gl_wait_interval_usecs * (GLuint64)1000;
	lat->self_wait_interval=(useconds_t)self_wait_interval_usecs;

	if (manual_wait > 0) {
		lat->flags |= GH_LATENCY_FLAG_MANUAL_WAIT;
	} else if (manual_wait < 0) {
		if ((gl_wait_interval_usecs > 0) || (self_wait_interval_usecs > 0))  {
			lat->flags |= GH_LATENCY_FLAG_MANUAL_WAIT;
		}
	}

	if (latency != GH_LATENCY_NOP) {
		GH_verbose(GH_MSG_INFO, "setting up latency limiter mode %d\n", latency);
	}

	if (latency > 0) {
		if (latency_gl_init()) {
			lat->latency=GH_LATENCY_FINISH_BEFORE;
			GH_verbose(GH_MSG_WARNING, "GPU sync not available, using latency mode %d\n",
					GH_LATENCY_FINISH_BEFORE);
		}
	}

	if (lat->latency > 0) {
		unsigned int cnt=(unsigned)lat->latency;
		lat->sync_object=malloc(sizeof(*lat->sync_object) * cnt);
		if (!lat->sync_object) {
			lat->latency=GH_LATENCY_FINISH_BEFORE;
			GH_verbose(GH_MSG_WARNING, "out of memory for sync objects, using latency mode %d\n");
		} else {
			unsigned int i;
			for (i=0; i<cnt; i++) {
				lat->sync_object[i]=NULL;
			}
			GH_verbose(GH_MSG_DEBUG, "enabling latency limiter: %d\n",lat->latency);
			if (lat->flags & GH_LATENCY_FLAG_MANUAL_WAIT) {
				GH_verbose(GH_MSG_INFO, "latency limiter with manual waits GL: %u usecs + self: %u usecs\n",
						gl_wait_interval_usecs, self_wait_interval_usecs);
			} else {
				GH_verbose(GH_MSG_INFO, "latency limiter with timeout: %u usecs\n",
						gl_wait_timeout_usecs);
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movl %r9d, -0x1c(%rbp)
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x14(%rax)
movl -0x14(%rbp), %eax
imulq $0x3e8, %rax, %rcx      # imm = 0x3E8
movq -0x8(%rbp), %rax
movq %rcx, 0x18(%rax)
movl -0x18(%rbp), %eax
imulq $0x3e8, %rax, %rcx      # imm = 0x3E8
movq -0x8(%rbp), %rax
movq %rcx, 0x20(%rax)
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x28(%rax)
cmpl $0x0, -0x10(%rbp)
jle 0x6b3b
movq -0x8(%rbp), %rax
movl 0x14(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x14(%rax)
jmp 0x6b5e
cmpl $0x0, -0x10(%rbp)
jge 0x6b5c
cmpl $0x0, -0x18(%rbp)
ja 0x6b4d
cmpl $0x0, -0x1c(%rbp)
jbe 0x6b5a
movq -0x8(%rbp), %rax
movl 0x14(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x14(%rax)
jmp 0x6b5c
jmp 0x6b5e
cmpl $-0x2, -0xc(%rbp)
je 0x6b7a
movl -0xc(%rbp), %edx
movl $0x3, %edi
leaq 0x3380(%rip), %rsi      # 0x9ef3
movb $0x0, %al
callq 0x3020
cmpl $0x0, -0xc(%rbp)
jle 0x6bab
callq 0x72c0
cmpl $0x0, %eax
je 0x6ba9
movq -0x8(%rbp), %rax
movl $0x0, (%rax)
movl $0x2, %edi
leaq 0x3377(%rip), %rsi      # 0x9f17
xorl %edx, %edx
movb $0x0, %al
callq 0x3020
jmp 0x6bab
movq -0x8(%rbp), %rax
cmpl $0x0, (%rax)
jle 0x6c91
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x2140
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x6c07
movq -0x8(%rbp), %rax
movl $0x0, (%rax)
movl $0x2, %edi
leaq 0x334b(%rip), %rsi      # 0x9f46
movb $0x0, %al
callq 0x3020
jmp 0x6c8f
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x20(%rbp), %eax
jae 0x6c34
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x24(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x6c0e
movq -0x8(%rbp), %rax
movl (%rax), %edx
movl $0x4, %edi
leaq 0x3337(%rip), %rsi      # 0x9f7d
movb $0x0, %al
callq 0x3020
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x6c77
movl -0x18(%rbp), %edx
movl -0x1c(%rbp), %ecx
movl $0x3, %edi
leaq 0x332d(%rip), %rsi      # 0x9f9b
movb $0x0, %al
callq 0x3020
jmp 0x6c8d
movl -0x14(%rbp), %edx
movl $0x3, %edi
leaq 0x3356(%rip), %rsi      # 0x9fdc
movb $0x0, %al
callq 0x3020
jmp 0x6c8f
jmp 0x6c91
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)