#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*/ LOG_INFO;
int /*<<< orphan*/ aquacc_fd_list_delete_by_fd(int);
int /*<<< orphan*/ closeSocket(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ freeSocket(int);
scalar_t__ readSocket(int);
int /*<<< orphan*/ set_write_event(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int);
bool socketchild_read_event_cb(int fd, void *data) {
  int fd_serial = (int)data;
  syslog(LOG_INFO, "socketchild_read_event_cb OK fd %d", fd);
  if (0 >= readSocket(fd)) {
    fprintf(stderr, "Error: reading from socket.\nClosing socket %d.\n", fd);
    freeSocket(fd);
    aquacc_fd_list_delete_by_fd(fd);
    closeSocket(fd);
    return true;
  }
  syslog(LOG_INFO, "set write event fd_serial %d", fd_serial);
  set_write_event(fd_serial);
  return true;
}


x86 assembly (clang, -O0):
<socketchild_read_event_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,-0x14(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe67(%rip),%rsi
call   1070 <syslog@plt>
mov    -0x8(%rbp),%edi
call   1030 <readSocket@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jl     11f0 <socketchild_read_event_cb+0x80>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe5c(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%edi
call   1090 <freeSocket@plt>
mov    -0x8(%rbp),%edi
call   1050 <aquacc_fd_list_delete_by_fd@plt>
mov    -0x8(%rbp),%edi
call   1080 <closeSocket@plt>
movl   $0x1,-0x4(%rbp)
jmp    1217 <socketchild_read_event_cb+0xa7>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe50(%rip),%rsi
call   1070 <syslog@plt>
mov    -0x14(%rbp),%edi
call   1040 <set_write_event@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socketchild_read_event_cb>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x2e57(%rip),%r15
mov    (%r15),%edi
lea    0xe75(%rip),%rsi
mov    %ebx,%edx
call   1070 <syslog@plt>
mov    %ebx,%edi
call   1030 <readSocket@plt>
test   %rax,%rax
jle    11ba <socketchild_read_event_cb+0x4a>
mov    (%r15),%edi
lea    0xeab(%rip),%rsi
mov    %r14d,%edx
call   1070 <syslog@plt>
mov    %r14d,%edi
call   1040 <set_write_event@plt>
jmp    11e6 <socketchild_read_event_cb+0x76>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
mov    %ebx,%edx
call   1060 <fprintf@plt>
mov    %ebx,%edi
call   1090 <freeSocket@plt>
mov    %ebx,%edi
call   1050 <aquacc_fd_list_delete_by_fd@plt>
mov    %ebx,%edi
call   1080 <closeSocket@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@LOG_INFO = global i32 0
@.str = [35 x i8] c"socketchild_read_event_cb OK fd %d\00"
@stderr = global i32 0
@.str.1 = [48 x i8] c"Error: reading from socket.\0AClosing socket %d.\0A\00"
@.str.2 = [29 x i8] c"set write event fd_serial %d\00"
define i32 @socketchild_read_event_cb(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = ptrtoint i8* %7 to i32
store i32 %8, i32* %6
%9 = load i32, i32* @LOG_INFO
%10 = load i32, i32* %4
%11 = call i32 @syslog(i32 %9, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %4
%13 = call i64 @readSocket(i32 %12)
%14 = icmp sge i64 0, %13
br i1 %14, label %15, label %25
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i32, i32* %4
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %4
%20 = call i32 @freeSocket(i32 %19)
%21 = load i32, i32* %4
%22 = call i32 @aquacc_fd_list_delete_by_fd(i32 %21)
%23 = load i32, i32* %4
%24 = call i32 @closeSocket(i32 %23)
store i32 1, i32* %3
br label %31
25: ; preds = %2
%26 = load i32, i32* @LOG_INFO
%27 = load i32, i32* %6
%28 = call i32 @syslog(i32 %26, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %6
%30 = call i32 @set_write_event(i32 %29)
store i32 1, i32* %3
br label %31
31: ; preds = %25, %15
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@LOG_INFO = global i32 0
@.str = [35 x i8] c"socketchild_read_event_cb OK fd %d\00"
@stderr = global i32 0
@.str.1 = [48 x i8] c"Error: reading from socket.\0AClosing socket %d.\0A\00"
@.str.2 = [29 x i8] c"set write event fd_serial %d\00"
define i32 @socketchild_read_event_cb(i32 %0, i8* %1) {
%3 = ptrtoint i8* %1 to i64
%4 = trunc i64 %3 to i32
%5 = load i32, i32* @LOG_INFO
%6 = tail call i32 @syslog(i32 %5, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %0)
%7 = tail call i64 @readSocket(i32 %0)
%8 = icmp slt i64 %7, 1
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%12 = tail call i32 @freeSocket(i32 %0)
%13 = tail call i32 @aquacc_fd_list_delete_by_fd(i32 %0)
%14 = tail call i32 @closeSocket(i32 %0)
br label %19
15: ; preds = %2
%16 = load i32, i32* @LOG_INFO
%17 = tail call i32 @syslog(i32 %16, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %4)
%18 = tail call i32 @set_write_event(i32 %4)
br label %19
19: ; preds = %15, %9
ret i32 1
}