#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*/ FIONREAD;
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ printf(char *, int);
int proc_request(int);
void handle_client_event(int client_sock, short event, void *arg) {
  int nread;
  int ret;
  while (1) {
    ioctl(client_sock, FIONREAD, &nread);
    if (nread > 0) {
      ret = proc_request(client_sock);
      if (ret == 2) {
        break;
      }
      printf("proc_requrest result %d\n", ret);
    }
  }
}


x86 assembly (clang, -O0):
<handle_client_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %edi,-0x4(%rbp)
mov    %ax,-0x6(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdx
call   1040 <ioctl@plt>
cmpl   $0x0,-0x14(%rbp)
jle    118e <handle_client_event+0x5e>
mov    -0x4(%rbp),%edi
call   1050 <proc_request@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x2,-0x18(%rbp)
jne    117f <handle_client_event+0x4f>
jmp    1193 <handle_client_event+0x63>
mov    -0x18(%rbp),%esi
lea    0xe77(%rip),%rdi
call   1030 <printf@plt>
jmp    1146 <handle_client_event+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_client_event>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2ea7(%rip),%r12
lea    0x4(%rsp),%r14
lea    0xeb3(%rip),%r15
nopl   (%rax)
mov    (%r12),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1040 <ioctl@plt>
cmpl   $0x0,0x4(%rsp)
jle    1150 <handle_client_event+0x20>
mov    %ebx,%edi
call   1050 <proc_request@plt>
cmp    $0x2,%eax
je     117d <handle_client_event+0x4d>
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
jmp    1150 <handle_client_event+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@FIONREAD = global i32 0
@.str = [25 x i8] c"proc_requrest result %d\0A\00"
define void @handle_client_event(i32 %0, i16 signext %1, i8* %2) {
%4 = alloca i32
%5 = alloca i16
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i16 %1, i16* %5
store i8* %2, i8** %6
br label %9
9: ; preds = %3, %24
%10 = load i32, i32* %4
%11 = load i32, i32* @FIONREAD
%12 = call i32 @ioctl(i32 %10, i32 %11, i32* %7)
%13 = load i32, i32* %7
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %9
%16 = load i32, i32* %4
%17 = call i32 @proc_request(i32 %16)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %21
20: ; preds = %15
br label %25
21: ; preds = %15
%22 = load i32, i32* %8
%23 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %21, %9
br label %9
25: ; preds = %20
ret void
}

LLVM IR (-O2):
@FIONREAD = global i32 0
@.str = [25 x i8] c"proc_requrest result %d\0A\00"
define void @handle_client_event(i32 %0, i16 signext %1, i8* nocapture readnone %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
br label %6
6: ; preds = %16, %3
%7 = load i32, i32* @FIONREAD
%8 = call i32 @ioctl(i32 %0, i32 %7, i32* %4)
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %6
%12 = call i32 @proc_request(i32 %0)
%13 = icmp eq i32 %12, 2
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %16
16: ; preds = %14, %6
br label %6
17: ; preds = %11
ret void
}