#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, long *, long *);
long uptime() {
  FILE *in = fopen("/proc/uptime", "r");
  long uptim = 0, a, b;
  if (in) {
    if (2 == fscanf(in, "%ld.%ld", &a, &b))
      uptim = a * 100 + b;
    fclose(in);
  }
  return uptim;
}


x86 assembly (clang, -O0):
<uptime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec1(%rip),%rdi
lea    0xec7(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     119f <uptime+0x6f>
mov    -0x8(%rbp),%rdi
lea    0xea2(%rip),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1040 <fscanf@plt>
mov    %eax,%ecx
mov    $0x2,%eax
cmp    %ecx,%eax
jne    1196 <uptime+0x66>
imul   $0x64,-0x18(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uptime>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xec2(%rip),%rdi
lea    0xec8(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1189 <uptime+0x59>
mov    %rax,%r14
lea    0xeb6(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rax,%rdi
call   1040 <fscanf@plt>
imul   $0x64,0x10(%rsp),%rcx
add    0x8(%rsp),%rcx
xor    %ebx,%ebx
cmp    $0x2,%eax
cmove  %rcx,%rbx
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    118b <uptime+0x5b>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/proc/uptime\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"%ld.%ld\00"
define i64 @uptime() {
%1 = alloca i32*
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = 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* %5, i32** %1
store i64 0, i64* %2
%6 = load i32*, i32** %1
%7 = icmp ne i32* %6, null
br i1 %7, label %8, label %20
8: ; preds = %0
%9 = load i32*, i32** %1
%10 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i64* %3, i64* %4)
%11 = icmp eq i32 2, %10
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i64, i64* %3
%14 = mul nsw i64 %13, 100
%15 = load i64, i64* %4
%16 = add nsw i64 %14, %15
store i64 %16, i64* %2
br label %17
17: ; preds = %12, %8
%18 = load i32*, i32** %1
%19 = call i32 @fclose(i32* %18)
br label %20
20: ; preds = %17, %0
%21 = load i64, i64* %2
ret i64 %21
}

LLVM IR (-O2):
@.str = [13 x i8] c"/proc/uptime\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"%ld.%ld\00"
define i64 @uptime() {
%1 = alloca i64
%2 = alloca i64
%3 = 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))
%4 = bitcast i64* %1 to i8*
%5 = bitcast i64* %2 to i8*
%6 = icmp eq i32* %3, null
br i1 %6, label %16, label %7
7: ; preds = %0
%8 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i64* %1, i64* %2)
%9 = icmp eq i32 %8, 2
%10 = load i64, i64* %1
%11 = mul nsw i64 %10, 100
%12 = load i64, i64* %2
%13 = add nsw i64 %11, %12
%14 = select i1 %9, i64 %13, i64 0
%15 = call i32 @fclose(i32* %3)
br label %16
16: ; preds = %7, %0
%17 = phi i64 [ %14, %7 ], [ 0, %0 ]
ret i64 %17
}