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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int sscanf(char *, char *, unsigned long *, unsigned long *);
int /*<<< orphan*/ stderr;
void read_uptime(unsigned long long *uptime) {
  FILE *fp = NULL;
  char line[128];
  unsigned long up_sec, up_cent;
  int err = 0;
  if ((fp = fopen(""
                  "/proc/uptime",
                  "r")) == NULL) {
    err = 1;
  } else if (fgets(line, sizeof(line), fp) == NULL) {
    err = 1;
  } else if (sscanf(line, "%lu.%lu", &up_sec, &up_cent) == 2) {
    *uptime = (unsigned long long)up_sec * 100 + (unsigned long long)up_cent;
  } else {
    err = 1;
  }
  if (fp != NULL) {
    fclose(fp);
  }
  if (err) {
    fprintf(stderr, ("Cannot read %s\n"),
            ""
            "/proc/uptime");
    exit(2);
  }
}


x86 assembly (clang, -O0):
<read_uptime>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0xa4(%rbp)
lea    0xe78(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11b1 <read_uptime+0x51>
movl   $0x1,-0xa4(%rbp)
jmp    1238 <read_uptime+0xd8>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x80,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    11df <read_uptime+0x7f>
movl   $0x1,-0xa4(%rbp)
jmp    1233 <read_uptime+0xd3>
lea    -0x90(%rbp),%rdi
lea    0xe22(%rip),%rsi
lea    -0x98(%rbp),%rdx
lea    -0xa0(%rbp),%rcx
call   1060 <sscanf@plt>
cmp    $0x2,%eax
jne    1224 <read_uptime+0xc4>
imul   $0x64,-0x98(%rbp),%rcx
64
add    -0xa0(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    122e <read_uptime+0xce>
movl   $0x1,-0xa4(%rbp)
jmp    1233 <read_uptime+0xd3>
jmp    1238 <read_uptime+0xd8>
cmpq   $0x0,-0x10(%rbp)
je     124c <read_uptime+0xec>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0xa4(%rbp)
je     127f <read_uptime+0x11f>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xdae(%rip),%rsi
lea    0xd90(%rip),%rdx
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_uptime>:
push   %r14
push   %rbx
sub    $0x98,%rsp
mov    %rdi,%r14
lea    0xe8c(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11e5 <read_uptime+0x85>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x80,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11dd <read_uptime+0x7d>
lea    0xe69(%rip),%rsi
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rdx
mov    %rsp,%rcx
call   1060 <sscanf@plt>
cmp    $0x2,%eax
jne    11dd <read_uptime+0x7d>
imul   $0x64,0x8(%rsp),%rax
add    (%rsp),%rax
mov    %rax,(%r14)
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x98,%rsp
pop    %rbx
pop    %r14
ret
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
lea    0xe04(%rip),%rdx
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>

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"%lu.%lu\00"
@stderr = global i32 0
@.str.3 = [16 x i8] c"Cannot read %s\0A\00"
define void @read_uptime(i64* %0) {
%2 = alloca i64*
%3 = alloca i32*
%4 = alloca [128 x i8]
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
store i64* %0, i64** %2
store i32* null, i32** %3
store i32 0, i32* %7
%8 = 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* %8, i32** %3
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 1, i32* %7
br label %30
11: ; preds = %1
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%13 = load i32*, i32** %3
%14 = call i32* @fgets(i8* %12, i32 128, i32* %13)
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %11
store i32 1, i32* %7
br label %29
17: ; preds = %11
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%19 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i64* %5, i64* %6)
%20 = icmp eq i32 %19, 2
br i1 %20, label %21, label %27
21: ; preds = %17
%22 = load i64, i64* %5
%23 = mul i64 %22, 100
%24 = load i64, i64* %6
%25 = add i64 %23, %24
%26 = load i64*, i64** %2
store i64 %25, i64* %26
br label %28
27: ; preds = %17
store i32 1, i32* %7
br label %28
28: ; preds = %27, %21
br label %29
29: ; preds = %28, %16
br label %30
30: ; preds = %29, %10
%31 = load i32*, i32** %3
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32*, i32** %3
%35 = call i32 @fclose(i32* %34)
br label %36
36: ; preds = %33, %30
%37 = load i32, i32* %7
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%42 = call i32 @exit(i32 2)
unreachable
43: ; preds = %36
ret void
}

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"%lu.%lu\00"
@stderr = global i32 0
@.str.3 = [16 x i8] c"Cannot read %s\0A\00"
define void @read_uptime(i64* nocapture writeonly %0) {
%2 = alloca [128 x i8]
%3 = alloca i64
%4 = alloca i64
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%6 = bitcast i64* %3 to i8*
%7 = bitcast i64* %4 to i8*
%8 = 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))
%9 = icmp eq i32* %8, null
br i1 %9, label %18, label %10
10: ; preds = %1
%11 = call i32* @fgets(i8* %5, i32 128, i32* %8)
%12 = icmp eq i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i64* %3, i64* %4)
%15 = icmp eq i32 %14, 2
br i1 %15, label %22, label %16
16: ; preds = %13, %10
%17 = call i32 @fclose(i32* %8)
br label %18
18: ; preds = %1, %16
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 2)
unreachable
22: ; preds = %13
%23 = load i64, i64* %3
%24 = mul i64 %23, 100
%25 = load i64, i64* %4
%26 = add i64 %24, %25
store i64 %26, i64* %0
%27 = call i32 @fclose(i32* %8)
ret void
}