#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 /*<<< orphan*/ close(int);
int open(char const *, int /*<<< orphan*/);
scalar_t__ read(int, char *, int);
scalar_t__ strtol(char *, char **, int);
void read_int(const char *filename, int *var) {
  int fd, n;
  char buffer[32];
  char *buffer_endptr = NULL;
  fd = open(filename, O_RDONLY);
  if (fd == -1)
    return;
  if (read(fd, buffer, 31) > 0) {
    n = (int)strtol(buffer, &buffer_endptr, 10);
    if (*buffer != '\0' && *buffer_endptr == '\0')
      *var = n;
  }
  close(fd);
}


x86 assembly (clang, -O0):
<read_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    117c <read_int+0x3c>
jmp    11df <read_int+0x9f>
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x1f,%edx
call   1040 <read@plt>
cmp    $0x0,%rax
jle    11d7 <read_int+0x97>
lea    -0x40(%rbp),%rdi
lea    -0x48(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x18(%rbp)
movsbl -0x40(%rbp),%eax
cmp    $0x0,%eax
je     11d2 <read_int+0x92>
mov    -0x48(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11d2 <read_int+0x92>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    11d7 <read_int+0x97>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_int>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
movq   $0x0,0x8(%rsp)
mov    0x2e8f(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11ab <read_int+0x6b>
mov    %eax,%ebp
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0x1f,%edx
call   1040 <read@plt>
test   %rax,%rax
jle    11a4 <read_int+0x64>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
cmpb   $0x0,0x10(%rsp)
je     11a4 <read_int+0x64>
mov    0x8(%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    11a4 <read_int+0x64>
mov    %eax,(%rbx)
mov    %ebp,%edi
call   1030 <close@plt>
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
define void @read_int(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [32 x i8]
%8 = alloca i8*
store i8* %0, i8** %3
store i32* %1, i32** %4
store i8* null, i8** %8
%9 = load i8*, i8** %3
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* %9, i32 %10)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %2
br label %40
15: ; preds = %2
%16 = load i32, i32* %5
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%18 = call i64 @read(i32 %16, i8* %17, i32 31)
%19 = icmp sgt i64 %18, 0
br i1 %19, label %20, label %37
20: ; preds = %15
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%22 = call i64 @strtol(i8* %21, i8** %8, i32 10)
%23 = trunc i64 %22 to i32
store i32 %23, i32* %6
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %36
28: ; preds = %20
%29 = load i8*, i8** %8
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = load i32, i32* %6
%35 = load i32*, i32** %4
store i32 %34, i32* %35
br label %36
36: ; preds = %33, %28, %20
br label %37
37: ; preds = %36, %15
%38 = load i32, i32* %5
%39 = call i32 @close(i32 %38)
br label %40
40: ; preds = %37, %14
ret void
}

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