#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*/ bzero(char *, int);
int /*<<< orphan*/ error(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int write(int, char *, int);
void handleHTTPRequest(int client_socket) {
  char buffer[1024];
  bzero(buffer, 256);
  int n;
  n = read(client_socket, buffer, 1024 - 1);
  if (n < 0) {
    error("can't read from socket", 6);
  }
  printf("%s\n", buffer);
  n = write(client_socket, "Gotcha!", 7);
  if (n < 0) {
    error("can't write to socket", 7);
  }
}


x86 assembly (clang, -O0):
<handleHTTPRequest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
mov    $0x100,%esi
call   1070 <bzero@plt>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x3ff,%edx
call   1050 <read@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jge    11a7 <handleHTTPRequest+0x57>
lea    0xe63(%rip),%rdi
mov    $0x6,%esi
call   1060 <error@plt>
lea    -0x410(%rbp),%rsi
lea    0xe62(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
lea    0xe57(%rip),%rsi
mov    $0x7,%edx
call   1030 <write@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jge    11f2 <handleHTTPRequest+0xa2>
lea    0xe3b(%rip),%rdi
mov    $0x7,%esi
call   1060 <error@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handleHTTPRequest>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x100,%esi
call   1070 <bzero@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x3ff,%edx
call   1050 <read@plt>
test   %eax,%eax
jns    1190 <handleHTTPRequest+0x40>
lea    0xe7a(%rip),%rdi
mov    $0x6,%esi
call   1060 <error@plt>
lea    0xe80(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
lea    0xe75(%rip),%rsi
mov    %ebx,%edi
mov    $0x7,%edx
call   1030 <write@plt>
test   %eax,%eax
jns    11c7 <handleHTTPRequest+0x77>
lea    0xe66(%rip),%rdi
mov    $0x7,%esi
call   1060 <error@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [23 x i8] c"can't read from socket\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [8 x i8] c"Gotcha!\00"
@.str.3 = [22 x i8] c"can't write to socket\00"
define void @handleHTTPRequest(i32 %0) {
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca i32
store i32 %0, i32* %2
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = call i32 @bzero(i8* %5, i32 256)
%7 = load i32, i32* %2
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%9 = call i32 @read(i32 %7, i8* %8, i32 1023)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 6)
br label %14
14: ; preds = %12, %1
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load i32, i32* %2
%18 = call i32 @write(i32 %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7)
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 7)
br label %23
23: ; preds = %21, %14
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"can't read from socket\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [8 x i8] c"Gotcha!\00"
@.str.3 = [22 x i8] c"can't write to socket\00"
define void @handleHTTPRequest(i32 %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @bzero(i8* %3, i32 256)
%5 = call i32 @read(i32 %0, i8* %3, i32 1023)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 6)
br label %9
9: ; preds = %7, %1
%10 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%11 = call i32 @write(i32 %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 7)
br label %15
15: ; preds = %13, %9
ret void
}