#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 */
typedef int /*<<< orphan*/ path;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ recv_size(int, char *, int);
int recv_until(int, char *, int, char);
int /*<<< orphan*/ send_str(int, char *);
int /*<<< orphan*/ stderr;
int handle_get(int socket) {
  int err;
  int linesize = -1;
  char buf[1024];
  char path[1024];
  fprintf(stderr, "Received GET request.\n");
  if (recv_size(socket, buf, 1) < 0)
    return -1;
  if (recv_until(socket, path, sizeof(path), ' ') < 0)
    return -1;
  fprintf(stderr, "Path: %s\n", path);
  if (recv_size(socket, buf, 1) < 0)
    return -1;
  if (recv_until(socket, buf, sizeof(buf), '\r') < 0)
    return -1;
  fprintf(stderr, "HTTP version: %s\n", buf);
  if (recv_size(socket, buf, 2) < 0)
    return -1;
  while (linesize) {
    linesize = recv_until(socket, buf, sizeof(buf), '\r');
    fprintf(stderr, "h> %s\n", buf);
    if (recv_size(socket, buf, 2) < 0)
      return -1;
  }
  send_str(socket, "HTTP/1.1 200 OK\r\n");
  send_str(socket, "\r\n");
  send_str(socket, "IT WORKS!\n");
  send_str(socket, "HELLO WORLD FROM QUAFIOS HTTP SERVER!\n");
  send_str(socket, "\r\n");
  fprintf(stderr, "GET request has been processed successfully.\n");
  return 0;
}


