#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(int client_sock) {
  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>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1040 <ioctl@plt>
cmpl   $0x0,-0x8(%rbp)
jle    1183 <handle_client+0x53>
mov    -0x4(%rbp),%edi
call   1050 <proc_request@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x2,-0xc(%rbp)
jne    1174 <handle_client+0x44>
jmp    1188 <handle_client+0x58>
mov    -0xc(%rbp),%esi
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
jmp    113b <handle_client+0xb>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_client>:
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+0x20>
mov    %ebx,%edi
call   1050 <proc_request@plt>
cmp    $0x2,%eax
je     117d <handle_client+0x4d>
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
jmp    1150 <handle_client+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(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
br label %5
5: ; preds = %1, %20
%6 = load i32, i32* %2
%7 = load i32, i32* @FIONREAD
%8 = call i32 @ioctl(i32 %6, i32 %7, i32* %3)
%9 = load i32, i32* %3
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %5
%12 = load i32, i32* %2
%13 = call i32 @proc_request(i32 %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 2
br i1 %15, label %16, label %17
16: ; preds = %11
br label %21
17: ; preds = %11
%18 = load i32, i32* %4
%19 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %17, %5
br label %5
21: ; preds = %16
ret void
}

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