#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*/ close(int);
char *create_error_response(int, char *);
int /*<<< orphan*/ error(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
char *get_request(int);
int /*<<< orphan*/ handle_request(char *, char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void handle(int client) {
  char *response;
  char *request = get_request(client);
  if (!handle_request(request, response)) {
    response = create_error_response(404, "Not found");
  }
  if (!write(client, response, strlen(response))) {
    error("error writing to socket", 0);
  }
  printf("fd: %d\n", client);
  fflush(stdout);
  close(client);
}


x86 assembly (clang, -O0):
<handle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <get_request@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <handle_request@plt>
cmp    $0x0,%eax
jne    11d2 <handle+0x42>
mov    $0x194,%edi
lea    0xe37(%rip),%rsi
call   1030 <create_error_response@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
cmp    $0x0,%eax
jne    120e <handle+0x7e>
lea    0xe03(%rip),%rdi
xor    %esi,%esi
call   10b0 <error@plt>
mov    -0x4(%rbp),%esi
lea    0xe0a(%rip),%rdi
call   1070 <printf@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
mov    -0x4(%rbp),%edi
call   1080 <close@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
call   1040 <get_request@plt>
mov    %rax,%rdi
call   1090 <handle_request@plt>
lea    0xe57(%rip),%rsi
mov    $0x194,%edi
call   1030 <create_error_response@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
test   %eax,%eax
jne    11dc <handle+0x4c>
lea    0xe35(%rip),%rdi
xor    %esi,%esi
call   10b0 <error@plt>
lea    0xe3f(%rip),%rdi
mov    %ebp,%esi
call   1070 <printf@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1080 <close@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"Not found\00"
@.str.1 = [24 x i8] c"error writing to socket\00"
@.str.2 = [8 x i8] c"fd: %d\0A\00"
@stdout = global i32 0
define void @handle(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i8* @get_request(i32 %5)
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = load i8*, i8** %3
%9 = call i32 @handle_request(i8* %7, i8* %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %1
%12 = call i8* @create_error_response(i32 404, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %3
br label %13
13: ; preds = %11, %1
%14 = load i32, i32* %2
%15 = load i8*, i8** %3
%16 = load i8*, i8** %3
%17 = call i32 @strlen(i8* %16)
%18 = call i32 @write(i32 %14, i8* %15, i32 %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %13
%21 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 0)
br label %22
22: ; preds = %20, %13
%23 = load i32, i32* %2
%24 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = load i32, i32* @stdout
%26 = call i32 @fflush(i32 %25)
%27 = load i32, i32* %2
%28 = call i32 @close(i32 %27)
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"Not found\00"
@.str.1 = [24 x i8] c"error writing to socket\00"
@.str.2 = [8 x i8] c"fd: %d\0A\00"
@stdout = global i32 0
define void @handle(i32 %0) {
%2 = tail call i8* @get_request(i32 %0)
%3 = tail call i32 @handle_request(i8* %2, i8* undef)
%4 = icmp eq i32 %3, 0
tail call void @llvm.assume(i1 %4)
%5 = tail call i8* @create_error_response(i32 404, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @strlen(i8* %5)
%7 = tail call i32 @write(i32 %0, i8* %5, i32 %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = tail call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 0)
br label %11
11: ; preds = %9, %1
%12 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%13 = load i32, i32* @stdout
%14 = tail call i32 @fflush(i32 %13)
%15 = tail call i32 @close(i32 %0)
ret void
}