#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 timezone {
  int dummy;
};
struct timeval {
  unsigned long tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, struct timezone *);
int /*<<< orphan*/ printf(char *, unsigned long, unsigned long, int);
delay(unsigned long int wait_time) {
  struct timeval tv;
  struct timezone tz;
  unsigned long int time, start, end;
  start = tv.tv_usec;
  gettimeofday(&tv, &tz);
  end = tv.tv_usec;
  int cont = 0;
  time = end - start;
  while (time < wait_time) {
    cont = cont + 1;
    gettimeofday(&tv, &tz);
    end = tv.tv_usec;
    time = end - start;
  }
  printf("time = %u, wait_time = %u, cont = %i\n", time, wait_time, cont);
}


x86 assembly (clang, -O0):
<delay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <gettimeofday@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x38(%rbp),%rax
sub    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1199 <delay+0x79>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <gettimeofday@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
sub    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    115c <delay+0x3c>
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x3c(%rbp),%ecx
lea    0xe55(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<delay>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
call   1040 <gettimeofday@plt>
lea    0xec4(%rip),%rdi
mov    %rbx,%rdx
xor    %ecx,%ecx
add    $0x10,%rsp
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
%struct.timeval = type { i64 }
%struct.timezone = type { i32 }
@.str = [38 x i8] c"time = %u, wait_time = %u, cont = %i\0A\00"
define i32 @delay(i64 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca %struct.timeval
%5 = alloca %struct.timezone
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
store i64 %0, i64* %3
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%11 = load i64, i64* %10
store i64 %11, i64* %7
%12 = call i32 @gettimeofday(%struct.timeval* %4, %struct.timezone* %5)
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%14 = load i64, i64* %13
store i64 %14, i64* %8
store i32 0, i32* %9
%15 = load i64, i64* %8
%16 = load i64, i64* %7
%17 = sub i64 %15, %16
store i64 %17, i64* %6
br label %18
18: ; preds = %22, %1
%19 = load i64, i64* %6
%20 = load i64, i64* %3
%21 = icmp ult i64 %19, %20
br i1 %21, label %22, label %31
22: ; preds = %18
%23 = load i32, i32* %9
%24 = add nsw i32 %23, 1
store i32 %24, i32* %9
%25 = call i32 @gettimeofday(%struct.timeval* %4, %struct.timezone* %5)
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%27 = load i64, i64* %26
store i64 %27, i64* %8
%28 = load i64, i64* %8
%29 = load i64, i64* %7
%30 = sub i64 %28, %29
store i64 %30, i64* %6
br label %18
31: ; preds = %18
%32 = load i64, i64* %6
%33 = load i64, i64* %3
%34 = load i32, i32* %9
%35 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i64 %32, i64 %33, i32 %34)
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
%struct.timezone = type { i32 }
@.str = [38 x i8] c"time = %u, wait_time = %u, cont = %i\0A\00"
define i32 @delay(i64 %0) {
%2 = alloca %struct.timeval
%3 = alloca %struct.timezone
%4 = bitcast %struct.timeval* %2 to i8*
%5 = bitcast %struct.timezone* %3 to i8*
%6 = call i32 @gettimeofday(%struct.timeval* %2, %struct.timezone* %3)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i64 undef, i64 %0, i32 0)
ret i32 undef
}