#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_succes_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_socket) {
  char *request_line;
  request_line = read_line(*connection_socket);
  if (strncmp(request_line, "GET", 3)) {
    build_error_response(*connection_socket, 501);
  } else {
    while (strcmp(read_line(*connection_socket), ""))
      ;
    build_succes_response(*connection_socket);
  }
  if (close(*connection_socket) == -1) {
    perror("Unable to close connection");
  }
  return 0;
}


x86 assembly (clang, -O0):
<process_http_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1070 <read_line@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe6a(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11bf <process_http_request+0x4f>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    $0x1f5,%esi
call   1080 <build_error_response@plt>
jmp    11f8 <process_http_request+0x88>
jmp    11c4 <process_http_request+0x54>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1070 <read_line@plt>
mov    %rax,%rdi
lea    0xe2a(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11ed <process_http_request+0x7d>
jmp    11c4 <process_http_request+0x54>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1060 <build_succes_response@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    1218 <process_http_request+0xa8>
lea    0xdf1(%rip),%rdi
call   1090 <perror@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_http_request>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%edi
call   1070 <read_line@plt>
lea    0xe7b(%rip),%rsi
mov    %rax,%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11a5 <process_http_request+0x35>
mov    (%rbx),%edi
mov    $0x1f5,%esi
call   1080 <build_error_response@plt>
jmp    11ce <process_http_request+0x5e>
lea    0xe57(%rip),%r14
nopl   0x0(%rax)
mov    (%rbx),%edi
call   1070 <read_line@plt>
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11b0 <process_http_request+0x40>
mov    (%rbx),%edi
call   1060 <build_succes_response@plt>
mov    (%rbx),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
je     11e4 <process_http_request+0x74>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe19(%rip),%rdi
call   1090 <perror@plt>
jmp    11da <process_http_request+0x6a>

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 i8* @process_http_request(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
store i32* %0, i32** %2
%4 = load i32*, i32** %2
%5 = load i32, i32* %4
%6 = call i8* @read_line(i32 %5)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = call i64 @strncmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i32*, i32** %2
%12 = load i32, i32* %11
%13 = call i32 @build_error_response(i32 %12, i32 501)
br label %26
14: ; preds = %1
br label %15
15: ; preds = %21, %14
%16 = load i32*, i32** %2
%17 = load i32, i32* %16
%18 = call i8* @read_line(i32 %17)
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %15
br label %15
22: ; preds = %15
%23 = load i32*, i32** %2
%24 = load i32, i32* %23
%25 = call i32 @build_succes_response(i32 %24)
br label %26
26: ; preds = %22, %10
%27 = load i32*, i32** %2
%28 = load i32, i32* %27
%29 = call i32 @close(i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %26
ret i8* null
}

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 noalias i8* @process_http_request(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = tail call i8* @read_line(i32 %2)
%4 = tail call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = load i32, i32* %0
%8 = tail call i32 @build_error_response(i32 %7, i32 501)
br label %17
9: ; preds = %1, %9
%10 = load i32, i32* %0
%11 = tail call i8* @read_line(i32 %10)
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %9
14: ; preds = %9
%15 = load i32, i32* %0
%16 = tail call i32 @build_succes_response(i32 %15)
br label %17
17: ; preds = %14, %6
%18 = load i32, i32* %0
%19 = tail call i32 @close(i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %17
ret i8* null
}