#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 */

/* Variables and functions */
long atol(char *);
double dtime();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ getuid();
int /*<<< orphan*/ printf(char *, long, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  long i, n;
  double t = 0.0;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s duration\n", argv[0]);
    return 1;
  }
  n = atol(argv[1]);
  t = dtime();
  for (i = 0; i < n; i++) {
    getuid();
  }
  t = dtime() - t;
  printf("syscall getuid %ld times in %f seconds\n", n, t);
  printf("   %.9f usec/syscall\n", 1000000.0 * t / n);
  printf("   %ld syscalls/second\n", (long)(n / t));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11a0 <main+0x50>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1262 <main+0x112>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atol@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1060 <dtime@plt>
movsd  %xmm0,-0x28(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    11eb <main+0x9b>
mov    $0x0,%al
call   1030 <getuid@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11c5 <main+0x75>
mov    $0x0,%al
call   1060 <dtime@plt>
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rsi
movsd  -0x28(%rbp),%xmm0
lea    0xe10(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0xde5(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
cvtsi2sdq -0x20(%rbp),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rsi
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cvtsi2sdq -0x20(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
cvttsd2si %xmm0,%rsi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x1,%edi
jg     1180 <main+0x30>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe98(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%r14d
jmp    122c <main+0xdc>
mov    0x8(%rsi),%rdi
call   1070 <atol@plt>
mov    %rax,%rbp
xor    %r14d,%r14d
xor    %eax,%eax
call   1060 <dtime@plt>
movsd  %xmm0,(%rsp)
test   %rbp,%rbp
jle    11bd <main+0x6d>
mov    %rbp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1030 <getuid@plt>
add    $0xffffffffffffffff,%rbx
jne    11b0 <main+0x60>
xor    %eax,%eax
call   1060 <dtime@plt>
subsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
lea    0xe47(%rip),%rdi
mov    %rbp,%rsi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0xe19(%rip),%xmm0
cvtsi2sd %rbp,%xmm1
movsd  %xmm1,0x8(%rsp)
mulsd  (%rsp),%xmm0
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rsi
lea    0xe3d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
divsd  (%rsp),%xmm0
cvttsd2si %xmm0,%rsi
lea    0xe35(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"Usage: %s duration\0A\00"
@.str.1 = [40 x i8] c"syscall getuid %ld times in %f seconds\0A\00"
@.str.2 = [22 x i8] c" %.9f usec/syscall\0A\00"
@.str.3 = [24 x i8] c" %ld syscalls/second\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %8
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %52
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @atol(i8* %20)
store i64 %21, i64* %7
%22 = call double (...) @dtime()
store double %22, double* %8
store i64 0, i64* %6
br label %23
23: ; preds = %29, %17
%24 = load i64, i64* %6
%25 = load i64, i64* %7
%26 = icmp slt i64 %24, %25
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = call i32 (...) @getuid()
br label %29
29: ; preds = %27
%30 = load i64, i64* %6
%31 = add nsw i64 %30, 1
store i64 %31, i64* %6
br label %23
32: ; preds = %23
%33 = call double (...) @dtime()
%34 = load double, double* %8
%35 = fsub double %33, %34
store double %35, double* %8
%36 = load i64, i64* %7
%37 = load double, double* %8
%38 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i64 %36, double %37)
%39 = load double, double* %8
%40 = fmul double 1.000000e+06, %39
%41 = load i64, i64* %7
%42 = sitofp i64 %41 to double
%43 = fdiv double %40, %42
%44 = fptosi double %43 to i64
%45 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i64 %44)
%46 = load i64, i64* %7
%47 = sitofp i64 %46 to double
%48 = load double, double* %8
%49 = fdiv double %47, %48
%50 = fptosi double %49 to i64
%51 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i64 %50)
store i32 0, i32* %3
br label %52
52: ; preds = %32, %11
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"Usage: %s duration\0A\00"
@.str.1 = [40 x i8] c"syscall getuid %ld times in %f seconds\0A\00"
@.str.2 = [22 x i8] c" %.9f usec/syscall\0A\00"
@.str.3 = [24 x i8] c" %ld syscalls/second\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %31
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @atol(i8* %10)
%12 = tail call double (...) @dtime()
%13 = icmp sgt i64 %11, 0
br i1 %13, label %14, label %19
14: ; preds = %8, %14
%15 = phi i64 [ %17, %14 ], [ 0, %8 ]
%16 = tail call i32 (...) @getuid()
%17 = add nuw nsw i64 %15, 1
%18 = icmp eq i64 %17, %11
br i1 %18, label %19, label %14
19: ; preds = %14, %8
%20 = tail call double (...) @dtime()
%21 = fsub double %20, %12
%22 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i64 %11, double %21)
%23 = fmul double %21, 1.000000e+06
%24 = sitofp i64 %11 to double
%25 = fdiv double %23, %24
%26 = fptosi double %25 to i64
%27 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i64 %26)
%28 = fdiv double %24, %21
%29 = fptosi double %28 to i64
%30 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i64 %29)
br label %31
31: ; preds = %19, %4
%32 = phi i32 [ 1, %4 ], [ 0, %19 ]
ret i32 %32
}