#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*/ error(int);
scalar_t__ parse_request_target(char *, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strcmp(char *, char *);
char *strdup(char const *);
int /*<<< orphan*/ *strstr(char *, char *);
char *strtok(char *, char *);
bool parse(const char *line, char *abs_path, char *query) {
  bool result = false;
  char *request = strdup(line);
  if (strstr(request, "  ") == NULL) {
    char *method = strtok(request, " ");
    char *request_target = strtok(NULL, " ");
    char *version = strtok(NULL, "\r\n");
    printf("method:%s\n", method);
    printf("request_target:%s\n", request_target);
    printf("version:%s\n", version);
    if (strcmp(method, "GET") == 0) {
      if (parse_request_target(request_target, abs_path, query)) {
        if (strcmp(version, "HTTP/1.1") == 0) {
          result = true;
        } else {
          error(505);
        }
      }
    } else {
      error(405);
    }
  } else {
    error(400);
  }
  return result;
}


x86 assembly (clang, -O0):
<parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
jne    129c <parse+0x12c>
mov    -0x28(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe30(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe1e(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xe0d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x38(%rbp),%rsi
lea    0xe08(%rip),%rdi
call   1030 <printf@plt>
mov    -0x40(%rbp),%rsi
lea    0xe0b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%rdi
lea    0xe07(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    128d <parse+0x11d>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1070 <parse_request_target@plt>
cmp    $0x0,%rax
je     1288 <parse+0x118>
mov    -0x40(%rbp),%rdi
lea    0xdd6(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1279 <parse+0x109>
movl   $0x1,-0x1c(%rbp)
jmp    1283 <parse+0x113>
mov    $0x1f9,%edi
call   1050 <error@plt>
jmp    1288 <parse+0x118>
jmp    1297 <parse+0x127>
mov    $0x195,%edi
call   1050 <error@plt>
jmp    12a6 <parse+0x136>
mov    $0x190,%edi
call   1050 <error@plt>
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
call   1080 <strdup@plt>
mov    %rax,%rbx
lea    0xe70(%rip),%rsi
mov    %rax,%rdi
call   1090 <strstr@plt>
mov    $0x190,%edi
test   %rax,%rax
jne    121d <parse+0xad>
lea    0xe58(%rip),%r12
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <strtok@plt>
mov    %rax,%rbp
xor    %ebx,%ebx
xor    %edi,%edi
mov    %r12,%rsi
call   1060 <strtok@plt>
mov    %rax,%r13
lea    0xe36(%rip),%rsi
xor    %edi,%edi
call   1060 <strtok@plt>
mov    %rax,%r12
lea    0xe28(%rip),%rdi
mov    %rbp,%rsi
call   1030 <printf@plt>
lea    0xe24(%rip),%rdi
mov    %r13,%rsi
call   1030 <printf@plt>
lea    0xe28(%rip),%rdi
mov    %r12,%rsi
call   1030 <printf@plt>
lea    0xe25(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcmp@plt>
mov    $0x195,%edi
test   %rax,%rax
je     1235 <parse+0xc5>
call   1050 <error@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1070 <parse_request_target@plt>
test   %rax,%rax
je     1224 <parse+0xb4>
lea    0xde5(%rip),%rsi
mov    %r12,%rdi
call   1040 <strcmp@plt>
mov    $0x1f9,%edi
test   %rax,%rax
jne    121d <parse+0xad>
mov    $0x1,%ebx
jmp    1224 <parse+0xb4>

LLVM IR (-O0):
@.str = [3 x i8] c" \00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [3 x i8] c"\0D\0A\00"
@.str.3 = [11 x i8] c"method:%s\0A\00"
@.str.4 = [19 x i8] c"request_target:%s\0A\00"
@.str.5 = [12 x i8] c"version:%s\0A\00"
@.str.6 = [4 x i8] c"GET\00"
@.str.7 = [9 x i8] c"HTTP/1.1\00"
define i32 @parse(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 0, i32* %7
%12 = load i8*, i8** %4
%13 = call i8* @strdup(i8* %12)
store i8* %13, i8** %8
%14 = load i8*, i8** %8
%15 = call i32* @strstr(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %49
17: ; preds = %3
%18 = load i8*, i8** %8
%19 = call i8* @strtok(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %19, i8** %9
%20 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %20, i8** %10
%21 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i8* %21, i8** %11
%22 = load i8*, i8** %9
%23 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %22)
%24 = load i8*, i8** %10
%25 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %24)
%26 = load i8*, i8** %11
%27 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %26)
%28 = load i8*, i8** %9
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %46
31: ; preds = %17
%32 = load i8*, i8** %10
%33 = load i8*, i8** %5
%34 = load i8*, i8** %6
%35 = call i64 @parse_request_target(i8* %32, i8* %33, i8* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %45
37: ; preds = %31
%38 = load i8*, i8** %11
%39 = call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %37
store i32 1, i32* %7
br label %44
42: ; preds = %37
%43 = call i32 @error(i32 505)
br label %44
44: ; preds = %42, %41
br label %45
45: ; preds = %44, %31
br label %48
46: ; preds = %17
%47 = call i32 @error(i32 405)
br label %48
48: ; preds = %46, %45
br label %51
49: ; preds = %3
%50 = call i32 @error(i32 400)
br label %51
51: ; preds = %49, %48
%52 = load i32, i32* %7
ret i32 %52
}

LLVM IR (-O2):
@.str = [3 x i8] c" \00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [3 x i8] c"\0D\0A\00"
@.str.3 = [11 x i8] c"method:%s\0A\00"
@.str.4 = [19 x i8] c"request_target:%s\0A\00"
@.str.5 = [12 x i8] c"version:%s\0A\00"
@.str.6 = [4 x i8] c"GET\00"
@.str.7 = [9 x i8] c"HTTP/1.1\00"
define i32 @parse(i8* nocapture %0, i8* %1, i8* %2) {
%4 = tail call i8* @strdup(i8* %0)
%5 = tail call i32* @strstr(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %22
7: ; preds = %3
%8 = tail call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %9)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %10)
%14 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %7
%17 = tail call i64 @parse_request_target(i8* %9, i8* %1, i8* %2)
%18 = icmp eq i64 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %16
%20 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %3, %7, %19
%23 = phi i32 [ 505, %19 ], [ 405, %7 ], [ 400, %3 ]
%24 = tail call i32 @error(i32 %23)
br label %25
25: ; preds = %22, %16, %19
%26 = phi i32 [ 0, %16 ], [ 1, %19 ], [ 0, %22 ]
ret i32 %26
}