#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 size_t ssize_t;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
size_t read(int, char *, int);
int sscanf(char *, char *, unsigned long *, unsigned long *);
unsigned long get_uptime(int fd) {
  char buf[80];
  ssize_t len;
  unsigned long u1, u2;
  lseek(fd, SEEK_SET, 0);
  len = read(fd, buf, sizeof buf);
  if (len < 0) {
    perror("read");
    return 0;
  }
  buf[len] = '\0';
  if (sscanf(buf, "%lu.%lu", &u1, &u2) != 2) {
    perror("sscanf");
    return 0;
  }
  return u1 * 100 + u2;
}


x86 assembly (clang, -O0):
<get_uptime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <lseek@plt>
mov    -0xc(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x50,%edx
call   1040 <read@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jae    119a <get_uptime+0x5a>
lea    0xe78(%rip),%rdi
call   1060 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ea <get_uptime+0xaa>
mov    -0x68(%rbp),%rax
movb   $0x0,-0x60(%rbp,%rax,1)
lea    -0x60(%rbp),%rdi
lea    0xe57(%rip),%rsi
lea    -0x70(%rbp),%rdx
lea    -0x78(%rbp),%rcx
call   1050 <sscanf@plt>
cmp    $0x2,%eax
je     11dd <get_uptime+0x9d>
lea    0xe42(%rip),%rdi
call   1060 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ea <get_uptime+0xaa>
imul   $0x64,-0x70(%rbp),%rax
add    -0x78(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_uptime>:
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %edi,%ebx
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <lseek@plt>
lea    0x10(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x50,%edx
call   1040 <read@plt>
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xe87(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rsp,%rcx
mov    %r14,%rdi
call   1050 <sscanf@plt>
cmp    $0x2,%eax
jne    11a0 <get_uptime+0x60>
imul   $0x64,0x8(%rsp),%rax
add    (%rsp),%rax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe61(%rip),%rdi
call   1060 <perror@plt>
xor    %eax,%eax
jmp    1198 <get_uptime+0x58>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [5 x i8] c"read\00"
@.str.1 = [8 x i8] c"%lu.%lu\00"
@.str.2 = [7 x i8] c"sscanf\00"
define i64 @get_uptime(i32 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca [80 x i8]
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i32 %0, i32* %3
%8 = load i32, i32* %3
%9 = load i32, i32* @SEEK_SET
%10 = call i32 @lseek(i32 %8, i32 %9, i32 0)
%11 = load i32, i32* %3
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%13 = call i64 @read(i32 %11, i8* %12, i32 80)
store i64 %13, i64* %5
%14 = load i64, i64* %5
%15 = icmp ult i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* %2
br label %31
18: ; preds = %1
%19 = load i64, i64* %5
%20 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 %19
store i8 0, i8* %20
%21 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%22 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64* %6, i64* %7)
%23 = icmp ne i32 %22, 2
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i64 0, i64* %2
br label %31
26: ; preds = %18
%27 = load i64, i64* %6
%28 = mul i64 %27, 100
%29 = load i64, i64* %7
%30 = add i64 %28, %29
store i64 %30, i64* %2
br label %31
31: ; preds = %26, %24, %16
%32 = load i64, i64* %2
ret i64 %32
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str.1 = [8 x i8] c"%lu.%lu\00"
@.str.2 = [7 x i8] c"sscanf\00"
define i64 @get_uptime(i32 %0) {
%2 = alloca [80 x i8]
%3 = alloca i64
%4 = alloca i64
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%6 = bitcast i64* %3 to i8*
%7 = bitcast i64* %4 to i8*
%8 = load i32, i32* @SEEK_SET
%9 = tail call i32 @lseek(i32 %0, i32 %8, i32 0)
%10 = call i64 @read(i32 %0, i8* %5, i32 80)
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %10
store i8 0, i8* %11
%12 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64* %3, i64* %4)
%13 = icmp eq i32 %12, 2
br i1 %13, label %16, label %14
14: ; preds = %1
%15 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %21
16: ; preds = %1
%17 = load i64, i64* %3
%18 = mul i64 %17, 100
%19 = load i64, i64* %4
%20 = add i64 %18, %19
br label %21
21: ; preds = %16, %14
%22 = phi i64 [ 0, %14 ], [ %20, %16 ]
ret i64 %22
}