#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 my_read(int, char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
char *strstr(char *, char *);
int /*<<< orphan*/ strtok(char *, char *);
int get_path(int cfd, char *path) {
  char buf[1024];
  if (my_read(cfd, buf, 1024) == -1)
    return -1;
  if (strstr(buf, "GET") != buf) {
    ;
    printf("wrong request\n");
    ;
    return -1;
  }
  if ((buf[4] == '/') && (buf[5] == ' '))
    strcat(path, "/index.html");
  else {
    strtok(&buf[4], " ");
    strcat(path, &buf[4]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1030 <my_read@plt>
cmp    $0xffffffff,%eax
jne    118b <get_path+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    122d <get_path+0xdd>
lea    -0x410(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1070 <strstr@plt>
lea    -0x410(%rbp),%rcx
cmp    %rcx,%rax
je     11c6 <get_path+0x76>
lea    0xe4f(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122d <get_path+0xdd>
movsbl -0x40c(%rbp),%eax
cmp    $0x2f,%eax
jne    11fb <get_path+0xab>
movsbl -0x40b(%rbp),%eax
cmp    $0x20,%eax
jne    11fb <get_path+0xab>
mov    -0x10(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   1060 <strcat@plt>
jmp    1226 <get_path+0xd6>
lea    -0x410(%rbp),%rdi
add    $0x4,%rdi
lea    0xe12(%rip),%rsi
call   1050 <strtok@plt>
mov    -0x10(%rbp),%rdi
lea    -0x410(%rbp),%rsi
add    $0x4,%rsi
call   1060 <strcat@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_path>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbx
mov    %rsp,%rsi
mov    $0x400,%edx
call   1040 <my_read@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     11c1 <get_path+0x81>
mov    $0x4547,%eax
xor    (%rsp),%eax
movzbl 0x2(%rsp),%ecx
xor    $0x54,%ecx
or     %ax,%cx
je     1186 <get_path+0x46>
lea    0xe93(%rip),%rdi
call   1030 <puts@plt>
jmp    11c1 <get_path+0x81>
cmpb   $0x2f,0x4(%rsp)
jne    11a0 <get_path+0x60>
cmpb   $0x20,0x5(%rsp)
jne    11a0 <get_path+0x60>
lea    0xe69(%rip),%rsi
mov    %rbx,%rdi
jmp    11ba <get_path+0x7a>
lea    0x4(%rsp),%rbp
lea    0xe64(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strtok@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <strcat@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"GET\00"
@.str.1 = [15 x i8] c"wrong request\0A\00"
@.str.2 = [12 x i8] c"/index.html\00"
@.str.3 = [2 x i8] c" \00"
define i32 @get_path(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [1024 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = load i32, i32* %4
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%9 = call i32 @my_read(i32 %7, i8* %8, i32 1024)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %39
12: ; preds = %2
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%14 = call i8* @strstr(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%16 = icmp ne i8* %14, %15
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %39
19: ; preds = %12
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 4
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 47
br i1 %23, label %24, label %32
24: ; preds = %19
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 5
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 32
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i8*, i8** %5
%31 = call i32 @strcat(i8* %30, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %38
32: ; preds = %24, %19
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 4
%34 = call i32 @strtok(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%35 = load i8*, i8** %5
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 4
%37 = call i32 @strcat(i8* %35, i8* %36)
br label %38
38: ; preds = %32, %29
store i32 0, i32* %3
br label %39
39: ; preds = %38, %17, %11
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [4 x i8] c"GET\00"
@.str.2 = [12 x i8] c"/index.html\00"
@.str.3 = [2 x i8] c" \00"
@str = [14 x i8] c"wrong request\00"
define i32 @get_path(i32 %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @my_read(i32 %0, i8* %4, i32 1024)
%6 = icmp eq i32 %5, -1
br i1 %6, label %25, label %7
7: ; preds = %2
%8 = call i32 @bcmp(i8* dereferenceable(3) %4, i8* dereferenceable(3) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 3)
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %25
12: ; preds = %7
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 4
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 47
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 5
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 32
%19 = select i1 %15, i1 %18, i1 false
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = call i32 @strcat(i8* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %25
22: ; preds = %12
%23 = call i32 @strtok(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32 @strcat(i8* %1, i8* %13)
br label %25
25: ; preds = %20, %22, %2, %10
%26 = phi i32 [ -1, %10 ], [ -1, %2 ], [ 0, %22 ], [ 0, %20 ]
ret i32 %26
}