#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*/ build_error_response(int, int);
int /*<<< orphan*/ build_success_response(int);
int close(int);
int /*<<< orphan*/ perror(char *);
char *read_line(int);
scalar_t__ strcmp(char *, char *);
scalar_t__ strncmp(char *, char *, int);
void process_http_request(int connection) {
  char *request_line;
  request_line = read_line(connection);
  if (strncmp(request_line, "GET", 3)) {
    build_error_response(connection, 501);
  } else {
    while (strcmp(read_line(connection), ""))
      ;
    build_success_response(connection);
    if (close(connection) == -1) {
      perror("Unable to close connection");
    }
  }
}


x86 assembly (clang, -O0):
<process_http_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1070 <read_line@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe6e(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11b8 <process_http_request+0x48>
mov    -0x4(%rbp),%edi
mov    $0x1f5,%esi
call   1080 <build_error_response@plt>
jmp    120d <process_http_request+0x9d>
jmp    11bd <process_http_request+0x4d>
mov    -0x4(%rbp),%edi
call   1070 <read_line@plt>
mov    %rax,%rdi
lea    0xe34(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11e3 <process_http_request+0x73>
jmp    11bd <process_http_request+0x4d>
mov    -0x4(%rbp),%edi
call   1040 <build_success_response@plt>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    1208 <process_http_request+0x98>
lea    0xe01(%rip),%rdi
call   1090 <perror@plt>
jmp    120d <process_http_request+0x9d>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_http_request>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
call   1070 <read_line@plt>
lea    0xe7e(%rip),%rsi
mov    %rax,%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11a7 <process_http_request+0x37>
mov    %ebx,%edi
mov    $0x1f5,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1080 <build_error_response@plt>
lea    0xe55(%rip),%r14
xchg   %ax,%ax
mov    %ebx,%edi
call   1070 <read_line@plt>
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11b0 <process_http_request+0x40>
mov    %ebx,%edi
call   1040 <build_success_response@plt>
mov    %ebx,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     11e2 <process_http_request+0x72>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe1b(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1090 <perror@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"GET\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [27 x i8] c"Unable to close connection\00"
define void @process_http_request(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i8* @read_line(i32 %4)
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* %2
%11 = call i32 @build_error_response(i32 %10, i32 501)
br label %28
12: ; preds = %1
br label %13
13: ; preds = %18, %12
%14 = load i32, i32* %2
%15 = call i8* @read_line(i32 %14)
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %13
br label %13
19: ; preds = %13
%20 = load i32, i32* %2
%21 = call i32 @build_success_response(i32 %20)
%22 = load i32, i32* %2
%23 = call i32 @close(i32 %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %19
br label %28
28: ; preds = %27, %9
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"GET\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [27 x i8] c"Unable to close connection\00"
define void @process_http_request(i32 %0) {
%2 = tail call i8* @read_line(i32 %0)
%3 = tail call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = tail call i32 @build_error_response(i32 %0, i32 501)
br label %17
7: ; preds = %1, %7
%8 = tail call i8* @read_line(i32 %0)
%9 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %7
11: ; preds = %7
%12 = tail call i32 @build_success_response(i32 %0)
%13 = tail call i32 @close(i32 %0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %11, %15, %5
ret void
}