#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 */
typedef int uint64_t;
struct timeval {
  long tv_sec;
  long tv_usec;
};
struct rusage {
  struct timeval ru_utime;
};

/* Variables and functions */
int /*<<< orphan*/ RUSAGE_SELF;
int /*<<< orphan*/ getrusage(int /*<<< orphan*/, struct rusage *);
int /*<<< orphan*/ printf(char *, long);
int main(void) {
  struct rusage r;
  struct timeval start;
  struct timeval end;
  getrusage(RUSAGE_SELF, &r);
  start = r.ru_utime;
  for (uint64_t i = 0; i < 100000000; i++)
    ;
  getrusage(RUSAGE_SELF, &r);
  end = r.ru_utime;
  long res =
      ((end.tv_sec - start.tv_sec) * 1000000L) + end.tv_usec - start.tv_usec;
  printf("Time elapsed in microseconds: %ld\n", res);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2eaa(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1040 <getrusage@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x5f5e100,-0x3c(%rbp)
jge    1178 <main+0x58>
jmp    116a <main+0x4a>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1158 <main+0x38>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1040 <getrusage@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
sub    -0x28(%rbp),%rax
imul   $0xf4240,%rax,%rax
add    -0x30(%rbp),%rax
sub    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rsi
lea    0xe40(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2eae(%rip),%r14
mov    (%r14),%edi
lea    0x8(%rsp),%r15
mov    %r15,%rsi
call   1040 <getrusage@plt>
mov    0x8(%rsp),%rbx
mov    0x10(%rsp),%r12
mov    (%r14),%edi
mov    %r15,%rsi
call   1040 <getrusage@plt>
mov    0x8(%rsp),%rax
sub    %rbx,%rax
mov    0x10(%rsp),%rcx
sub    %r12,%rcx
imul   $0xf4240,%rax,%rsi
add    %rcx,%rsi
lea    0xe88(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.rusage = type { %struct.timeval }
%struct.timeval = type { i64, i64 }
@RUSAGE_SELF = global i32 0
@.str = [35 x i8] c"Time elapsed in microseconds: %ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.rusage
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca i32
%6 = alloca i64
store i32 0, i32* %1
%7 = load i32, i32* @RUSAGE_SELF
%8 = call i32 @getrusage(i32 %7, %struct.rusage* %2)
%9 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i32 0, i32 0
%10 = bitcast %struct.timeval* %3 to i8*
%11 = bitcast %struct.timeval* %9 to i8*
store i32 0, i32* %5
br label %12
12: ; preds = %16, %0
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 100000000
br i1 %14, label %15, label %19
15: ; preds = %12
br label %16
16: ; preds = %15
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 1
store i32 %18, i32* %5
br label %12
19: ; preds = %12
%20 = load i32, i32* @RUSAGE_SELF
%21 = call i32 @getrusage(i32 %20, %struct.rusage* %2)
%22 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i32 0, i32 0
%23 = bitcast %struct.timeval* %4 to i8*
%24 = bitcast %struct.timeval* %22 to i8*
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%26 = load i64, i64* %25
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%28 = load i64, i64* %27
%29 = sub nsw i64 %26, %28
%30 = mul nsw i64 %29, 1000000
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%32 = load i64, i64* %31
%33 = add nsw i64 %30, %32
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%35 = load i64, i64* %34
%36 = sub nsw i64 %33, %35
store i64 %36, i64* %6
%37 = load i64, i64* %6
%38 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i64 %37)
ret i32 0
}

LLVM IR (-O2):
%struct.rusage = type { %struct.timeval }
%struct.timeval = type { i64, i64 }
@RUSAGE_SELF = global i32 0
@.str = [35 x i8] c"Time elapsed in microseconds: %ld\0A\00"
define i32 @main() {
%1 = alloca %struct.rusage
%2 = bitcast %struct.rusage* %1 to i8*
%3 = load i32, i32* @RUSAGE_SELF
%4 = call i32 @getrusage(i32 %3, %struct.rusage* %1)
%5 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 0, i32 0
%6 = load i64, i64* %5
%7 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 0, i32 1
%8 = load i64, i64* %7
%9 = load i32, i32* @RUSAGE_SELF
%10 = call i32 @getrusage(i32 %9, %struct.rusage* %1)
%11 = load i64, i64* %5
%12 = load i64, i64* %7
%13 = sub nsw i64 %11, %6
%14 = mul nsw i64 %13, 1000000
%15 = sub i64 %12, %8
%16 = add i64 %15, %14
%17 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i64 %16)
ret i32 0
}