x86 assembly (clang, -O0):
<handle_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
mov    %edi,-0x8(%rbp)
movl   $0xffffffff,-0x10(%rbp)
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
lea    0xe9b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x1,%edx
call   1030 <recv_size@plt>
cmp    $0x0,%rax
jge    1196 <handle_get+0x56>
movl   $0xffffffff,-0x4(%rbp)
jmp    1363 <handle_get+0x223>
mov    -0x8(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    $0x400,%edx
mov    $0x20,%ecx
call   1060 <recv_until@plt>
cmp    $0x0,%eax
jge    11c4 <handle_get+0x84>
movl   $0xffffffff,-0x4(%rbp)
jmp    1363 <handle_get+0x223>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    -0x810(%rbp),%rdx
lea    0xe3c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x1,%edx
call   1030 <recv_size@plt>
cmp    $0x0,%rax
jge    120c <handle_get+0xcc>
movl   $0xffffffff,-0x4(%rbp)
jmp    1363 <handle_get+0x223>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
mov    $0xd,%ecx
call   1060 <recv_until@plt>
cmp    $0x0,%eax
jge    123a <handle_get+0xfa>
movl   $0xffffffff,-0x4(%rbp)
jmp    1363 <handle_get+0x223>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xdd0(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x2,%edx
call   1030 <recv_size@plt>
cmp    $0x0,%rax
jge    1282 <handle_get+0x142>
movl   $0xffffffff,-0x4(%rbp)
jmp    1363 <handle_get+0x223>
jmp    1287 <handle_get+0x147>
cmpl   $0x0,-0x10(%rbp)
je     12fa <handle_get+0x1ba>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
mov    $0xd,%ecx
call   1060 <recv_until@plt>
mov    %eax,-0x10(%rbp)
mov    0x2d2c(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xd6f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x2,%edx
call   1030 <recv_size@plt>
cmp    $0x0,%rax
jge    12f5 <handle_get+0x1b5>
movl   $0xffffffff,-0x4(%rbp)
jmp    1363 <handle_get+0x223>
jmp    1287 <handle_get+0x147>
mov    -0x8(%rbp),%edi
lea    0xd36(%rip),%rsi
call   1050 <send_str@plt>
mov    -0x8(%rbp),%edi
lea    0xd36(%rip),%rsi
call   1050 <send_str@plt>
mov    -0x8(%rbp),%edi
lea    0xd2a(%rip),%rsi
call   1050 <send_str@plt>
mov    -0x8(%rbp),%edi
lea    0xd26(%rip),%rsi
call   1050 <send_str@plt>
mov    -0x8(%rbp),%edi
lea    0xd09(%rip),%rsi
call   1050 <send_str@plt>
mov    0x2c94(%rip),%rax
mov    (%rax),%edi
lea    0xd29(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_get>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x800,%rsp
mov    %edi,%r15d
mov    0x2e87(%rip),%r12
mov    (%r12),%edi
lea    0xe9c(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0x1,%edx
call   1030 <recv_size@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
js     12e6 <handle_get+0x1a6>
lea    0x400(%rsp),%rsi
mov    %r15d,%edi
mov    $0x400,%edx
mov    $0x20,%ecx
call   1060 <recv_until@plt>
test   %eax,%eax
js     12e6 <handle_get+0x1a6>
mov    (%r12),%edi
lea    0xe61(%rip),%rsi
lea    0x400(%rsp),%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0x1,%edx
call   1030 <recv_size@plt>
test   %rax,%rax
js     12e6 <handle_get+0x1a6>
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0x400,%edx
mov    $0xd,%ecx
call   1060 <recv_until@plt>
test   %eax,%eax
js     12e6 <handle_get+0x1a6>
mov    (%r12),%edi
lea    0xe1b(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1030 <recv_size@plt>
test   %rax,%rax
js     12e6 <handle_get+0x1a6>
mov    $0xffffffff,%ebx
mov    %rsp,%rbp
lea    0xdf8(%rip),%r14
nopl   0x0(%rax,%rax,1)
test   %ebx,%ebx
je     1288 <handle_get+0x148>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
mov    $0xd,%ecx
call   1060 <recv_until@plt>
mov    %eax,%ebx
mov    (%r12),%edi
mov    %r14,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x2,%edx
call   1030 <recv_size@plt>
test   %rax,%rax
jns    1240 <handle_get+0x100>
mov    $0xffffffff,%ebp
jmp    12e6 <handle_get+0x1a6>
lea    0xdab(%rip),%rsi
mov    %r15d,%edi
call   1050 <send_str@plt>
lea    0xdab(%rip),%rbx
mov    %r15d,%edi
mov    %rbx,%rsi
call   1050 <send_str@plt>
lea    0xd9c(%rip),%rsi
mov    %r15d,%edi
call   1050 <send_str@plt>
lea    0xd98(%rip),%rsi
mov    %r15d,%edi
call   1050 <send_str@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1050 <send_str@plt>
mov    (%r12),%edi
lea    0xda1(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %ebp,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"Received GET request.\0A\00"
@.str.1 = [10 x i8] c"Path: %s\0A\00"
@.str.2 = [18 x i8] c"HTTP version: %s\0A\00"
@.str.3 = [7 x i8] c"h> %s\0A\00"
@.str.4 = [18 x i8] c"HTTP/1.1 200 OK\0D\0A\00"
@.str.5 = [3 x i8] c"\0D\0A\00"
@.str.6 = [11 x i8] c"IT WORKS!\0A\00"
@.str.7 = [39 x i8] c"HELLO WORLD FROM QUAFIOS HTTP SERVER!\0A\00"
@.str.8 = [46 x i8] c"GET request has been processed successfully.\0A\00"
define i32 @handle_get(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
store i32 %0, i32* %3
store i32 -1, i32* %5
%8 = load i32, i32* @stderr
%9 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* %3
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%12 = call i64 @recv_size(i32 %10, i8* %11, i32 1)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %1
store i32 -1, i32* %2
br label %75
15: ; preds = %1
%16 = load i32, i32* %3
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%18 = call i32 @recv_until(i32 %16, i8* %17, i32 1024, i8 signext 32)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 -1, i32* %2
br label %75
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = load i32, i32* %3
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%27 = call i64 @recv_size(i32 %25, i8* %26, i32 1)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %21
store i32 -1, i32* %2
br label %75
30: ; preds = %21
%31 = load i32, i32* %3
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%33 = call i32 @recv_until(i32 %31, i8* %32, i32 1024, i8 signext 13)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %30
store i32 -1, i32* %2
br label %75
36: ; preds = %30
%37 = load i32, i32* @stderr
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %38)
%40 = load i32, i32* %3
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%42 = call i64 @recv_size(i32 %40, i8* %41, i32 2)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %36
store i32 -1, i32* %2
br label %75
45: ; preds = %36
br label %46
46: ; preds = %61, %45
%47 = load i32, i32* %5
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %62
49: ; preds = %46
%50 = load i32, i32* %3
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%52 = call i32 @recv_until(i32 %50, i8* %51, i32 1024, i8 signext 13)
store i32 %52, i32* %5
%53 = load i32, i32* @stderr
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %54)
%56 = load i32, i32* %3
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%58 = call i64 @recv_size(i32 %56, i8* %57, i32 2)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %49
store i32 -1, i32* %2
br label %75
61: ; preds = %49
br label %46
62: ; preds = %46
%63 = load i32, i32* %3
%64 = call i32 @send_str(i32 %63, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%65 = load i32, i32* %3
%66 = call i32 @send_str(i32 %65, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%67 = load i32, i32* %3
%68 = call i32 @send_str(i32 %67, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%69 = load i32, i32* %3
%70 = call i32 @send_str(i32 %69, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0))
%71 = load i32, i32* %3
%72 = call i32 @send_str(i32 %71, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%73 = load i32, i32* @stderr
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %2
br label %75
75: ; preds = %62, %60, %44, %35, %29, %20, %14
%76 = load i32, i32* %2
ret i32 %76
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"Received GET request.\0A\00"
@.str.1 = [10 x i8] c"Path: %s\0A\00"
@.str.2 = [18 x i8] c"HTTP version: %s\0A\00"
@.str.3 = [7 x i8] c"h> %s\0A\00"
@.str.4 = [18 x i8] c"HTTP/1.1 200 OK\0D\0A\00"
@.str.5 = [3 x i8] c"\0D\0A\00"
@.str.6 = [11 x i8] c"IT WORKS!\0A\00"
@.str.7 = [39 x i8] c"HELLO WORLD FROM QUAFIOS HTTP SERVER!\0A\00"
@.str.8 = [46 x i8] c"GET request has been processed successfully.\0A\00"
define i32 @handle_get(i32 %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%8 = call i64 @recv_size(i32 %0, i8* %4, i32 1)
%9 = icmp slt i64 %8, 0
br i1 %9, label %43, label %10
10: ; preds = %1
%11 = call i32 @recv_until(i32 %0, i8* %5, i32 1024, i8 signext 32)
%12 = icmp slt i32 %11, 0
br i1 %12, label %43, label %13
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%16 = call i64 @recv_size(i32 %0, i8* %4, i32 1)
%17 = icmp slt i64 %16, 0
br i1 %17, label %43, label %18
18: ; preds = %13
%19 = call i32 @recv_until(i32 %0, i8* %4, i32 1024, i8 signext 13)
%20 = icmp slt i32 %19, 0
br i1 %20, label %43, label %21
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%24 = call i64 @recv_size(i32 %0, i8* %4, i32 2)
%25 = icmp slt i64 %24, 0
br i1 %25, label %43, label %26
26: ; preds = %21, %29
%27 = phi i32 [ %30, %29 ], [ -1, %21 ]
%28 = icmp eq i32 %27, 0
br i1 %28, label %35, label %29
29: ; preds = %26
%30 = call i32 @recv_until(i32 %0, i8* %4, i32 1024, i8 signext 13)
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%33 = call i64 @recv_size(i32 %0, i8* %4, i32 2)
%34 = icmp slt i64 %33, 0
br i1 %34, label %43, label %26
35: ; preds = %26
%36 = call i32 @send_str(i32 %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%37 = call i32 @send_str(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%38 = call i32 @send_str(i32 %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%39 = call i32 @send_str(i32 %0, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0))
%40 = call i32 @send_str(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.8, i64 0, i64 0))
br label %43
43: ; preds = %29, %21, %18, %13, %10, %1, %35
%44 = phi i32 [ 0, %35 ], [ -1, %1 ], [ -1, %10 ], [ -1, %13 ], [ -1, %18 ], [ -1, %21 ], [ -1, %29 ]
ret i32 %44
}