#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*/ err(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memmove(char *, char *, int);
int /*<<< orphan*/ strlcpy(char *, char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *strndup(char *, int);
char *strtok_r(char *, char *, char **);
int checkGET(char *buff, char *fileName, char *firstLine) {
  char *backup, *word, *line, *lptr, *wptr;
  wptr = NULL;
  lptr = NULL;
  backup = strndup(buff, strlen(buff));
  if (backup == NULL)
    err(0, "strndup fail");
  line = strtok_r(backup, "\n", &lptr);
  strlcpy(firstLine, line);
  int i;
  word = strtok_r(line, " ", &wptr);
  if (word == NULL || strncmp(word, "GET", 3) != 0) {
    free(backup);
    return 0;
  }
  word = strtok_r(NULL, " ", &wptr);
  if (word == NULL) {
    free(backup);
    return 0;
  }
  strlcpy(fileName, word);
  if (fileName[0] != '/') {
    free(backup);
    return 0;
  }
  memmove(fileName, fileName + 1, strlen(fileName + 1));
  fileName[strlen(fileName) - 1] = '\0';
  word = strtok_r(NULL, " ", &wptr);
  if (word == NULL || strncmp(word, "HTTP/1.1", 8) != 0) {
    free(backup);
    return 0;
  }
  while (line != NULL) {
    if (strlen(line) == 1) {
      free(backup);
      return 1;
    }
    line = strtok_r(NULL, "\n", &lptr);
  }
  free(backup);
  return 0;
}


x86 assembly (clang, -O0):
<checkGET>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    %eax,%esi
call   1070 <strndup@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11dd <checkGET+0x5d>
xor    %edi,%edi
lea    0xe28(%rip),%rsi
call   1080 <err@plt>
mov    -0x28(%rbp),%rdi
lea    0xe25(%rip),%rsi
lea    -0x40(%rbp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1090 <strlcpy@plt>
mov    -0x38(%rbp),%rdi
lea    0xe02(%rip),%rsi
lea    -0x48(%rbp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1244 <checkGET+0xc4>
mov    -0x30(%rbp),%rdi
lea    0xde1(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     1259 <checkGET+0xd9>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    13cf <checkGET+0x24f>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdab(%rip),%rsi
lea    -0x48(%rbp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1291 <checkGET+0x111>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    13cf <checkGET+0x24f>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1090 <strlcpy@plt>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     12c3 <checkGET+0x143>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    13cf <checkGET+0x24f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1050 <strlen@plt>
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
call   10a0 <memmove@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x60(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
xor    %eax,%eax
mov    %eax,%edi
lea    0xcf0(%rip),%rsi
lea    -0x48(%rbp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1356 <checkGET+0x1d6>
mov    -0x30(%rbp),%rdi
lea    0xcd3(%rip),%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     136b <checkGET+0x1eb>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    13cf <checkGET+0x24f>
jmp    1370 <checkGET+0x1f0>
cmpq   $0x0,-0x38(%rbp)
je     13bf <checkGET+0x23f>
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x1,%eax
jne    13a2 <checkGET+0x222>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    13cf <checkGET+0x24f>
xor    %eax,%eax
mov    %eax,%edi
lea    0xc60(%rip),%rsi
lea    -0x40(%rbp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,-0x38(%rbp)
jmp    1370 <checkGET+0x1f0>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkGET>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%rbx
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <strndup@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11cc <checkGET+0x4c>
lea    0xe3b(%rip),%rsi
xor    %edi,%edi
call   1080 <err@plt>
lea    0xe3a(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %r14,%rdi
call   1060 <strtok_r@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %rax,%rsi
call   1090 <strlcpy@plt>
lea    0xe1a(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1060 <strtok_r@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     1221 <checkGET+0xa1>
lea    0xe02(%rip),%rsi
mov    %rax,%rdi
mov    $0x3,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     123a <checkGET+0xba>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xdce(%rip),%rsi
xor    %r12d,%r12d
mov    %rsp,%rdx
xor    %edi,%edi
call   1060 <strtok_r@plt>
test   %rax,%rax
je     1221 <checkGET+0xa1>
mov    %r15,%rdi
mov    %rax,%rsi
call   1090 <strlcpy@plt>
cmpb   $0x2f,(%r15)
jne    1221 <checkGET+0xa1>
lea    0x1(%r15),%r12
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   10a0 <memmove@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r15,1)
lea    0xd7b(%rip),%rsi
xor    %r12d,%r12d
mov    %rsp,%rdx
xor    %edi,%edi
call   1060 <strtok_r@plt>
test   %rax,%rax
je     1221 <checkGET+0xa1>
lea    0xd64(%rip),%rsi
mov    %rax,%rdi
mov    $0x8,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1221 <checkGET+0xa1>
test   %rbx,%rbx
je     1221 <checkGET+0xa1>
lea    0xd36(%rip),%r15
lea    0x8(%rsp),%r13
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x1,%eax
je     130a <checkGET+0x18a>
xor    %r12d,%r12d
xor    %edi,%edi
mov    %r15,%rsi
mov    %r13,%rdx
call   1060 <strtok_r@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    12e0 <checkGET+0x160>
jmp    1221 <checkGET+0xa1>
mov    $0x1,%r12d
jmp    1221 <checkGET+0xa1>

LLVM IR (-O0):
@.str = [13 x i8] c"strndup fail\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [4 x i8] c"GET\00"
@.str.4 = [9 x i8] c"HTTP/1.1\00"
define i32 @checkGET(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* null, i8** %12
store i8* null, i8** %11
%14 = load i8*, i8** %5
%15 = load i8*, i8** %5
%16 = call i32 @strlen(i8* %15)
%17 = call i8* @strndup(i8* %14, i32 %16)
store i8* %17, i8** %8
%18 = load i8*, i8** %8
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = call i32 @err(i32 0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %3
%23 = load i8*, i8** %8
%24 = call i8* @strtok_r(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %11)
store i8* %24, i8** %10
%25 = load i8*, i8** %7
%26 = load i8*, i8** %10
%27 = call i32 @strlcpy(i8* %25, i8* %26)
%28 = load i8*, i8** %10
%29 = call i8* @strtok_r(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %12)
store i8* %29, i8** %9
%30 = load i8*, i8** %9
%31 = icmp eq i8* %30, null
br i1 %31, label %36, label %32
32: ; preds = %22
%33 = load i8*, i8** %9
%34 = call i64 @strncmp(i8* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %32, %22
%37 = load i8*, i8** %8
%38 = call i32 @free(i8* %37)
store i32 0, i32* %4
br label %98
39: ; preds = %32
%40 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %12)
store i8* %40, i8** %9
%41 = load i8*, i8** %9
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = load i8*, i8** %8
%45 = call i32 @free(i8* %44)
store i32 0, i32* %4
br label %98
46: ; preds = %39
%47 = load i8*, i8** %6
%48 = load i8*, i8** %9
%49 = call i32 @strlcpy(i8* %47, i8* %48)
%50 = load i8*, i8** %6
%51 = getelementptr inbounds i8, i8* %50, i64 0
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp ne i32 %53, 47
br i1 %54, label %55, label %58
55: ; preds = %46
%56 = load i8*, i8** %8
%57 = call i32 @free(i8* %56)
store i32 0, i32* %4
br label %98
58: ; preds = %46
%59 = load i8*, i8** %6
%60 = load i8*, i8** %6
%61 = getelementptr inbounds i8, i8* %60, i64 1
%62 = load i8*, i8** %6
%63 = getelementptr inbounds i8, i8* %62, i64 1
%64 = call i32 @strlen(i8* %63)
%65 = call i32 @memmove(i8* %59, i8* %61, i32 %64)
%66 = load i8*, i8** %6
%67 = load i8*, i8** %6
%68 = call i32 @strlen(i8* %67)
%69 = sub nsw i32 %68, 1
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %66, i64 %70
store i8 0, i8* %71
%72 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %12)
store i8* %72, i8** %9
%73 = load i8*, i8** %9
%74 = icmp eq i8* %73, null
br i1 %74, label %79, label %75
75: ; preds = %58
%76 = load i8*, i8** %9
%77 = call i64 @strncmp(i8* %76, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 8)
%78 = icmp ne i64 %77, 0
br i1 %78, label %79, label %82
79: ; preds = %75, %58
%80 = load i8*, i8** %8
%81 = call i32 @free(i8* %80)
store i32 0, i32* %4
br label %98
82: ; preds = %75
br label %83
83: ; preds = %93, %82
%84 = load i8*, i8** %10
%85 = icmp ne i8* %84, null
br i1 %85, label %86, label %95
86: ; preds = %83
%87 = load i8*, i8** %10
%88 = call i32 @strlen(i8* %87)
%89 = icmp eq i32 %88, 1
br i1 %89, label %90, label %93
90: ; preds = %86
%91 = load i8*, i8** %8
%92 = call i32 @free(i8* %91)
store i32 1, i32* %4
br label %98
93: ; preds = %86
%94 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %11)
store i8* %94, i8** %10
br label %83
95: ; preds = %83
%96 = load i8*, i8** %8
%97 = call i32 @free(i8* %96)
store i32 0, i32* %4
br label %98
98: ; preds = %95, %90, %79, %55, %43, %36
%99 = load i32, i32* %4
ret i32 %99
}

LLVM IR (-O2):
@.str = [13 x i8] c"strndup fail\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [4 x i8] c"GET\00"
@.str.4 = [9 x i8] c"HTTP/1.1\00"
define i32 @checkGET(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = bitcast i8** %4 to i8*
%7 = bitcast i8** %5 to i8*
store i8* null, i8** %5
store i8* null, i8** %4
%8 = tail call i32 @strlen(i8* %0)
%9 = tail call i8* @strndup(i8* %0, i32 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = tail call i32 @err(i32 0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %3
%14 = call i8* @strtok_r(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %4)
%15 = call i32 @strlcpy(i8* %2, i8* %14)
%16 = call i8* @strtok_r(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %5)
%17 = icmp eq i8* %16, null
br i1 %17, label %50, label %18
18: ; preds = %13
%19 = call i64 @strncmp(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %50
21: ; preds = %18
%22 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %5)
%23 = icmp eq i8* %22, null
br i1 %23, label %50, label %24
24: ; preds = %21
%25 = call i32 @strlcpy(i8* %1, i8* %22)
%26 = load i8, i8* %1
%27 = icmp eq i8 %26, 47
br i1 %27, label %28, label %50
28: ; preds = %24
%29 = getelementptr inbounds i8, i8* %1, i64 1
%30 = call i32 @strlen(i8* %29)
%31 = call i32 @memmove(i8* %1, i8* %29, i32 %30)
%32 = call i32 @strlen(i8* %1)
%33 = add nsw i32 %32, -1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %1, i64 %34
store i8 0, i8* %35
%36 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %5)
%37 = icmp eq i8* %36, null
br i1 %37, label %50, label %38
38: ; preds = %28
%39 = call i64 @strncmp(i8* %36, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 8)
%40 = icmp ne i64 %39, 0
%41 = icmp eq i8* %14, null
%42 = or i1 %40, %41
br i1 %42, label %50, label %43
43: ; preds = %38, %47
%44 = phi i8* [ %48, %47 ], [ %14, %38 ]
%45 = call i32 @strlen(i8* %44)
%46 = icmp eq i32 %45, 1
br i1 %46, label %50, label %47
47: ; preds = %43
%48 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %4)
%49 = icmp eq i8* %48, null
br i1 %49, label %50, label %43
50: ; preds = %47, %43, %28, %38, %24, %21, %13, %18
%51 = phi i32 [ 0, %18 ], [ 0, %13 ], [ 0, %21 ], [ 0, %24 ], [ 0, %38 ], [ 0, %28 ], [ 1, %43 ], [ 0, %47 ]
%52 = call i32 @free(i8* %9)
ret i32 %51
}