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

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
double strtod(char *, char **);
int time(int /*<<< orphan*/ *);
int get_boot_time() {
  int uptime = 0;
  FILE *fp = fopen("/proc/uptime", "r");
  if (fp != NULL) {
    char buf[BUFSIZ];
    char *b = fgets(buf, BUFSIZ, fp);
    if (b == buf) {
      char *end_ptr;
      double upsecs = strtod(buf, &end_ptr);
      uptime = (int)upsecs;
    }
    fclose(fp);
  }
  time_t now = time(NULL);
  return now - uptime;
}


x86 assembly (clang, -O0):
<get_boot_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xea0(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11fe <get_boot_time+0xae>
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1050 <fgets@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
mov    %rcx,-0x28(%rbp)
cmp    %rax,-0x28(%rbp)
jne    11ee <get_boot_time+0x9e>
mov    -0x48(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x38(%rbp)
cvttsd2si -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
sub    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_boot_time>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe9a(%rip),%rdi
lea    0xea0(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ca <get_boot_time+0x7a>
mov    %rax,%r14
mov    %rsp,%r15
mov    0x2e5c(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rbx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
mov    (%rax),%esi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1050 <fgets@plt>
xor    %r12d,%r12d
cmp    %rbx,%rax
jne    11bd <get_boot_time+0x6d>
lea    -0x28(%rbp),%rsi
mov    %rbx,%rdi
call   1030 <strtod@plt>
cvttsd2si %xmm0,%r12d
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r15,%rsp
jmp    11cd <get_boot_time+0x7d>
xor    %r12d,%r12d
xor    %edi,%edi
call   1060 <time@plt>
sub    %r12d,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/proc/uptime\00"
@.str.1 = [2 x i8] c"r\00"
@BUFSIZ = global i32 0
define i32 @get_boot_time() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca double
%8 = alloca i32
store i32 0, i32* %1
%9 = 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* %9, i32** %2
%10 = load i32*, i32** %2
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %30
12: ; preds = %0
%13 = load i32, i32* @BUFSIZ
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %3
%16 = alloca i8, i64 %14
store i64 %14, i64* %4
%17 = load i32, i32* @BUFSIZ
%18 = load i32*, i32** %2
%19 = call i8* @fgets(i8* %16, i32 %17, i32* %18)
store i8* %19, i8** %5
%20 = load i8*, i8** %5
%21 = icmp eq i8* %20, %16
br i1 %21, label %22, label %26
22: ; preds = %12
%23 = call double @strtod(i8* %16, i8** %6)
store double %23, double* %7
%24 = load double, double* %7
%25 = fptosi double %24 to i32
store i32 %25, i32* %1
br label %26
26: ; preds = %22, %12
%27 = load i32*, i32** %2
%28 = call i32 @fclose(i32* %27)
%29 = load i8*, i8** %3
br label %30
30: ; preds = %26, %0
%31 = call i32 @time(i32* null)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = load i32, i32* %1
%34 = sub nsw i32 %32, %33
ret i32 %34
}

LLVM IR (-O2):
@.str = [13 x i8] c"/proc/uptime\00"
@.str.1 = [2 x i8] c"r\00"
@BUFSIZ = global i32 0
define i32 @get_boot_time() {
%1 = alloca i8*
%2 = 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))
%3 = icmp eq i32* %2, null
br i1 %3, label %19, label %4
4: ; preds = %0
%5 = load i32, i32* @BUFSIZ
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = load i32, i32* @BUFSIZ
%10 = call i8* @fgets(i8* %8, i32 %9, i32* %2)
%11 = icmp eq i8* %10, %8
br i1 %11, label %12, label %16
12: ; preds = %4
%13 = bitcast i8** %1 to i8*
%14 = call double @strtod(i8* %8, i8** %1)
%15 = fptosi double %14 to i32
br label %16
16: ; preds = %12, %4
%17 = phi i32 [ %15, %12 ], [ 0, %4 ]
%18 = call i32 @fclose(i32* %2)
br label %19
19: ; preds = %16, %0
%20 = phi i32 [ %17, %16 ], [ 0, %0 ]
%21 = call i32 @time(i32* null)
%22 = sub nsw i32 %21, %20
ret i32 %22
}