#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*/ printf(char *, ...);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int i = 0;
  long int t1, t2, t3, t4;
  struct timeval time1;
  gettimeofday(&time1, NULL);
  for (i = 0; i < 1000; i++)
    printf("hello");
  struct timeval time2;
  gettimeofday(&time2, NULL);
  struct timeval time3;
  gettimeofday(&time3, NULL);
  for (i = 0; i < 1000; i++)
    write(1, "hello", 6);
  struct timeval time4;
  gettimeofday(&time4, NULL);
  t1 = time1.tv_sec * 1000000 + time1.tv_usec;
  t2 = time2.tv_sec * 1000000 + time2.tv_usec;
  t3 = time3.tv_sec * 1000000 + time3.tv_usec;
  t4 = time4.tv_sec * 1000000 + time4.tv_usec;
  printf("%ld\n%ld\n", t2 - t1, t4 - t3);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jge    1183 <main+0x53>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    115a <main+0x2a>
lea    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jge    11d5 <main+0xa5>
mov    $0x1,%edi
lea    0xe43(%rip),%rsi
mov    $0x6,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a4 <main+0x74>
lea    -0x48(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
imul   $0xf4240,-0x30(%rbp),%eax
add    -0x2c(%rbp),%eax
cltq
mov    %rax,-0x10(%rbp)
imul   $0xf4240,-0x38(%rbp),%eax
add    -0x34(%rbp),%eax
cltq
mov    %rax,-0x18(%rbp)
imul   $0xf4240,-0x40(%rbp),%eax
add    -0x3c(%rbp),%eax
cltq
mov    %rax,-0x20(%rbp)
imul   $0xf4240,-0x48(%rbp),%eax
add    -0x44(%rbp),%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rsi
sub    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
sub    -0x20(%rbp),%rdx
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    $0x3e8,%ebp
lea    0xeb2(%rip),%rbx
xchg   %ax,%ax
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffff,%ebp
jne    1150 <main+0x20>
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    $0x3e8,%ebp
lea    0xe7d(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x6,%edx
call   1030 <write@plt>
add    $0xffffffff,%ebp
jne    1190 <main+0x60>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
movslq 0x20(%rsp),%rax
imul   $0xf4240,%rax,%rax
movslq 0x24(%rsp),%rcx
add    %rax,%rcx
movslq 0x18(%rsp),%rax
imul   $0xf4240,%rax,%rax
movslq 0x1c(%rsp),%rsi
add    %rax,%rsi
sub    %rcx,%rsi
movslq 0x10(%rsp),%rax
imul   $0xf4240,%rax,%rax
movslq 0x14(%rsp),%rcx
add    %rax,%rcx
movslq 0x8(%rsp),%rax
imul   $0xf4240,%rax,%rax
movslq 0xc(%rsp),%rdx
add    %rax,%rdx
sub    %rcx,%rdx
lea    0xdf6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [6 x i8] c"hello\00"
@.str.1 = [9 x i8] c"%ld\0A%ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca %struct.timeval
%8 = alloca %struct.timeval
%9 = alloca %struct.timeval
%10 = alloca %struct.timeval
store i32 0, i32* %1
store i32 0, i32* %2
%11 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
store i32 0, i32* %2
br label %12
12: ; preds = %17, %0
%13 = load i32, i32* %2
%14 = icmp slt i32 %13, 1000
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
store i32 %19, i32* %2
br label %12
20: ; preds = %12
%21 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
%22 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
store i32 0, i32* %2
br label %23
23: ; preds = %28, %20
%24 = load i32, i32* %2
%25 = icmp slt i32 %24, 1000
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = call i32 @write(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 6)
br label %28
28: ; preds = %26
%29 = load i32, i32* %2
%30 = add nsw i32 %29, 1
store i32 %30, i32* %2
br label %23
31: ; preds = %23
%32 = call i32 @gettimeofday(%struct.timeval* %10, i32* null)
%33 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%34 = load i32, i32* %33
%35 = mul nsw i32 %34, 1000000
%36 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%37 = load i32, i32* %36
%38 = add nsw i32 %35, %37
%39 = sext i32 %38 to i64
store i64 %39, i64* %3
%40 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%41 = load i32, i32* %40
%42 = mul nsw i32 %41, 1000000
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%44 = load i32, i32* %43
%45 = add nsw i32 %42, %44
%46 = sext i32 %45 to i64
store i64 %46, i64* %4
%47 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%48 = load i32, i32* %47
%49 = mul nsw i32 %48, 1000000
%50 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%51 = load i32, i32* %50
%52 = add nsw i32 %49, %51
%53 = sext i32 %52 to i64
store i64 %53, i64* %5
%54 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%55 = load i32, i32* %54
%56 = mul nsw i32 %55, 1000000
%57 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
%58 = load i32, i32* %57
%59 = add nsw i32 %56, %58
%60 = sext i32 %59 to i64
store i64 %60, i64* %6
%61 = load i64, i64* %4
%62 = load i64, i64* %3
%63 = sub nsw i64 %61, %62
%64 = load i64, i64* %6
%65 = load i64, i64* %5
%66 = sub nsw i64 %64, %65
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i64 %63, i64 %66)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [6 x i8] c"hello\00"
@.str.1 = [9 x i8] c"%ld\0A%ld\0A\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %1 to i8*
%6 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
br label %7
7: ; preds = %0, %7
%8 = phi i32 [ 0, %0 ], [ %10, %7 ]
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%10 = add nuw nsw i32 %8, 1
%11 = icmp eq i32 %10, 1000
br i1 %11, label %12, label %7
12: ; preds = %7
%13 = bitcast %struct.timeval* %2 to i8*
%14 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%15 = bitcast %struct.timeval* %3 to i8*
%16 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
br label %17
17: ; preds = %12, %17
%18 = phi i32 [ 0, %12 ], [ %20, %17 ]
%19 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 6)
%20 = add nuw nsw i32 %18, 1
%21 = icmp eq i32 %20, 1000
br i1 %21, label %22, label %17
22: ; preds = %17
%23 = bitcast %struct.timeval* %4 to i8*
%24 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%26 = load i32, i32* %25
%27 = mul nsw i32 %26, 1000000
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%29 = load i32, i32* %28
%30 = add nsw i32 %27, %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%33 = load i32, i32* %32
%34 = mul nsw i32 %33, 1000000
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%36 = load i32, i32* %35
%37 = add nsw i32 %34, %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%40 = load i32, i32* %39
%41 = mul nsw i32 %40, 1000000
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%43 = load i32, i32* %42
%44 = add nsw i32 %41, %43
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%47 = load i32, i32* %46
%48 = mul nsw i32 %47, 1000000
%49 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%50 = load i32, i32* %49
%51 = add nsw i32 %48, %50
%52 = sext i32 %51 to i64
%53 = sub nsw i64 %38, %31
%54 = sub nsw i64 %52, %45
%55 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i64 %53, i64 %54)
ret i32 0
}