#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*/ strlcpy(char *, char *, int);
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, 256);
  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, 256);
  if (fileName[0] != '/') {
    free(backup);
    return 0;
  }
  word = strtok_r(NULL, " ", &wptr);
  if (word == NULL || strncmp(word, "HTTP/1.1", 8) != 0) {
    free(backup);
    return 0;
  }
  line = strtok_r(NULL, "\n", &lptr);
  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    $0x50,%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,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%esi
call   1070 <strndup@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11cd <checkGET+0x5d>
xor    %edi,%edi
lea    0xe38(%rip),%rsi
call   1080 <err@plt>
mov    -0x28(%rbp),%rdi
lea    0xe35(%rip),%rsi
lea    -0x40(%rbp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    $0x100,%edx
call   1090 <strlcpy@plt>
mov    -0x38(%rbp),%rdi
lea    0xe0d(%rip),%rsi
lea    -0x48(%rbp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1239 <checkGET+0xc9>
mov    -0x30(%rbp),%rdi
lea    0xdec(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     124e <checkGET+0xde>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    138b <checkGET+0x21b>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdb6(%rip),%rsi
lea    -0x48(%rbp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1286 <checkGET+0x116>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    138b <checkGET+0x21b>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x100,%edx
call   1090 <strlcpy@plt>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     12bd <checkGET+0x14d>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    138b <checkGET+0x21b>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd47(%rip),%rsi
lea    -0x48(%rbp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12ff <checkGET+0x18f>
mov    -0x30(%rbp),%rdi
lea    0xd2a(%rip),%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     1314 <checkGET+0x1a4>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    138b <checkGET+0x21b>
xor    %eax,%eax
mov    %eax,%edi
lea    0xcee(%rip),%rsi
lea    -0x40(%rbp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     137b <checkGET+0x20b>
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x1,%eax
jne    135e <checkGET+0x1ee>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    138b <checkGET+0x21b>
xor    %eax,%eax
mov    %eax,%edi
lea    0xca4(%rip),%rsi
lea    -0x40(%rbp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,-0x38(%rbp)
jmp    132c <checkGET+0x1bc>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkGET>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <strndup@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11bb <checkGET+0x4b>
lea    0xe4c(%rip),%rsi
xor    %edi,%edi
call   1080 <err@plt>
lea    0xe4b(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %r14,%rdi
call   1060 <strtok_r@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %rax,%rsi
mov    $0x100,%edx
call   1090 <strlcpy@plt>
lea    0xe26(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <strtok_r@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1216 <checkGET+0xa6>
lea    0xe0d(%rip),%rsi
mov    %rax,%rdi
mov    $0x3,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     122c <checkGET+0xbc>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xddc(%rip),%rsi
xor    %ebx,%ebx
lea    0x8(%rsp),%rdx
xor    %edi,%edi
call   1060 <strtok_r@plt>
test   %rax,%rax
je     1216 <checkGET+0xa6>
mov    %r15,%rdi
mov    %rax,%rsi
mov    $0x100,%edx
call   1090 <strlcpy@plt>
cmpb   $0x2f,(%r15)
jne    1216 <checkGET+0xa6>
lea    0xdac(%rip),%rsi
xor    %ebx,%ebx
lea    0x8(%rsp),%rdx
xor    %edi,%edi
call   1060 <strtok_r@plt>
test   %rax,%rax
je     1216 <checkGET+0xa6>
lea    0xd98(%rip),%rsi
mov    %rax,%rdi
mov    $0x8,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1216 <checkGET+0xa6>
lea    0xd77(%rip),%rsi
xor    %ebx,%ebx
lea    0x10(%rsp),%rdx
xor    %edi,%edi
call   1060 <strtok_r@plt>
test   %rax,%rax
je     1216 <checkGET+0xa6>
lea    0xd59(%rip),%r15
lea    0x10(%rsp),%r12
mov    %rax,%rdi
call   1050 <strlen@plt>
cmp    $0x1,%eax
je     12df <checkGET+0x16f>
xor    %ebx,%ebx
xor    %edi,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1060 <strtok_r@plt>
test   %rax,%rax
jne    12b9 <checkGET+0x149>
jmp    1216 <checkGET+0xa6>
mov    $0x1,%ebx
jmp    1216 <checkGET+0xa6>

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*
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
%13 = load i8*, i8** %5
%14 = load i8*, i8** %5
%15 = call i32 @strlen(i8* %14)
%16 = call i8* @strndup(i8* %13, i32 %15)
store i8* %16, i8** %8
%17 = load i8*, i8** %8
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %21
19: ; preds = %3
%20 = call i32 @err(i32 0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %3
%22 = load i8*, i8** %8
%23 = call i8* @strtok_r(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %11)
store i8* %23, i8** %10
%24 = load i8*, i8** %7
%25 = load i8*, i8** %10
%26 = call i32 @strlcpy(i8* %24, i8* %25, i32 256)
%27 = load i8*, i8** %10
%28 = call i8* @strtok_r(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %12)
store i8* %28, i8** %9
%29 = load i8*, i8** %9
%30 = icmp eq i8* %29, null
br i1 %30, label %35, label %31
31: ; preds = %21
%32 = load i8*, i8** %9
%33 = call i64 @strncmp(i8* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %31, %21
%36 = load i8*, i8** %8
%37 = call i32 @free(i8* %36)
store i32 0, i32* %4
br label %85
38: ; preds = %31
%39 = 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* %39, i8** %9
%40 = load i8*, i8** %9
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = load i8*, i8** %8
%44 = call i32 @free(i8* %43)
store i32 0, i32* %4
br label %85
45: ; preds = %38
%46 = load i8*, i8** %6
%47 = load i8*, i8** %9
%48 = call i32 @strlcpy(i8* %46, i8* %47, i32 256)
%49 = load i8*, i8** %6
%50 = getelementptr inbounds i8, i8* %49, i64 0
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 47
br i1 %53, label %54, label %57
54: ; preds = %45
%55 = load i8*, i8** %8
%56 = call i32 @free(i8* %55)
store i32 0, i32* %4
br label %85
57: ; preds = %45
%58 = 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* %58, i8** %9
%59 = load i8*, i8** %9
%60 = icmp eq i8* %59, null
br i1 %60, label %65, label %61
61: ; preds = %57
%62 = load i8*, i8** %9
%63 = call i64 @strncmp(i8* %62, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 8)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %68
65: ; preds = %61, %57
%66 = load i8*, i8** %8
%67 = call i32 @free(i8* %66)
store i32 0, i32* %4
br label %85
68: ; preds = %61
%69 = 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* %69, i8** %10
br label %70
70: ; preds = %80, %68
%71 = load i8*, i8** %10
%72 = icmp ne i8* %71, null
br i1 %72, label %73, label %82
73: ; preds = %70
%74 = load i8*, i8** %10
%75 = call i32 @strlen(i8* %74)
%76 = icmp eq i32 %75, 1
br i1 %76, label %77, label %80
77: ; preds = %73
%78 = load i8*, i8** %8
%79 = call i32 @free(i8* %78)
store i32 1, i32* %4
br label %85
80: ; preds = %73
%81 = 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* %81, i8** %10
br label %70
82: ; preds = %70
%83 = load i8*, i8** %8
%84 = call i32 @free(i8* %83)
store i32 0, i32* %4
br label %85
85: ; preds = %82, %77, %65, %54, %42, %35
%86 = load i32, i32* %4
ret i32 %86
}

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, i32 256)
%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 %44, 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 %44
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 %44, label %24
24: ; preds = %21
%25 = call i32 @strlcpy(i8* %1, i8* %22, i32 256)
%26 = load i8, i8* %1
%27 = icmp eq i8 %26, 47
br i1 %27, label %28, label %44
28: ; preds = %24
%29 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %5)
%30 = icmp eq i8* %29, null
br i1 %30, label %44, label %31
31: ; preds = %28
%32 = call i64 @strncmp(i8* %29, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 8)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %44
34: ; preds = %31
%35 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %4)
%36 = icmp eq i8* %35, null
br i1 %36, label %44, label %37
37: ; preds = %34, %41
%38 = phi i8* [ %42, %41 ], [ %35, %34 ]
%39 = call i32 @strlen(i8* %38)
%40 = icmp eq i32 %39, 1
br i1 %40, label %44, label %41
41: ; preds = %37
%42 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %4)
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %37
44: ; preds = %41, %37, %34, %28, %31, %24, %21, %13, %18
%45 = phi i32 [ 0, %18 ], [ 0, %13 ], [ 0, %21 ], [ 0, %24 ], [ 0, %31 ], [ 0, %28 ], [ 0, %34 ], [ 1, %37 ], [ 0, %41 ]
%46 = call i32 @free(i8* %9)
ret i32 %45
}