#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 tms {
  scalar_t__ tms_stime;
  scalar_t__ tms_utime;
};
typedef int clock_t;

/* Variables and functions */
float CLOCKS_PER_SEC;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ _SC_CLK_TCK;
int clock();
int /*<<< orphan*/ err_exit(char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ getppid();
int /*<<< orphan*/ printf(char *, float, float);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
long sysconf(int /*<<< orphan*/);
int times(struct tms *);
int main(int argc, char *argv[]) {
  clock_t cpu_time;
  struct tms buf;
  long clock_ticks = 0;
  int i = 0;
  clock_ticks = sysconf(_SC_CLK_TCK);
  printf("CLOCKS_PER_SEC=%ld, sysconf(_SC_CLK_TCK)=%ld\n", CLOCKS_PER_SEC,
         clock_ticks);
  for (; i < 9000000; i++) {
    getppid();
  }
  if ((cpu_time = clock()) == -1) {
    err_exit("Error on clock() %s\n", strerror(errno));
  }
  if (times(&buf) == -1) {
    err_exit("Error on times() %s\n", strerror(errno));
  }
  printf("clock() %ld, cpu time (clocks per sec) %.2f\n", cpu_time,
         ((float)cpu_time) / (CLOCKS_PER_SEC));
  printf("user cpu time %.2f, system cpu time %.2f\n",
         ((float)buf.tms_utime) / clock_ticks,
         ((float)buf.tms_stime) / clock_ticks);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
mov    %rax,-0x30(%rbp)
mov    0x2e2a(%rip),%rax
movss  (%rax),%xmm0
cvtsi2ssq -0x30(%rbp),%xmm1
lea    0xe31(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x895440,-0x34(%rbp)
jge    11f6 <main+0x76>
mov    $0x0,%al
call   1080 <getppid@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11d4 <main+0x54>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1225 <main+0xa5>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %eax,%esi
lea    0xe0e(%rip),%rdi
call   1050 <err_exit@plt>
lea    -0x28(%rbp),%rdi
call   1060 <times@plt>
cmp    $0xffffffff,%eax
jne    1253 <main+0xd3>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %eax,%esi
lea    0xdf5(%rip),%rdi
call   1050 <err_exit@plt>
cvtsi2ssl -0x14(%rbp),%xmm0
cvtsi2ssl -0x14(%rbp),%xmm1
mov    0x2d84(%rip),%rax
divss  (%rax),%xmm1
lea    0xde9(%rip),%rdi
call   1040 <printf@plt>
cvtsi2ssq -0x20(%rbp),%xmm0
cvtsi2ssq -0x30(%rbp),%xmm1
divss  %xmm1,%xmm0
cvtsi2ssq -0x28(%rbp),%xmm1
cvtsi2ssq -0x30(%rbp),%xmm2
divss  %xmm2,%xmm1
lea    0xdea(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
mov    0x2e4c(%rip),%r14
movss  (%r14),%xmm0
cvtsi2ss %rax,%xmm1
lea    0xe53(%rip),%rdi
movss  %xmm1,0x4(%rsp)
call   1040 <printf@plt>
mov    $0x895440,%ebx
nopl   (%rax)
xor    %eax,%eax
call   1080 <getppid@plt>
add    $0xffffffff,%ebx
jne    11c0 <main+0x40>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11f6 <main+0x76>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xe3f(%rip),%rdi
mov    %eax,%esi
call   1050 <err_exit@plt>
lea    0x8(%rsp),%rdi
call   1060 <times@plt>
cmp    $0xffffffff,%eax
jne    1221 <main+0xa1>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xe29(%rip),%rdi
mov    %eax,%esi
call   1050 <err_exit@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
movaps %xmm0,%xmm1
divss  (%r14),%xmm1
lea    0xe21(%rip),%rdi
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
cvtsi2ssq 0x10(%rsp),%xmm0
movss  0x4(%rsp),%xmm2
divss  %xmm2,%xmm0
xorps  %xmm1,%xmm1
cvtsi2ssq 0x8(%rsp),%xmm1
divss  %xmm2,%xmm1
lea    0xe20(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.tms = type { i64, i64 }
@_SC_CLK_TCK = global i32 0
@.str = [46 x i8] c"CLOCKS_PER_SEC=%ld, sysconf(_SC_CLK_TCK)=%ld\0A\00"
@CLOCKS_PER_SEC = global float 0.000000e+00
@.str.1 = [21 x i8] c"Error on clock() %s\0A\00"
@errno = global i32 0
@.str.2 = [21 x i8] c"Error on times() %s\0A\00"
@.str.3 = [45 x i8] c"clock() %ld, cpu time (clocks per sec) %.2f\0A\00"
@.str.4 = [42 x i8] c"user cpu time %.2f, system cpu time %.2f\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.tms
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %8
store i32 0, i32* %9
%10 = load i32, i32* @_SC_CLK_TCK
%11 = call i64 @sysconf(i32 %10)
store i64 %11, i64* %8
%12 = load float, float* @CLOCKS_PER_SEC
%13 = load i64, i64* %8
%14 = sitofp i64 %13 to float
%15 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), float %12, float %14)
br label %16
16: ; preds = %21, %2
%17 = load i32, i32* %9
%18 = icmp slt i32 %17, 9000000
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = call i32 (...) @getppid()
br label %21
21: ; preds = %19
%22 = load i32, i32* %9
%23 = add nsw i32 %22, 1
store i32 %23, i32* %9
br label %16
24: ; preds = %16
%25 = call i32 (...) @clock()
store i32 %25, i32* %6
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i32, i32* @errno
%29 = call i32 @strerror(i32 %28)
%30 = call i32 @err_exit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %27, %24
%32 = call i32 @times(%struct.tms* %7)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load i32, i32* @errno
%36 = call i32 @strerror(i32 %35)
%37 = call i32 @err_exit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %34, %31
%39 = load i32, i32* %6
%40 = sitofp i32 %39 to float
%41 = load i32, i32* %6
%42 = sitofp i32 %41 to float
%43 = load float, float* @CLOCKS_PER_SEC
%44 = fdiv float %42, %43
%45 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), float %40, float %44)
%46 = getelementptr inbounds %struct.tms, %struct.tms* %7, i32 0, i32 1
%47 = load i64, i64* %46
%48 = sitofp i64 %47 to float
%49 = load i64, i64* %8
%50 = sitofp i64 %49 to float
%51 = fdiv float %48, %50
%52 = getelementptr inbounds %struct.tms, %struct.tms* %7, i32 0, i32 0
%53 = load i64, i64* %52
%54 = sitofp i64 %53 to float
%55 = load i64, i64* %8
%56 = sitofp i64 %55 to float
%57 = fdiv float %54, %56
%58 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), float %51, float %57)
%59 = load i32, i32* @EXIT_SUCCESS
%60 = call i32 @exit(i32 %59)
unreachable
}

