#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;
  scalar_t__ tv_usec;
};
struct ntptimeval {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
main() {
  int i = 0;
  struct timeval val;
  struct timeval begin;
  struct timeval end;
  struct ntptimeval ntv;
  fprintf(stderr, "!NANO\n");
  gettimeofday(&begin, NULL);
  while (i < 10000000) {
    gettimeofday(&val, NULL);
    i++;
  }
  gettimeofday(&end, NULL);
  end.tv_sec -= begin.tv_sec;
  if (begin.tv_usec > end.tv_usec) {
    end.tv_sec--;
    end.tv_usec += 1000000;
  }
  end.tv_usec -= begin.tv_usec;
  fprintf(stdout, "loop took:%u.%u\n", end.tv_sec, end.tv_usec);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
lea    0xeaa(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmpl   $0x989680,-0x8(%rbp)
jge    1192 <main+0x62>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116a <main+0x3a>
lea    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x28(%rbp),%ecx
mov    -0x38(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x30(%rbp),%rax
jle    11cf <main+0x9f>
mov    -0x38(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
add    $0xf4240,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x30(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%edx
mov    -0x30(%rbp),%rcx
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
mov    0x2ea3(%rip),%rax
mov    (%rax),%edi
lea    0xeba(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    $0x989680,%ebp
lea    0x28(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
add    $0xffffffff,%ebp
jne    1170 <main+0x40>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x8(%rsp),%edx
sub    0x18(%rsp),%edx
mov    0x20(%rsp),%rax
mov    0x10(%rsp),%rcx
cmp    %rcx,%rax
jle    11b0 <main+0x80>
add    $0xffffffff,%edx
mov    %edx,0x8(%rsp)
add    $0xf4240,%rcx
sub    %rax,%rcx
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
%struct.ntptimeval = type { i32 }
@stderr = global i32 0
@.str = [7 x i8] c"!NANO\0A\00"
@stdout = global i32 0
@.str.1 = [17 x i8] c"loop took:%u.%u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = alloca %struct.ntptimeval
store i32 0, i32* %1
store i32 0, i32* %2
%7 = load i32, i32* @stderr
%8 = call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
br label %10
10: ; preds = %13, %0
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 10000000
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%15 = load i32, i32* %2
%16 = add nsw i32 %15, 1
store i32 %16, i32* %2
br label %10
17: ; preds = %10
%18 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%22 = load i32, i32* %21
%23 = sub nsw i32 %22, %20
store i32 %23, i32* %21
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%25 = load i64, i64* %24
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%27 = load i64, i64* %26
%28 = icmp sgt i64 %25, %27
br i1 %28, label %29, label %36
29: ; preds = %17
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%31 = load i32, i32* %30
%32 = add nsw i32 %31, -1
store i32 %32, i32* %30
%33 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%34 = load i64, i64* %33
%35 = add nsw i64 %34, 1000000
store i64 %35, i64* %33
br label %36
36: ; preds = %29, %17
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%38 = load i64, i64* %37
%39 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%40 = load i64, i64* %39
%41 = sub nsw i64 %40, %38
store i64 %41, i64* %39
%42 = load i32, i32* @stdout
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%44 = load i32, i32* %43
%45 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%46 = load i64, i64* %45
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %44, i64 %46)
%48 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@stderr = global i32 0
@.str = [7 x i8] c"!NANO\0A\00"
@stdout = global i32 0
@.str.1 = [17 x i8] c"loop took:%u.%u\0A\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %1 to i8*
%5 = bitcast %struct.timeval* %2 to i8*
%6 = bitcast %struct.timeval* %3 to i8*
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
br label %10
10: ; preds = %0, %10
%11 = phi i32 [ 0, %0 ], [ %13, %10 ]
%12 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%13 = add nuw nsw i32 %11, 1
%14 = icmp eq i32 %13, 10000000
br i1 %14, label %15, label %10
15: ; preds = %10
%16 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%20 = load i32, i32* %19
%21 = sub nsw i32 %20, %18
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%23 = load i64, i64* %22
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%25 = load i64, i64* %24
%26 = icmp sgt i64 %23, %25
br i1 %26, label %27, label %30
27: ; preds = %15
%28 = add nsw i32 %21, -1
store i32 %28, i32* %19
%29 = add nsw i64 %25, 1000000
br label %30
30: ; preds = %27, %15
%31 = phi i32 [ %28, %27 ], [ %21, %15 ]
%32 = phi i64 [ %29, %27 ], [ %25, %15 ]
%33 = sub nsw i64 %32, %23
%34 = load i32, i32* @stdout
%35 = tail call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %31, i64 %33)
%36 = tail call i32 @exit(i32 0)
unreachable
}