#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 */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
void buzz_time(int delay) {
  struct timeval now, stop;
  int diff;
  int remain_time = 0;
  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 = remain_time + (stop.tv_sec * 1000000 + stop.tv_usec) -
           (now.tv_sec * 1000000 + now.tv_usec);
    ;
  } while (diff > 0);
}


x86 assembly (clang, -O0):
<buzz_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x20(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    -0x4(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0xf4240,-0x18(%rbp)
jle    1157 <buzz_time+0x47>
mov    -0x18(%rbp),%eax
sub    $0xf4240,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115c <buzz_time+0x4c>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    -0x20(%rbp),%eax
imul   $0xf4240,-0x14(%rbp),%ecx
add    -0x18(%rbp),%ecx
add    %ecx,%eax
imul   $0xf4240,-0xc(%rbp),%ecx
add    -0x10(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     115c <buzz_time+0x4c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buzz_time>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
add    (%rsp),%ebx
mov    %ebx,(%rsp)
cmp    $0xf4241,%ebx
jl     113d <buzz_time+0x2d>
add    $0xfff0bdc0,%ebx
mov    %ebx,(%rsp)
addl   $0x1,0x4(%rsp)
lea    0x8(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
imul   $0xf4240,0x4(%rsp),%eax
add    (%rsp),%eax
imul   $0xf4240,0xc(%rsp),%ecx
add    0x8(%rsp),%ecx
cmp    %ecx,%eax
jg     1150 <buzz_time+0x40>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define void @buzz_time(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %6
%7 = call i32 @gettimeofday(%struct.timeval* %4, i32 0)
%8 = load i32, i32* %2
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%10 = load i32, i32* %9
%11 = add nsw i32 %10, %8
store i32 %11, i32* %9
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%13 = load i32, i32* %12
%14 = icmp sgt i32 %13, 1000000
br i1 %14, label %15, label %22
15: ; preds = %1
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%17 = load i32, i32* %16
%18 = sub nsw i32 %17, 1000000
store i32 %18, i32* %16
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%20 = load i32, i32* %19
%21 = add nsw i32 %20, 1
store i32 %21, i32* %19
br label %22
22: ; preds = %15, %1
br label %23
23: ; preds = %40, %22
%24 = call i32 @gettimeofday(%struct.timeval* %3, i32 0)
%25 = load i32, i32* %6
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%27 = load i32, i32* %26
%28 = mul nsw i32 %27, 1000000
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%30 = load i32, i32* %29
%31 = add nsw i32 %28, %30
%32 = add nsw i32 %25, %31
%33 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%34 = load i32, i32* %33
%35 = mul nsw i32 %34, 1000000
%36 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%37 = load i32, i32* %36
%38 = add nsw i32 %35, %37
%39 = sub nsw i32 %32, %38
store i32 %39, i32* %5
br label %40
40: ; preds = %23
%41 = load i32, i32* %5
%42 = icmp sgt i32 %41, 0
br i1 %42, label %23, label %43
43: ; preds = %40
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define void @buzz_time(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
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
br label %20
20: ; preds = %20, %16
%21 = call i32 @gettimeofday(%struct.timeval* %2, i32 0)
%22 = load i32, i32* %17
%23 = mul nsw i32 %22, 1000000
%24 = load i32, i32* %7
%25 = add nsw i32 %23, %24
%26 = load i32, i32* %18
%27 = mul nsw i32 %26, 1000000
%28 = load i32, i32* %19
%29 = add nsw i32 %27, %28
%30 = icmp sgt i32 %25, %29
br i1 %30, label %20, label %31
31: ; preds = %20
ret void
}