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

/* Variables and functions */
int /*<<< orphan*/ _SC_CLK_TCK;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, float *);
int /*<<< orphan*/ printf(char *, long const, long const);
long sysconf(int /*<<< orphan*/);
void dump_time(void) {
  float uptime_secs = 0.0F;
  const long rate = sysconf(_SC_CLK_TCK);
  FILE *f = fopen("/proc/uptime", "r");
  if (!f)
    return;
  fscanf(f, "%f", &uptime_secs);
  fclose(f);
  const long ticks = (long)(rate * uptime_secs);
  printf("  \"time\": { \"ticks\": %ld, \"rate\": %ld}", ticks, rate);
}


x86 assembly (clang, -O0):
<dump_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
mov    %rax,-0x10(%rbp)
lea    0xe87(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1199 <dump_time+0x49>
jmp    11de <dump_time+0x8e>
mov    -0x18(%rbp),%rdi
lea    0xe6b(%rip),%rsi
lea    -0x4(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cvtsi2ssq -0x10(%rbp),%xmm0
mulss  -0x4(%rbp),%xmm0
cvttss2si %xmm0,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe39(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_time>:
push   %r14
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
mov    %rax,%r14
lea    0xe8c(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c3 <dump_time+0x73>
mov    %rax,%rbx
lea    0xe80(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
cvtsi2ss %r14,%xmm0
mulss  0x4(%rsp),%xmm0
cvttss2si %xmm0,%rsi
lea    0xe57(%rip),%rdi
mov    %r14,%rdx
call   1040 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@_SC_CLK_TCK = global i32 0
@.str = [13 x i8] c"/proc/uptime\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%f\00"
@.str.3 = [39 x i8] c" \22time\22: { \22ticks\22: %ld, \22rate\22: %ld}\00"
define void @dump_time() {
%1 = alloca float
%2 = alloca i64
%3 = alloca i32*
%4 = alloca i64
store float 0.000000e+00, float* %1
%5 = load i32, i32* @_SC_CLK_TCK
%6 = call i64 @sysconf(i32 %5)
store i64 %6, i64* %2
%7 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp ne i32* %8, null
br i1 %9, label %11, label %10
10: ; preds = %0
br label %24
11: ; preds = %0
%12 = load i32*, i32** %3
%13 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %1)
%14 = load i32*, i32** %3
%15 = call i32 @fclose(i32* %14)
%16 = load i64, i64* %2
%17 = sitofp i64 %16 to float
%18 = load float, float* %1
%19 = fmul float %17, %18
%20 = fptosi float %19 to i64
store i64 %20, i64* %4
%21 = load i64, i64* %4
%22 = load i64, i64* %2
%23 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i64 %21, i64 %22)
br label %24
24: ; preds = %11, %10
ret void
}

LLVM IR (-O2):
@_SC_CLK_TCK = global i32 0
@.str = [13 x i8] c"/proc/uptime\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%f\00"
@.str.3 = [39 x i8] c" \22time\22: { \22ticks\22: %ld, \22rate\22: %ld}\00"
define void @dump_time() {
%1 = alloca float
%2 = bitcast float* %1 to i8*
store float 0.000000e+00, float* %1
%3 = load i32, i32* @_SC_CLK_TCK
%4 = tail call i64 @sysconf(i32 %3)
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %15, label %7
7: ; preds = %0
%8 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %1)
%9 = call i32 @fclose(i32* %5)
%10 = sitofp i64 %4 to float
%11 = load float, float* %1
%12 = fmul float %11, %10
%13 = fptosi float %12 to i64
%14 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i64 %13, i64 %4)
br label %15
15: ; preds = %0, %7
ret void
}