#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*/ SEEK_SET;
scalar_t__ append_buf(char const *, int, int, char *, size_t *);
scalar_t__ copy_buf(int, int, char *, size_t *);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int read_file(int fd, const char *uptime, size_t uptimelen, int outfd,
              char *outbuf, size_t *outlen) {
  lseek(fd, SEEK_SET, 0);
  if (append_buf(uptime, uptimelen, outfd, outbuf, outlen) < 0)
    return -1;
  if (copy_buf(fd, outfd, outbuf, outlen) < 0)
    return -1;
  if (append_buf("\n", 1, outfd, outbuf, outlen) < 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <lseek@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    %eax,%esi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1050 <append_buf@plt>
cmp    $0x0,%rax
jge    1191 <read_file+0x61>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f3 <read_file+0xc3>
mov    -0x8(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1040 <copy_buf@plt>
cmp    $0x0,%rax
jge    11ba <read_file+0x8a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f3 <read_file+0xc3>
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
lea    0xe34(%rip),%rdi
mov    $0x1,%esi
call   1050 <append_buf@plt>
cmp    $0x0,%rax
jge    11ec <read_file+0xbc>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f3 <read_file+0xc3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
mov    %r8,%r15
mov    %ecx,%r12d
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <lseek@plt>
mov    %rbx,%rdi
mov    %r13d,%esi
mov    %r12d,%edx
mov    %r15,%rcx
mov    %r14,%r8
call   1050 <append_buf@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
js     11b0 <read_file+0x80>
mov    %ebp,%edi
mov    %r12d,%esi
mov    %r15,%rdx
mov    %r14,%rcx
call   1040 <copy_buf@plt>
test   %rax,%rax
js     11b0 <read_file+0x80>
lea    0xe6a(%rip),%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %r15,%rcx
mov    %r14,%r8
call   1050 <append_buf@plt>
mov    %rax,%rbx
sar    $0x3f,%rbx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [2 x i8] c"\0A\00"
define i32 @read_file(i32 %0, i8* %1, i64 %2, i32 %3, i8* %4, i64* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64*
store i32 %0, i32* %8
store i8* %1, i8** %9
store i64 %2, i64* %10
store i32 %3, i32* %11
store i8* %4, i8** %12
store i64* %5, i64** %13
%14 = load i32, i32* %8
%15 = load i32, i32* @SEEK_SET
%16 = call i32 @lseek(i32 %14, i32 %15, i32 0)
%17 = load i8*, i8** %9
%18 = load i64, i64* %10
%19 = trunc i64 %18 to i32
%20 = load i32, i32* %11
%21 = load i8*, i8** %12
%22 = load i64*, i64** %13
%23 = call i64 @append_buf(i8* %17, i32 %19, i32 %20, i8* %21, i64* %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %6
store i32 -1, i32* %7
br label %42
26: ; preds = %6
%27 = load i32, i32* %8
%28 = load i32, i32* %11
%29 = load i8*, i8** %12
%30 = load i64*, i64** %13
%31 = call i64 @copy_buf(i32 %27, i32 %28, i8* %29, i64* %30)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %26
store i32 -1, i32* %7
br label %42
34: ; preds = %26
%35 = load i32, i32* %11
%36 = load i8*, i8** %12
%37 = load i64*, i64** %13
%38 = call i64 @append_buf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1, i32 %35, i8* %36, i64* %37)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %34
store i32 -1, i32* %7
br label %42
41: ; preds = %34
store i32 0, i32* %7
br label %42
42: ; preds = %41, %40, %33, %25
%43 = load i32, i32* %7
ret i32 %43
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [2 x i8] c"\0A\00"
define i32 @read_file(i32 %0, i8* %1, i64 %2, i32 %3, i8* %4, i64* %5) {
%7 = load i32, i32* @SEEK_SET
%8 = tail call i32 @lseek(i32 %0, i32 %7, i32 0)
%9 = trunc i64 %2 to i32
%10 = tail call i64 @append_buf(i8* %1, i32 %9, i32 %3, i8* %4, i64* %5)
%11 = icmp slt i64 %10, 0
br i1 %11, label %19, label %12
12: ; preds = %6
%13 = tail call i64 @copy_buf(i32 %0, i32 %3, i8* %4, i64* %5)
%14 = icmp slt i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %12
%16 = tail call i64 @append_buf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1, i32 %3, i8* %4, i64* %5)
%17 = ashr i64 %16, 63
%18 = trunc i64 %17 to i32
br label %19
19: ; preds = %15, %12, %6
%20 = phi i32 [ -1, %6 ], [ -1, %12 ], [ %18, %15 ]
ret i32 %20
}