#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 {
  int tv_usec;
  int tv_sec;
};

/* Variables and functions */
float ftimediff(struct timeval *, struct timeval *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
void buzz(int delay) {
  struct timeval now, stop;
  float diff;
  gettimeofday(&stop, 0);
  stop.tv_usec += delay;
  if (stop.tv_usec > 1000000) {
    stop.tv_usec -= 1000000;
    stop.tv_sec += 1;
  }
  do {
    gettimeofday(&now, 0);
    diff = ftimediff(&stop, &now);
  } while (diff > 0.0);
}


x86 assembly (clang, -O0):
<buzz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    -0x4(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0xf4240,-0x18(%rbp)
jle    1160 <buzz+0x40>
mov    -0x18(%rbp),%eax
sub    $0xf4240,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1165 <buzz+0x45>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    -0x18(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <ftimediff@plt>
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
ja     1165 <buzz+0x45>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buzz>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
add    0x8(%rsp),%ebx
mov    %ebx,0x8(%rsp)
cmp    $0xf4241,%ebx
jl     1154 <buzz+0x34>
add    $0xfff0bdc0,%ebx
mov    %ebx,0x8(%rsp)
addl   $0x1,0xc(%rsp)
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%r14
xchg   %ax,%ax
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <ftimediff@plt>
ucomiss 0xe84(%rip),%xmm0
ja     1160 <buzz+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define void @buzz(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca float
store i32 %0, i32* %2
%6 = call i32 @gettimeofday(%struct.timeval* %4, i32 0)
%7 = load i32, i32* %2
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%9 = load i32, i32* %8
%10 = add nsw i32 %9, %7
store i32 %10, i32* %8
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%12 = load i32, i32* %11
%13 = icmp sgt i32 %12, 1000000
br i1 %13, label %14, label %21
14: ; preds = %1
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%16 = load i32, i32* %15
%17 = sub nsw i32 %16, 1000000
store i32 %17, i32* %15
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1
store i32 %20, i32* %18
br label %21
21: ; preds = %14, %1
br label %22
22: ; preds = %25, %21
%23 = call i32 @gettimeofday(%struct.timeval* %3, i32 0)
%24 = call float @ftimediff(%struct.timeval* %4, %struct.timeval* %3)
store float %24, float* %5
br label %25
25: ; preds = %22
%26 = load float, float* %5
%27 = fpext float %26 to double
%28 = fcmp ogt double %27, 0.000000e+00
br i1 %28, label %22, label %29
29: ; preds = %25
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define void @buzz(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 0)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%8 = load i32, i32* %7
%9 = add nsw i32 %8, %0
store i32 %9, i32* %7
%10 = icmp sgt i32 %9, 1000000
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = add nsw i32 %9, -1000000
store i32 %12, i32* %7
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 1
store i32 %15, i32* %13
br label %16
16: ; preds = %11, %1
br label %17
17: ; preds = %16, %17
%18 = call i32 @gettimeofday(%struct.timeval* %2, i32 0)
%19 = call float @ftimediff(%struct.timeval* %3, %struct.timeval* %2)
%20 = fcmp ogt float %19, 0.000000e+00
br i1 %20, label %17, label %21
21: ; preds = %17
ret void
}