#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 *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int strtoul(char *, char **, int /*<<< orphan*/);
int get_int_option(char *conf_path, char *name, int *val) {
  int fd;
  int cnt;
  char fname[512];
  char buf[256];
  char *endp;
  int tmp = 0;
  ;
  snprintf(fname, 512, "%s/%s", conf_path, name);
  if ((fd = open(fname, O_RDONLY)) < 0) {
    ;
    return -1;
  }
  cnt = read(fd, buf, 256);
  ;
  close(fd);
  if (cnt < 0 || !cnt) {
    return -1;
  }
  buf[cnt] = 0;
  *val = strtoul(buf, &endp, 0);
  if (endp == buf)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<get_int_option>:
push   %rbp
mov    %rsp,%rbp
sub    $0x340,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x33c(%rbp)
lea    -0x230(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    $0x200,%esi
lea    0xe74(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x230(%rbp),%rdi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    11be <get_int_option+0x6e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1250 <get_int_option+0x100>
mov    -0x24(%rbp),%edi
lea    -0x330(%rbp),%rsi
mov    $0x100,%edx
call   1050 <read@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
cmpl   $0x0,-0x28(%rbp)
jl     11f1 <get_int_option+0xa1>
cmpl   $0x0,-0x28(%rbp)
jne    11fd <get_int_option+0xad>
movl   $0xffffffff,-0x4(%rbp)
jmp    1250 <get_int_option+0x100>
movslq -0x28(%rbp),%rax
movb   $0x0,-0x330(%rbp,%rax,1)
lea    -0x330(%rbp),%rdi
lea    -0x338(%rbp),%rsi
xor    %edx,%edx
call   1070 <strtoul@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x338(%rbp),%rax
lea    -0x330(%rbp),%rcx
cmp    %rcx,%rax
jne    1249 <get_int_option+0xf9>
movl   $0xffffffff,-0x4(%rbp)
jmp    1250 <get_int_option+0x100>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x340,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_int_option>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x310,%rsp
mov    %rdx,%r14
mov    %rsi,%r8
mov    %rdi,%rcx
lea    0xe91(%rip),%rdx
lea    0x110(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x200,%esi
call   1030 <snprintf@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
js     11ea <get_int_option+0x9a>
mov    %eax,%ebx
lea    0x10(%rsp),%r15
mov    %eax,%edi
mov    %r15,%rsi
mov    $0x100,%edx
call   1050 <read@plt>
mov    %eax,%r12d
mov    %ebx,%edi
call   1040 <close@plt>
test   %r12d,%r12d
jle    11ea <get_int_option+0x9a>
mov    %r12d,%eax
movb   $0x0,0x10(%rsp,%rax,1)
lea    0x8(%rsp),%rsi
mov    %r15,%rdi
xor    %edx,%edx
call   1070 <strtoul@plt>
mov    %eax,(%r14)
xor    %ebp,%ebp
cmp    %r15,0x8(%rsp)
sete   %bpl
neg    %ebp
mov    %ebp,%eax
add    $0x310,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
@O_RDONLY = global i32 0
define i32 @get_int_option(i8* %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [512 x i8]
%11 = alloca [256 x i8]
%12 = alloca i8*
%13 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i32 0, i32* %13
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%15 = load i8*, i8** %5
%16 = load i8*, i8** %6
%17 = call i32 @snprintf(i8* %14, i32 512, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %16)
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* %18, i32 %19)
store i32 %20, i32* %8
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %3
store i32 -1, i32* %4
br label %47
23: ; preds = %3
%24 = load i32, i32* %8
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%26 = call i32 @read(i32 %24, i8* %25, i32 256)
store i32 %26, i32* %9
%27 = load i32, i32* %8
%28 = call i32 @close(i32 %27)
%29 = load i32, i32* %9
%30 = icmp slt i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %23
%32 = load i32, i32* %9
%33 = icmp ne i32 %32, 0
br i1 %33, label %35, label %34
34: ; preds = %31, %23
store i32 -1, i32* %4
br label %47
35: ; preds = %31
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 %37
store i8 0, i8* %38
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%40 = call i32 @strtoul(i8* %39, i8** %12, i32 0)
%41 = load i32*, i32** %7
store i32 %40, i32* %41
%42 = load i8*, i8** %12
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%44 = icmp eq i8* %42, %43
br i1 %44, label %45, label %46
45: ; preds = %35
store i32 -1, i32* %4
br label %47
46: ; preds = %35
store i32 0, i32* %4
br label %47
47: ; preds = %46, %45, %34, %22
%48 = load i32, i32* %4
ret i32 %48
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
@O_RDONLY = global i32 0
define i32 @get_int_option(i8* %0, i8* %1, i32* nocapture writeonly %2) {
%4 = alloca [512 x i8]
%5 = alloca [256 x i8]
%6 = alloca i8*
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%9 = bitcast i8** %6 to i8*
%10 = call i32 @snprintf(i8* %7, i32 512, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %7, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %25, label %14
14: ; preds = %3
%15 = call i32 @read(i32 %12, i8* %8, i32 256)
%16 = call i32 @close(i32 %12)
%17 = icmp sgt i32 %15, 0
br i1 %17, label %18, label %25
18: ; preds = %14
%19 = zext i32 %15 to i64
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %19
store i8 0, i8* %20
%21 = call i32 @strtoul(i8* %8, i8** %6, i32 0)
store i32 %21, i32* %2
%22 = load i8*, i8** %6
%23 = icmp eq i8* %22, %8
%24 = sext i1 %23 to i32
br label %25
25: ; preds = %18, %14, %3
%26 = phi i32 [ -1, %3 ], [ -1, %14 ], [ %24, %18 ]
ret i32 %26
}