#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 atoi(char *);
int /*<<< orphan*/ close(int);
int open(char const *, int /*<<< orphan*/);
scalar_t__ read(int, char *, int);
int read_sys_int(const char *path) {
  int ret = -1;
  int fd = open(path, O_RDONLY);
  char buf[16] = "";
  if (fd > 0) {
    if (read(fd, buf, 16) > 0)
      ret = atoi(buf);
    close(fd);
  }
  return ret;
}


x86 assembly (clang, -O0):
<read_sys_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
cmpl   $0x0,-0x10(%rbp)
jle    11c1 <read_sys_int+0x71>
mov    -0x10(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
jle    11b9 <read_sys_int+0x69>
lea    -0x20(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_sys_int>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
test   %eax,%eax
jle    1181 <read_sys_int+0x41>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x10,%edx
call   1040 <read@plt>
test   %rax,%rax
jle    1188 <read_sys_int+0x48>
mov    %rsp,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
jmp    118d <read_sys_int+0x4d>
mov    $0xffffffff,%ebp
jmp    1194 <read_sys_int+0x54>
mov    $0xffffffff,%ebp
mov    %ebx,%edi
call   1030 <close@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
define i32 @read_sys_int(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [16 x i8]
store i8* %0, i8** %2
store i32 -1, i32* %3
%6 = load i8*, i8** %2
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* %6, i32 %7)
store i32 %8, i32* %4
%9 = bitcast [16 x i8]* %5 to i8*
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %23
12: ; preds = %1
%13 = load i32, i32* %4
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%15 = call i64 @read(i32 %13, i8* %14, i32 16)
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %3
br label %20
20: ; preds = %17, %12
%21 = load i32, i32* %4
%22 = call i32 @close(i32 %21)
br label %23
23: ; preds = %20, %1
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define i32 @read_sys_int(i8* nocapture %0) {
%2 = alloca [16 x i8]
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* %0, i32 %3)
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%6 = icmp sgt i32 %4, 0
br i1 %6, label %7, label %15
7: ; preds = %1
%8 = call i64 @read(i32 %4, i8* %5, i32 16)
%9 = icmp sgt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @atoi(i8* %5)
br label %12
12: ; preds = %10, %7
%13 = phi i32 [ %11, %10 ], [ -1, %7 ]
%14 = tail call i32 @close(i32 %4)
br label %15
15: ; preds = %12, %1
%16 = phi i32 [ %13, %12 ], [ -1, %1 ]
ret i32 %16
}