LLVM IR (-O2):
%struct.tms = type { i64, i64 }
@_SC_CLK_TCK = global i32 0
@.str = [46 x i8] c"CLOCKS_PER_SEC=%ld, sysconf(_SC_CLK_TCK)=%ld\0A\00"
@CLOCKS_PER_SEC = global float 0.000000e+00
@.str.1 = [21 x i8] c"Error on clock() %s\0A\00"
@errno = global i32 0
@.str.2 = [21 x i8] c"Error on times() %s\0A\00"
@.str.3 = [45 x i8] c"clock() %ld, cpu time (clocks per sec) %.2f\0A\00"
@.str.4 = [42 x i8] c"user cpu time %.2f, system cpu time %.2f\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.tms
%4 = bitcast %struct.tms* %3 to i8*
%5 = load i32, i32* @_SC_CLK_TCK
%6 = tail call i64 @sysconf(i32 %5)
%7 = load float, float* @CLOCKS_PER_SEC
%8 = sitofp i64 %6 to float
%9 = tail call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), float %7, float %8)
br label %10
10: ; preds = %2, %10
%11 = phi i32 [ 0, %2 ], [ %13, %10 ]
%12 = tail call i32 (...) @getppid()
%13 = add nuw nsw i32 %11, 1
%14 = icmp eq i32 %13, 9000000
br i1 %14, label %15, label %10
15: ; preds = %10
%16 = tail call i32 (...) @clock()
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i32, i32* @errno
%20 = tail call i32 @strerror(i32 %19)
%21 = tail call i32 @err_exit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %18, %15
%23 = call i32 @times(%struct.tms* %3)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i32, i32* @errno
%27 = tail call i32 @strerror(i32 %26)
%28 = tail call i32 @err_exit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %25, %22
%30 = sitofp i32 %16 to float
%31 = load float, float* @CLOCKS_PER_SEC
%32 = fdiv float %30, %31
%33 = tail call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), float %30, float %32)
%34 = getelementptr inbounds %struct.tms, %struct.tms* %3, i64 0, i32 1
%35 = load i64, i64* %34
%36 = sitofp i64 %35 to float
%37 = fdiv float %36, %8
%38 = getelementptr inbounds %struct.tms, %struct.tms* %3, i64 0, i32 0
%39 = load i64, i64* %38
%40 = sitofp i64 %39 to float
%41 = fdiv float %40, %8
%42 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), float %37, float %41)
%43 = load i32, i32* @EXIT_SUCCESS
%44 = tail call i32 @exit(i32 %43)
unreachable
}