#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int atoi(char *);
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int sapi_get_max_conn() {
  int fd;
  int ret;
  char buf[10];
  fd = open("/proc/sys/net/core/somaxconn", O_RDONLY);
  if (fd < 0)
    return -1;
  ret = read(fd, buf, sizeof(buf));
  if (ret > 0)
    ret = atoi(buf);
  close(fd);
  if (ret >= 0)
    return ret;
  return -1;
}


x86 assembly (clang, -O0):
<sapi_get_max_conn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1176 <sapi_get_max_conn+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <sapi_get_max_conn+0x84>
mov    -0x8(%rbp),%edi
lea    -0x16(%rbp),%rsi
mov    $0xa,%edx
call   1040 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11a0 <sapi_get_max_conn+0x60>
lea    -0x16(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x0,-0xc(%rbp)
jl     11bd <sapi_get_max_conn+0x7d>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c4 <sapi_get_max_conn+0x84>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sapi_get_max_conn>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
lea    0xeaa(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     1195 <sapi_get_max_conn+0x55>
mov    %eax,%ebx
lea    0xe(%rsp),%rsi
mov    %eax,%edi
mov    $0xa,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    1180 <sapi_get_max_conn+0x40>
lea    0xe(%rsp),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1030 <close@plt>
test   %ebp,%ebp
mov    $0xffffffff,%eax
cmovns %ebp,%eax
jmp    119a <sapi_get_max_conn+0x5a>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"/proc/sys/net/core/somaxconn\00"
@O_RDONLY = global i32 0
define i32 @sapi_get_max_conn() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [10 x i8]
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 -1, i32* %1
br label %27
10: ; preds = %0
%11 = load i32, i32* %2
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%13 = call i32 @read(i32 %11, i8* %12, i32 10)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %3
br label %19
19: ; preds = %16, %10
%20 = load i32, i32* %2
%21 = call i32 @close(i32 %20)
%22 = load i32, i32* %3
%23 = icmp sge i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = load i32, i32* %3
store i32 %25, i32* %1
br label %27
26: ; preds = %19
store i32 -1, i32* %1
br label %27
27: ; preds = %26, %24, %9
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str = [29 x i8] c"/proc/sys/net/core/somaxconn\00"
@O_RDONLY = global i32 0
define i32 @sapi_get_max_conn() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %0
%7 = call i32 @read(i32 %4, i8* %2, i32 10)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = call i32 @atoi(i8* %2)
br label %11
11: ; preds = %9, %6
%12 = phi i32 [ %10, %9 ], [ %7, %6 ]
%13 = tail call i32 @close(i32 %4)
%14 = icmp sgt i32 %12, -1
%15 = select i1 %14, i32 %12, i32 -1
br label %16
16: ; preds = %11, %0
%17 = phi i32 [ -1, %0 ], [ %15, %11 ]
ret i32 %17
}