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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ usleep(unsigned long);
unsigned long do_time(unsigned long usecs) {
  struct timeval after, before;
  int secs, usec;
  gettimeofday(&before, NULL);
  usleep(usecs);
  gettimeofday(&after, NULL);
  secs = after.tv_sec - before.tv_sec;
  usec = after.tv_usec - before.tv_usec;
  return secs * 1000000 + usec;
}


x86 assembly (clang, -O0):
<do_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x8(%rbp),%rdi
call   1040 <usleep@plt>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x10(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
imul   $0xf4240,-0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
cltq
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_time>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    %rbx,%rdi
call   1040 <usleep@plt>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%ecx
sub    (%rsp),%eax
sub    0x4(%rsp),%ecx
imul   $0xf4240,%eax,%eax
add    %ecx,%eax
cltq
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define i64 @do_time(i64 %0) {
%2 = alloca i64
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca i32
%6 = alloca i32
store i64 %0, i64* %2
%7 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%8 = load i64, i64* %2
%9 = call i32 @usleep(i64 %8)
%10 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%14 = load i32, i32* %13
%15 = sub nsw i32 %12, %14
store i32 %15, i32* %5
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%19 = load i32, i32* %18
%20 = sub nsw i32 %17, %19
store i32 %20, i32* %6
%21 = load i32, i32* %5
%22 = mul nsw i32 %21, 1000000
%23 = load i32, i32* %6
%24 = add nsw i32 %22, %23
%25 = sext i32 %24 to i64
ret i64 %25
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define i64 @do_time(i64 %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 = tail call i32 @usleep(i64 %0)
%8 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%12 = load i32, i32* %11
%13 = sub nsw i32 %10, %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%17 = load i32, i32* %16
%18 = sub i32 %15, %17
%19 = mul nsw i32 %13, 1000000
%20 = add nsw i32 %18, %19
%21 = sext i32 %20 to i64
ret i64 %21
}