#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct timeval {
  unsigned long long tv_sec;
  unsigned long long tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
void wait_ticks(int c) {
  struct timeval now, last;
  unsigned long long a, b;
  gettimeofday(&last, NULL);
  a = 1000000ull * last.tv_sec + last.tv_usec;
  for (;;) {
    gettimeofday(&now, NULL);
    b = 1000000ull * now.tv_sec + now.tv_usec;
    if (b - a > c)
      break;
  }
}


x86 assembly (clang, -O0):
<wait_ticks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
imul   $0xf4240,-0x28(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
imul   $0xf4240,-0x18(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
sub    -0x30(%rbp),%rax
movslq -0x4(%rbp),%rcx
cmp    %rcx,%rax
jbe    116f <wait_ticks+0x5f>
jmp    1174 <wait_ticks+0x64>
jmp    1138 <wait_ticks+0x28>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_ticks>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edi,%r14d
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x8(%rsp),%r15
mov    0x10(%rsp),%rbp
movslq %r14d,%rbx
lea    0x18(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x18(%rsp),%rax
sub    %r15,%rax
mov    0x20(%rsp),%rcx
sub    %rbp,%rcx
imul   $0xf4240,%rax,%rax
add    %rcx,%rax
cmp    %rbx,%rax
jbe    1140 <wait_ticks+0x30>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define void @wait_ticks(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca i64
%6 = alloca i64
store i32 %0, i32* %2
%7 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%9 = load i64, i64* %8
%10 = mul i64 1000000, %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%12 = load i64, i64* %11
%13 = add i64 %10, %12
store i64 %13, i64* %5
br label %14
14: ; preds = %29, %1
%15 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%17 = load i64, i64* %16
%18 = mul i64 1000000, %17
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%20 = load i64, i64* %19
%21 = add i64 %18, %20
store i64 %21, i64* %6
%22 = load i64, i64* %6
%23 = load i64, i64* %5
%24 = sub i64 %22, %23
%25 = load i32, i32* %2
%26 = sext i32 %25 to i64
%27 = icmp ugt i64 %24, %26
br i1 %27, label %28, label %29
28: ; preds = %14
br label %30
29: ; preds = %14
br label %14
30: ; preds = %28
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define void @wait_ticks(i32 %0) {
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %2 to i8*
%5 = bitcast %struct.timeval* %3 to i8*
%6 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%8 = load i64, i64* %7
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%10 = load i64, i64* %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%13 = sext i32 %0 to i64
br label %14
14: ; preds = %14, %1
%15 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%16 = load i64, i64* %11
%17 = load i64, i64* %12
%18 = sub i64 %16, %8
%19 = mul i64 %18, 1000000
%20 = sub i64 %17, %10
%21 = add i64 %20, %19
%22 = icmp ugt i64 %21, %13
br i1 %22, label %23, label %14
23: ; preds = %14
ret void
}