#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);
char *strchr(char *, char const);
int read_sys_int2(const char *path, const char c) {
  int ret = -1;
  int fd = open(path, O_RDONLY);
  char buf[32] = "";
  if (fd > 0) {
    if (read(fd, buf, 32) > 0) {
      char *p = strchr(buf, c);
      if (p)
        ret = atoi(p + 1);
    }
    close(fd);
  }
  return ret;
}


x86 assembly (clang, -O0):
<read_sys_int2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movl   $0xffffffff,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
cmpl   $0x0,-0x14(%rbp)
jle    11fc <read_sys_int2+0x9c>
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x20,%edx
call   1060 <read@plt>
cmp    $0x0,%rax
jle    11f4 <read_sys_int2+0x94>
lea    -0x40(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     11ef <read_sys_int2+0x8f>
mov    -0x48(%rbp),%rdi
add    $0x1,%rdi
call   1080 <atoi@plt>
mov    %eax,-0x10(%rbp)
jmp    11f4 <read_sys_int2+0x94>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_sys_int2>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,%r14d
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
test   %eax,%eax
jle    11bc <read_sys_int2+0x6c>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x20,%edx
call   1050 <read@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jle    11b3 <read_sys_int2+0x63>
movsbl %r14b,%esi
mov    %rsp,%rdi
call   1030 <strchr@plt>
test   %rax,%rax
je     11b3 <read_sys_int2+0x63>
add    $0x1,%rax
mov    %rax,%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1040 <close@plt>
jmp    11c1 <read_sys_int2+0x71>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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