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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err_exit(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ errno;
int open(char *, int /*<<< orphan*/, int);
size_t read(int, char *, int);
int sscanf(char *, char *, double *, double *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void uptime(double *uptime_secs, double *idle_secs) {
  size_t num_bytes_read;
  int fd;
  char read_buf[128];
  fd = open("/proc/uptime", O_RDONLY, S_IRUSR | S_IRGRP | S_IROTH);
  if (fd != -1) {
    if ((num_bytes_read = read(fd, read_buf, 128)) != -1) {
      if (sscanf(read_buf, "%lf %lf", &(*uptime_secs), &(*idle_secs)) == 2) {
        close(fd);
      } else {
        err_exit("Erron on sscanf, %s, line no %d\n", strerror(errno), 35);
      }
    } else {
      err_exit("Erron on read, %s %d\n", strerror(errno), 38);
    }
  } else {
    err_exit("Error on open, %s %d\n", strerror(errno), 41);
  }
}


x86 assembly (clang, -O0):
<uptime>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
mov    0x2e3d(%rip),%rax
mov    (%rax),%edx
mov    0x2e44(%rip),%rax
or     (%rax),%edx
mov    0x2e33(%rip),%rax
or     (%rax),%edx
lea    0xe62(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
je     124f <uptime+0xef>
mov    -0x1c(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
call   1040 <read@plt>
mov    %rax,-0x18(%rbp)
cmp    $0xffffffffffffffff,%rax
je     1229 <uptime+0xc9>
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe25(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x2,%eax
jne    1203 <uptime+0xa3>
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
jmp    1224 <uptime+0xc4>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %eax,%esi
lea    0xdfb(%rip),%rdi
mov    $0x23,%edx
call   1050 <err_exit@plt>
jmp    124a <uptime+0xea>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %eax,%esi
lea    0xdf6(%rip),%rdi
mov    $0x26,%edx
call   1050 <err_exit@plt>
jmp    1270 <uptime+0x110>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %eax,%esi
lea    0xde6(%rip),%rdi
mov    $0x29,%edx
call   1050 <err_exit@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uptime>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e70(%rip),%rax
mov    0x2e41(%rip),%rcx
mov    0x2e4a(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    (%rax),%esi
mov    0x2e35(%rip),%rax
or     (%rax),%edx
lea    0xe64(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11e9 <uptime+0x89>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x80,%edx
call   1040 <read@plt>
cmp    $0xffffffffffffffff,%rax
je     1207 <uptime+0xa7>
lea    0xe49(%rip),%rsi
mov    %rsp,%rdi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1060 <sscanf@plt>
cmp    $0x2,%eax
jne    1225 <uptime+0xc5>
mov    %ebp,%edi
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <close@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe4e(%rip),%rdi
mov    %eax,%esi
mov    $0x29,%edx
jmp    1241 <uptime+0xe1>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe1a(%rip),%rdi
mov    %eax,%esi
mov    $0x26,%edx
jmp    1241 <uptime+0xe1>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xddb(%rip),%rdi
mov    %eax,%esi
mov    $0x23,%edx
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <err_exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/proc/uptime\00"
@O_RDONLY = global i32 0
@S_IRUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [8 x i8] c"%lf %lf\00"
@.str.2 = [33 x i8] c"Erron on sscanf, %s, line no %d\0A\00"
@errno = global i32 0
@.str.3 = [22 x i8] c"Erron on read, %s %d\0A\00"
@.str.4 = [22 x i8] c"Error on open, %s %d\0A\00"
define void @uptime(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
%5 = alloca i64
%6 = alloca i32
%7 = alloca [128 x i8]
store double* %0, double** %3
store double* %1, double** %4
%8 = load i32, i32* @O_RDONLY
%9 = load i32, i32* @S_IRUSR
%10 = load i32, i32* @S_IRGRP
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IROTH
%13 = or i32 %11, %12
%14 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %41
17: ; preds = %2
%18 = load i32, i32* %6
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%20 = call i64 @read(i32 %18, i8* %19, i32 128)
store i64 %20, i64* %5
%21 = icmp ne i64 %20, -1
br i1 %21, label %22, label %36
22: ; preds = %17
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%24 = load double*, double** %3
%25 = load double*, double** %4
%26 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double* %24, double* %25)
%27 = icmp eq i32 %26, 2
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i32, i32* %6
%30 = call i32 @close(i32 %29)
br label %35
31: ; preds = %22
%32 = load i32, i32* @errno
%33 = call i32 @strerror(i32 %32)
%34 = call i32 @err_exit(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %33, i32 35)
br label %35
35: ; preds = %31, %28
br label %40
36: ; preds = %17
%37 = load i32, i32* @errno
%38 = call i32 @strerror(i32 %37)
%39 = call i32 @err_exit(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %38, i32 38)
br label %40
40: ; preds = %36, %35
br label %45
41: ; preds = %2
%42 = load i32, i32* @errno
%43 = call i32 @strerror(i32 %42)
%44 = call i32 @err_exit(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %43, i32 41)
br label %45
45: ; preds = %41, %40
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"/proc/uptime\00"
@O_RDONLY = global i32 0
@S_IRUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [8 x i8] c"%lf %lf\00"
@.str.2 = [33 x i8] c"Erron on sscanf, %s, line no %d\0A\00"
@errno = global i32 0
@.str.3 = [22 x i8] c"Erron on read, %s %d\0A\00"
@.str.4 = [22 x i8] c"Error on open, %s %d\0A\00"
define void @uptime(double* %0, double* %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDONLY
%6 = load i32, i32* @S_IRUSR
%7 = load i32, i32* @S_IRGRP
%8 = or i32 %7, %6
%9 = load i32, i32* @S_IROTH
%10 = or i32 %8, %9
%11 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %29, label %13
13: ; preds = %2
%14 = call i64 @read(i32 %11, i8* %4, i32 128)
%15 = icmp eq i64 %14, -1
br i1 %15, label %25, label %16
16: ; preds = %13
%17 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double* %0, double* %1)
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 @close(i32 %11)
br label %33
21: ; preds = %16
%22 = load i32, i32* @errno
%23 = tail call i32 @strerror(i32 %22)
%24 = tail call i32 @err_exit(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 35)
br label %33
25: ; preds = %13
%26 = load i32, i32* @errno
%27 = tail call i32 @strerror(i32 %26)
%28 = tail call i32 @err_exit(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %27, i32 38)
br label %33
29: ; preds = %2
%30 = load i32, i32* @errno
%31 = tail call i32 @strerror(i32 %30)
%32 = tail call i32 @err_exit(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %31, i32 41)
br label %33
33: ; preds = %25, %21, %19, %29
ret void
}