#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 */
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, char *);
scalar_t__ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int handle_request(char *buf, int nread, int clifd,
                   struct sockaddr_in *client_address) {
  if (buf[0] == 4) {
    return 1;
  }
  if (send(clifd, buf, nread, 0) < 0) {
    fprintf(stderr, "send_fd error");
    return 1;
  }
  printf("sent fd %d %s\n", clifd, inet_ntoa(client_address->sin_addr));
  return 0;
}


x86 assembly (clang, -O0):
<handle_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x4,%eax
jne    1172 <handle_request+0x32>
movl   $0x1,-0x4(%rbp)
jmp    11d8 <handle_request+0x98>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0x0,%rax
jge    11ae <handle_request+0x6e>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d8 <handle_request+0x98>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    -0x24(%rbp),%esi
mov    %rax,%rdx
lea    0xe42(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_request>:
push   %rbp
push   %r14
push   %rbx
mov    $0x1,%ebx
cmpb   $0x4,(%rdi)
je     1198 <handle_request+0x58>
mov    %rcx,%r14
mov    %edx,%ebp
mov    %esi,%edx
mov    %rdi,%rsi
mov    %ebp,%edi
xor    %ecx,%ecx
call   1040 <send@plt>
test   %rax,%rax
js     1183 <handle_request+0x43>
mov    (%r14),%edi
call   1030 <inet_ntoa@plt>
lea    0xe99(%rip),%rdi
mov    %ebp,%esi
mov    %rax,%rdx
call   1050 <printf@plt>
xor    %ebx,%ebx
jmp    1198 <handle_request+0x58>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
call   1060 <fprintf@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
@stderr = global i32 0
@.str = [14 x i8] c"send_fd error\00"
@.str.1 = [15 x i8] c"sent fd %d %s\0A\00"
define i32 @handle_request(i8* %0, i32 %1, i32 %2, %struct.sockaddr_in* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store %struct.sockaddr_in* %3, %struct.sockaddr_in** %9
%10 = load i8*, i8** %6
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 4
br i1 %14, label %15, label %16
15: ; preds = %4
store i32 1, i32* %5
br label %32
16: ; preds = %4
%17 = load i32, i32* %8
%18 = load i8*, i8** %6
%19 = load i32, i32* %7
%20 = call i64 @send(i32 %17, i8* %18, i32 %19, i32 0)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %5
br label %32
25: ; preds = %16
%26 = load i32, i32* %8
%27 = load %struct.sockaddr_in*, %struct.sockaddr_in** %9
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i8* @inet_ntoa(i32 %29)
%31 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %26, i8* %30)
store i32 0, i32* %5
br label %32
32: ; preds = %25, %22, %15
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
@stderr = global i32 0
@.str = [14 x i8] c"send_fd error\00"
@.str.1 = [15 x i8] c"sent fd %d %s\0A\00"
define i32 @handle_request(i8* %0, i32 %1, i32 %2, %struct.sockaddr_in* nocapture %3) {
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 4
br i1 %6, label %18, label %7
7: ; preds = %4
%8 = tail call i64 @send(i32 %2, i8* %0, i32 %1, i32 0)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %18
13: ; preds = %7
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%15 = load i32, i32* %14
%16 = tail call i8* @inet_ntoa(i32 %15)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %2, i8* %16)
br label %18
18: ; preds = %4, %13, %10
%19 = phi i32 [ 1, %10 ], [ 0, %13 ], [ 1, %4 ]
ret i32 %19
}