#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("[miku:client do get]\n");
    if ((buf[4] == '/') && (buf[5] == ' '))
      strcat(path, "/index.html");
    else {
      strtok(&buf[4], " ");
      strcat(path, &buf[4]);
    }
    return 0;
  } else if (strstr(buf, "POST") == buf) {
    printf("[miku:client do post]\n");
    if ((buf[5] == '/') && (buf[6] == ' '))
      strcat(path, "/index.html");
    else {
      strtok(&buf[5], " ");
      strcat(path, &buf[5]);
    }
    return 0;
  } else {
    ;
    printf("wrong request\n");
    ;
    return -1;
  }
}


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    12d4 <get_path+0x184>
lea    -0x410(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1070 <strstr@plt>
lea    -0x410(%rbp),%rcx
cmp    %rcx,%rax
jne    1226 <get_path+0xd6>
lea    0xe4f(%rip),%rdi
call   1040 <printf@plt>
movsbl -0x40c(%rbp),%eax
cmp    $0x2f,%eax
jne    11ef <get_path+0x9f>
movsbl -0x40b(%rbp),%eax
cmp    $0x20,%eax
jne    11ef <get_path+0x9f>
mov    -0x10(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   1060 <strcat@plt>
jmp    121a <get_path+0xca>
lea    -0x410(%rbp),%rdi
add    $0x4,%rdi
lea    0xe25(%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)
jmp    12d4 <get_path+0x184>
lea    -0x410(%rbp),%rdi
lea    0xdf4(%rip),%rsi
call   1070 <strstr@plt>
lea    -0x410(%rbp),%rcx
cmp    %rcx,%rax
jne    12c1 <get_path+0x171>
lea    0xddd(%rip),%rdi
call   1040 <printf@plt>
movsbl -0x40b(%rbp),%eax
cmp    $0x2f,%eax
jne    128a <get_path+0x13a>
movsbl -0x40a(%rbp),%eax
cmp    $0x20,%eax
jne    128a <get_path+0x13a>
mov    -0x10(%rbp),%rdi
lea    0xd9a(%rip),%rsi
call   1060 <strcat@plt>
jmp    12b5 <get_path+0x165>
lea    -0x410(%rbp),%rdi
add    $0x5,%rdi
lea    0xd8a(%rip),%rsi
call   1050 <strtok@plt>
mov    -0x10(%rbp),%rdi
lea    -0x410(%rbp),%rsi
add    $0x5,%rsi
call   1060 <strcat@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d4 <get_path+0x184>
lea    0xd7c(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-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     11fb <get_path+0xbb>
mov    $0x4547,%eax
xor    (%rsp),%eax
movzbl 0x2(%rsp),%ecx
xor    $0x54,%ecx
or     %ax,%cx
je     11a6 <get_path+0x66>
cmpl   $0x54534f50,(%rsp)
jne    11cc <get_path+0x8c>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
cmpb   $0x2f,0x5(%rsp)
jne    119f <get_path+0x5f>
cmpb   $0x20,0x6(%rsp)
je     11c0 <get_path+0x80>
lea    0x5(%rsp),%rbp
jmp    11df <get_path+0x9f>
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
cmpb   $0x2f,0x4(%rsp)
jne    11da <get_path+0x9a>
cmpb   $0x20,0x5(%rsp)
jne    11da <get_path+0x9a>
lea    0xe3d(%rip),%rsi
mov    %rbx,%rdi
jmp    11f4 <get_path+0xb4>
lea    0xe3f(%rip),%rdi
call   1030 <puts@plt>
jmp    11fb <get_path+0xbb>
lea    0x4(%rsp),%rbp
lea    0xe2a(%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 = [22 x i8] c"[miku:client do get]\0A\00"
@.str.2 = [12 x i8] c"/index.html\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [5 x i8] c"POST\00"
@.str.5 = [23 x i8] c"[miku:client do post]\0A\00"
@.str.6 = [15 x i8] c"wrong request\0A\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 %66
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 eq i8* %14, %15
br i1 %16, label %17, label %38
17: ; preds = %12
%18 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 4
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 47
br i1 %22, label %23, label %31
23: ; preds = %17
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 5
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 32
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = load i8*, i8** %5
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %37
31: ; preds = %23, %17
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 4
%33 = call i32 @strtok(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%34 = load i8*, i8** %5
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 4
%36 = call i32 @strcat(i8* %34, i8* %35)
br label %37
37: ; preds = %31, %28
store i32 0, i32* %3
br label %66
38: ; preds = %12
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%40 = call i8* @strstr(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%42 = icmp eq i8* %40, %41
br i1 %42, label %43, label %64
43: ; preds = %38
%44 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 5
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 47
br i1 %48, label %49, label %57
49: ; preds = %43
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 6
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 32
br i1 %53, label %54, label %57
54: ; preds = %49
%55 = load i8*, i8** %5
%56 = call i32 @strcat(i8* %55, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %63
57: ; preds = %49, %43
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 5
%59 = call i32 @strtok(i8* %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%60 = load i8*, i8** %5
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 5
%62 = call i32 @strcat(i8* %60, i8* %61)
br label %63
63: ; preds = %57, %54
store i32 0, i32* %3
br label %66
64: ; preds = %38
%65 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %3
br label %66
66: ; preds = %64, %63, %37, %11
%67 = load i32, i32* %3
ret i32 %67
}

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"
@str.7 = [22 x i8] c"[miku:client do post]\00"
@str.8 = [21 x i8] c"[miku:client do get]\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 %44, 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 %10, label %24
10: ; preds = %7
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.8, i64 0, i64 0))
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 4
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 47
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 5
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 32
%18 = select i1 %14, i1 %17, i1 false
br i1 %18, label %19, label %21
19: ; preds = %10
%20 = call i32 @strcat(i8* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %44
21: ; preds = %10
%22 = call i32 @strtok(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 @strcat(i8* %1, i8* %12)
br label %44
24: ; preds = %7
%25 = bitcast [1024 x i8]* %3 to i32*
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 1414745936
br i1 %27, label %28, label %42
28: ; preds = %24
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.7, i64 0, i64 0))
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 5
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 47
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 6
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 32
%36 = select i1 %32, i1 %35, i1 false
br i1 %36, label %37, label %39
37: ; preds = %28
%38 = call i32 @strcat(i8* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %44
39: ; preds = %28
%40 = call i32 @strtok(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%41 = call i32 @strcat(i8* %1, i8* %30)
br label %44
42: ; preds = %24
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %44
44: ; preds = %37, %39, %19, %21, %2, %42
%45 = phi i32 [ -1, %42 ], [ -1, %2 ], [ 0, %21 ], [ 0, %19 ], [ 0, %39 ], [ 0, %37 ]
ret i32 %45
}