#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 {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
double times(struct tms *);
int main(void) {
  FILE *file;
  double tott;
  struct tms runtimes;
  int clk_tck = 1;
  tott = times(&runtimes);
  sleep(1);
  tott = times(&runtimes) - tott;
  clk_tck = (int)(tott / 10.0) * 10;
  printf("\nSlept for 1 sec.\n");
  printf("Measured time in clock_t was: %f\n\n", tott);
  printf("Therefore, CLK_TCK is probably = %d\n\n", clk_tck);
  file = fopen("../include/clk_tck.h", "w");
  fprintf(file, "#ifndef CLK_TCK\n");
  fprintf(file, "#define CLK_TCK %d\n", clk_tck);
  fprintf(file, "#endif\n");
  fclose(file);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
lea    -0x20(%rbp),%rdi
call   1060 <times@plt>
movsd  %xmm0,-0x18(%rbp)
mov    $0x1,%edi
call   1090 <sleep@plt>
lea    -0x20(%rbp),%rdi
call   1060 <times@plt>
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe42(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
imul   $0xa,%eax,%eax
mov    %eax,-0x24(%rbp)
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  -0x18(%rbp),%xmm0
lea    0xe35(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe5f(%rip),%rdi
lea    0xe6d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe5b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xe57(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <times@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    %rbx,%rdi
call   1070 <times@plt>
subsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movapd %xmm0,%xmm1
divsd  0xe2d(%rip),%xmm1
cvttsd2si %xmm1,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%ebp
lea    0xeb2(%rip),%rdi
call   1030 <puts@plt>
lea    0xe19(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xe28(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe3e(%rip),%rdi
lea    0xe4c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0xe3f(%rip),%rdi
mov    $0x10,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10a0 <fwrite@plt>
lea    0xe37(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xe38(%rip),%rdi
mov    $0x7,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.tms = type { i32 }
@.str = [19 x i8] c"\0ASlept for 1 sec.\0A\00"
@.str.1 = [35 x i8] c"Measured time in clock_t was: %f\0A\0A\00"
@.str.2 = [38 x i8] c"Therefore, CLK_TCK is probably = %d\0A\0A\00"
@.str.3 = [21 x i8] c"../include/clk_tck.h\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [17 x i8] c"#ifndef CLK_TCK\0A\00"
@.str.6 = [20 x i8] c"#define CLK_TCK %d\0A\00"
@.str.7 = [8 x i8] c"#endif\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca double
%4 = alloca %struct.tms
%5 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %5
%6 = call double @times(%struct.tms* %4)
store double %6, double* %3
%7 = call i32 @sleep(i32 1)
%8 = call double @times(%struct.tms* %4)
%9 = load double, double* %3
%10 = fsub double %8, %9
store double %10, double* %3
%11 = load double, double* %3
%12 = fdiv double %11, 1.000000e+01
%13 = fptosi double %12 to i32
%14 = mul nsw i32 %13, 10
store i32 %14, i32* %5
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%16 = load double, double* %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), double %16)
%18 = load i32, i32* %5
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %20, i32** %2
%21 = load i32*, i32** %2
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%23 = load i32*, i32** %2
%24 = load i32, i32* %5
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %24)
%26 = load i32*, i32** %2
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%28 = load i32*, i32** %2
%29 = call i32 @fclose(i32* %28)
%30 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.tms = type { i32 }
@.str.1 = [35 x i8] c"Measured time in clock_t was: %f\0A\0A\00"
@.str.2 = [38 x i8] c"Therefore, CLK_TCK is probably = %d\0A\0A\00"
@.str.3 = [21 x i8] c"../include/clk_tck.h\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [17 x i8] c"#ifndef CLK_TCK\0A\00"
@.str.6 = [20 x i8] c"#define CLK_TCK %d\0A\00"
@.str.7 = [8 x i8] c"#endif\0A\00"
@str = [18 x i8] c"\0ASlept for 1 sec.\00"
define i32 @main() {
%1 = alloca %struct.tms
%2 = bitcast %struct.tms* %1 to i8*
%3 = call double @times(%struct.tms* %1)
%4 = tail call i32 @sleep(i32 1)
%5 = call double @times(%struct.tms* %1)
%6 = fsub double %5, %3
%7 = fdiv double %6, 1.000000e+01
%8 = fptosi double %7 to i32
%9 = mul nsw i32 %8, 10
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), double %6)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%13 = tail call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i64 16, i64 1, i32* %13)
%15 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %9)
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i64 7, i64 1, i32* %13)
%17 = tail call i32 @fclose(i32* %13)
%18 = tail call i32 @exit(i32 0)
unreachable
}