#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 */
struct sysentry {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
void get_sys_uptime(struct sysentry *unused_se, char *uptime) {
  FILE *f;
  char buf[80];
  f = fopen("/proc/uptime", "r");
  if (!f) {
    fprintf(stderr, "Could not open /proc/uptime\n");
    sprintf(uptime, "-");
    return;
  }
  if ((fgets(buf, 80, f)) != NULL) {
    char *value;
    value = strchr(buf, ' ');
    *value = '\0';
    sprintf(uptime, "%s", buf);
  } else {
    sprintf(uptime, "-");
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<get_sys_uptime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe86(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c1 <get_sys_uptime+0x61>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    0xe6a(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe77(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
jmp    122c <get_sys_uptime+0xcc>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x50,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1211 <get_sys_uptime+0xb1>
lea    -0x70(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x70(%rbp),%rdx
lea    0xe29(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
jmp    1223 <get_sys_uptime+0xc3>
mov    -0x10(%rbp),%rdi
lea    0xe10(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sys_uptime>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%r14
lea    0xe8d(%rip),%rdi
lea    0xe93(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11bc <get_sys_uptime+0x5c>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x50,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11d9 <get_sys_uptime+0x79>
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
movb   $0x0,(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
jmp    11df <get_sys_uptime+0x7f>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
call   1070 <fprintf@plt>
movw   $0x2d,(%r14)
jmp    11e7 <get_sys_uptime+0x87>
movw   $0x2d,(%r14)
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sysentry = type { i32 }
@.str = [13 x i8] c"/proc/uptime\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [29 x i8] c"Could not open /proc/uptime\0A\00"
@.str.3 = [2 x i8] c"-\00"
@.str.4 = [3 x i8] c"%s\00"
define void @get_sys_uptime(%struct.sysentry* %0, i8* %1) {
%3 = alloca %struct.sysentry*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [80 x i8]
%7 = alloca i8*
store %struct.sysentry* %0, %struct.sysentry** %3
store i8* %1, i8** %4
%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** %5
%9 = load i32*, i32** %5
%10 = icmp ne i32* %9, null
br i1 %10, label %16, label %11
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%14 = load i8*, i8** %4
%15 = call i32 (i8*, i8*, ...) @sprintf(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %34
16: ; preds = %2
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%18 = load i32*, i32** %5
%19 = call i32* @fgets(i8* %17, i32 80, i32* %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %28
21: ; preds = %16
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%23 = call i8* @strchr(i8* %22, i8 signext 32)
store i8* %23, i8** %7
%24 = load i8*, i8** %7
store i8 0, i8* %24
%25 = load i8*, i8** %4
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%27 = call i32 (i8*, i8*, ...) @sprintf(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %26)
br label %31
28: ; preds = %16
%29 = load i8*, i8** %4
%30 = call i32 (i8*, i8*, ...) @sprintf(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %28, %21
%32 = load i32*, i32** %5
%33 = call i32 @fclose(i32* %32)
br label %34
34: ; preds = %31, %11
ret void
}

LLVM IR (-O2):
%struct.sysentry = type { i32 }
@.str = [13 x i8] c"/proc/uptime\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [29 x i8] c"Could not open /proc/uptime\0A\00"
define void @get_sys_uptime(%struct.sysentry* nocapture readnone %0, i8* %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%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 %7, label %11
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%10 = bitcast i8* %1 to i16*
store i16 45, i16* %10
br label %21
11: ; preds = %2
%12 = call i32* @fgets(i8* %4, i32 80, i32* %5)
%13 = icmp eq i32* %12, null
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = call i8* @strchr(i8* %4, i8 signext 32)
store i8 0, i8* %15
%16 = call i8* @strcpy(i8* dereferenceable(1) %1, i8* %4)
br label %19
17: ; preds = %11
%18 = bitcast i8* %1 to i16*
store i16 45, i16* %18
br label %19
19: ; preds = %17, %14
%20 = call i32 @fclose(i32* %5)
br label %21
21: ; preds = %19, %7
ret void
}