#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 /*<<< orphan*/ uid_t;
struct timespec {
  long double tv_sec;
  long double tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_PROCESS_CPUTIME_ID;
int /*<<< orphan*/ SYS_getuid;
long atol(char *);
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
int errno;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, long, long double, long double, double);
int /*<<< orphan*/ syscall(int /*<<< orphan*/);
int /*<<< orphan*/ ts_subtract(struct timespec *, struct timespec *,
                               struct timespec *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  struct timespec start_time, end_time, elapsed_time;
  uid_t uid;
  long iterations, i;
  double per_call;
  if (argc != 2) {
    usage(argv[0]);
    return 1;
  }
  iterations = atol(argv[1]);
  if (iterations < 0) {
    usage(argv[0]);
    return 1;
  }
  if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start_time)) {
    perror("clock_gettime");
    return errno;
  }
  for (i = iterations; i; i--)
    uid = syscall(SYS_getuid);
  if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end_time)) {
    perror("clock_gettime");
    return errno;
  }
  ts_subtract(&elapsed_time, &end_time, &start_time);
  per_call = (elapsed_time.tv_sec * 1000000000.0L + elapsed_time.tv_nsec) /
             (double)iterations;
  printf("%ld calls in %ld.%09ld s (%lf ns/call)\n", iterations,
         elapsed_time.tv_sec, elapsed_time.tv_nsec, per_call);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ab <main+0x3b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fc <main+0x18c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atol@plt>
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
jge    11df <main+0x6f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fc <main+0x18c>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%rax
je     1218 <main+0xa8>
lea    0xe02(%rip),%rdi
call   1090 <perror@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12fc <main+0x18c>
mov    -0x80(%rbp),%rax
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
je     1259 <main+0xe9>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
call   1060 <syscall@plt>
mov    %eax,-0x74(%rbp)
mov    -0x88(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x88(%rbp)
jmp    1223 <main+0xb3>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%rax
je     1292 <main+0x122>
lea    0xd88(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d50(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12fc <main+0x18c>
lea    -0x70(%rbp),%rdi
lea    -0x50(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1040 <ts_subtract@plt>
fldt   -0x70(%rbp)
fldt   -0x60(%rbp)
flds   0xd51(%rip)
fmulp  %st,%st(2)
faddp  %st,%st(1)
cvtsi2sdq -0x80(%rbp),%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
fldl   -0x98(%rbp)
fdivrp %st,%st(1)
fstpl  -0x90(%rbp)
mov    -0x80(%rbp),%rsi
fldt   -0x70(%rbp)
fldt   -0x60(%rbp)
movsd  -0x90(%rbp),%xmm0
ff
mov    %rsp,%rax
fstpt  0x10(%rax)
fstpt  (%rax)
lea    0xd22(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    124a <main+0xda>
mov    0x8(%rbx),%rdi
call   1080 <atol@plt>
test   %rax,%rax
js     124a <main+0xda>
mov    %rax,%r14
mov    0x2e42(%rip),%r15
mov    (%r15),%edi
lea    0x70(%rsp),%rsi
call   1030 <clock_gettime@plt>
test   %rax,%rax
jne    1266 <main+0xf6>
test   %r14,%r14
je     11df <main+0x6f>
mov    0x2e08(%rip),%r12
mov    %r14,%rbx
nopl   0x0(%rax,%rax,1)
mov    (%r12),%edi
call   1060 <syscall@plt>
add    $0xffffffffffffffff,%rbx
jne    11d0 <main+0x60>
mov    (%r15),%edi
lea    0x50(%rsp),%rsi
call   1030 <clock_gettime@plt>
test   %rax,%rax
jne    1266 <main+0xf6>
lea    0x30(%rsp),%rdi
lea    0x50(%rsp),%rsi
lea    0x70(%rsp),%rdx
call   1040 <ts_subtract@plt>
fldt   0x30(%rsp)
fldt   0x40(%rsp)
fld    %st(1)
fmuls  0xdeb(%rip)
fadd   %st(1),%st
cvtsi2sd %r14,%xmm0
movsd  %xmm0,0x28(%rsp)
fdivl  0x28(%rsp)
fstpl  0x20(%rsp)
movsd  0x20(%rsp),%xmm0
fstpt  0x10(%rsp)
fstpt  (%rsp)
lea    0xdd4(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
jmp    1257 <main+0xe7>
mov    (%rbx),%rdi
call   1070 <usage@plt>
mov    $0x1,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd97(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d5f(%rip),%rax
mov    (%rax),%eax
jmp    1257 <main+0xe7>

LLVM IR (-O0):
%struct.timespec = type { x86_fp80, x86_fp80 }
@CLOCK_PROCESS_CPUTIME_ID = global i32 0
@.str = [14 x i8] c"clock_gettime\00"
@errno = global i32 0
@SYS_getuid = global i32 0
@.str.1 = [40 x i8] c"%ld calls in %ld.%09ld s (%lf ns/call)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.timespec
%7 = alloca %struct.timespec
%8 = alloca %struct.timespec
%9 = alloca i32
%10 = alloca i64
%11 = alloca i64
%12 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @usage(i8* %18)
store i32 1, i32* %3
br label %76
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i64 @atol(i8* %23)
store i64 %24, i64* %10
%25 = load i64, i64* %10
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %20
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 @usage(i8* %30)
store i32 1, i32* %3
br label %76
32: ; preds = %20
%33 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
%34 = call i64 @clock_gettime(i32 %33, %struct.timespec* %6)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%38 = load i32, i32* @errno
store i32 %38, i32* %3
br label %76
39: ; preds = %32
%40 = load i64, i64* %10
store i64 %40, i64* %11
br label %41
41: ; preds = %47, %39
%42 = load i64, i64* %11
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %50
44: ; preds = %41
%45 = load i32, i32* @SYS_getuid
%46 = call i32 @syscall(i32 %45)
store i32 %46, i32* %9
br label %47
47: ; preds = %44
%48 = load i64, i64* %11
%49 = add nsw i64 %48, -1
store i64 %49, i64* %11
br label %41
50: ; preds = %41
%51 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
%52 = call i64 @clock_gettime(i32 %51, %struct.timespec* %7)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %50
%55 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%56 = load i32, i32* @errno
store i32 %56, i32* %3
br label %76
57: ; preds = %50
%58 = call i32 @ts_subtract(%struct.timespec* %8, %struct.timespec* %7, %struct.timespec* %6)
%59 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 0
%60 = load x86_fp80, x86_fp80* %59
%61 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 1
%62 = load x86_fp80, x86_fp80* %61
%63 = call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %60, x86_fp80 0xK401CEE6B280000000000, x86_fp80 %62)
%64 = load i64, i64* %10
%65 = sitofp i64 %64 to double
%66 = fpext double %65 to x86_fp80
%67 = fdiv x86_fp80 %63, %66
%68 = fptrunc x86_fp80 %67 to double
store double %68, double* %12
%69 = load i64, i64* %10
%70 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 0
%71 = load x86_fp80, x86_fp80* %70
%72 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 1
%73 = load x86_fp80, x86_fp80* %72
%74 = load double, double* %12
%75 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i64 %69, x86_fp80 %71, x86_fp80 %73, double %74)
store i32 0, i32* %3
br label %76
76: ; preds = %57, %54, %36, %27, %15
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
%struct.timespec = type { x86_fp80, x86_fp80 }
@CLOCK_PROCESS_CPUTIME_ID = global i32 0
@.str = [14 x i8] c"clock_gettime\00"
@errno = global i32 0
@SYS_getuid = global i32 0
@.str.1 = [40 x i8] c"%ld calls in %ld.%09ld s (%lf ns/call)\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = alloca %struct.timespec
%6 = bitcast %struct.timespec* %3 to i8*
%7 = bitcast %struct.timespec* %4 to i8*
%8 = bitcast %struct.timespec* %5 to i8*
%9 = icmp eq i32 %0, 2
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i32 @usage(i8* %11)
br label %55
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i64 @atol(i8* %15)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i8*, i8** %1
%20 = tail call i32 @usage(i8* %19)
br label %55
21: ; preds = %13
%22 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
%23 = call i64 @clock_gettime(i32 %22, %struct.timespec* %3)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = icmp eq i64 %16, 0
br i1 %26, label %36, label %30
27: ; preds = %21
%28 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%29 = load i32, i32* @errno
br label %55
30: ; preds = %25, %30
%31 = phi i64 [ %34, %30 ], [ %16, %25 ]
%32 = load i32, i32* @SYS_getuid
%33 = call i32 @syscall(i32 %32)
%34 = add nsw i64 %31, -1
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %30
36: ; preds = %30, %25
%37 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
%38 = call i64 @clock_gettime(i32 %37, %struct.timespec* %4)
%39 = icmp eq i64 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %36
%41 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%42 = load i32, i32* @errno
br label %55
43: ; preds = %36
%44 = call i32 @ts_subtract(%struct.timespec* %5, %struct.timespec* %4, %struct.timespec* %3)
%45 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i64 0, i32 0
%46 = load x86_fp80, x86_fp80* %45
%47 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i64 0, i32 1
%48 = load x86_fp80, x86_fp80* %47
%49 = call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %46, x86_fp80 0xK401CEE6B280000000000, x86_fp80 %48)
%50 = sitofp i64 %16 to double
%51 = fpext double %50 to x86_fp80
%52 = fdiv x86_fp80 %49, %51
%53 = fptrunc x86_fp80 %52 to double
%54 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i64 %16, x86_fp80 %46, x86_fp80 %48, double %53)
br label %55
55: ; preds = %43, %40, %27, %18, %10
%56 = phi i32 [ 1, %10 ], [ 1, %18 ], [ %29, %27 ], [ %42, %40 ], [ 0, %43 ]
ret i32 %56
}