#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 */
char *malloc(int);
char *realloc(char *, int);
scalar_t__ strcmp(char *, char *);
char *strstr(char *, char *);
int words(char *);
int checkGet(char *ligne) {
  char *buffer = malloc(4 * sizeof(char));
  int i;
  for (i = 0; i < 4; ++i) {
    buffer[i] = ligne[i];
  }
  if (strcmp(buffer, "GET ") != 0) {
    return -1;
  }
  if (words(ligne) != 3) {
    return -1;
  }
  char *troisiemeMot = strstr(ligne, "HTTP/");
  int position = troisiemeMot - ligne;
  buffer = realloc(buffer, 8 * sizeof(char));
  for (i = 0; i < 8; i++) {
    buffer[i] = ligne[i + position];
  }
  if (strcmp(buffer, "HTTP/1.0") != 0 && strcmp(buffer, "HTTP/1.1") != 0) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<checkGet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    119f <checkGet+0x4f>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1171 <checkGet+0x21>
mov    -0x18(%rbp),%rdi
lea    0xe56(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     11c5 <checkGet+0x75>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <checkGet+0x148>
mov    -0x10(%rbp),%rdi
call   1040 <words@plt>
cmp    $0x3,%eax
je     11e3 <checkGet+0x93>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <checkGet+0x148>
mov    -0x10(%rbp),%rdi
lea    0xe17(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x8,%esi
call   1060 <realloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    1251 <checkGet+0x101>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    -0x2c(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    121e <checkGet+0xce>
mov    -0x18(%rbp),%rdi
lea    0xdaf(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     1291 <checkGet+0x141>
mov    -0x18(%rbp),%rdi
lea    0xd9e(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     1291 <checkGet+0x141>
movl   $0xffffffff,-0x4(%rbp)
jmp    1298 <checkGet+0x148>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkGet>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
mov    (%rbx),%eax
mov    %eax,0x0(%rbp)
lea    0xe8d(%rip),%rsi
mov    %rbp,%rdi
call   1030 <strcmp@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
jne    1225 <checkGet+0xd5>
mov    %rbx,%rdi
call   1040 <words@plt>
cmp    $0x3,%eax
jne    1225 <checkGet+0xd5>
lea    0xe63(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strstr@plt>
mov    %rax,%r15
sub    %ebx,%r15d
mov    %rbp,%rdi
mov    $0x8,%esi
call   1060 <realloc@plt>
mov    %rax,%rbp
movslq %r15d,%rax
mov    (%rbx,%rax,1),%cl
mov    %cl,0x0(%rbp)
mov    0x1(%rbx,%rax,1),%cl
mov    %cl,0x1(%rbp)
mov    0x2(%rbx,%rax,1),%cl
mov    %cl,0x2(%rbp)
mov    0x3(%rbx,%rax,1),%cl
mov    %cl,0x3(%rbp)
mov    0x4(%rbx,%rax,1),%cl
mov    %cl,0x4(%rbp)
mov    0x5(%rbx,%rax,1),%cl
mov    %cl,0x5(%rbp)
mov    0x6(%rbx,%rax,1),%cl
mov    %cl,0x6(%rbp)
mov    0x7(%rbx,%rax,1),%al
mov    %al,0x7(%rbp)
lea    0xe0a(%rip),%rsi
mov    %rbp,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1222 <checkGet+0xd2>
lea    0xdff(%rip),%rsi
mov    %rbp,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
jne    1225 <checkGet+0xd5>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"GET \00"
@.str.1 = [6 x i8] c"HTTP/\00"
@.str.2 = [9 x i8] c"HTTP/1.0\00"
@.str.3 = [9 x i8] c"HTTP/1.1\00"
define i32 @checkGet(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
%8 = call i8* @malloc(i32 4)
store i8* %8, i8** %4
store i32 0, i32* %5
br label %9
9: ; preds = %22, %1
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 4
br i1 %11, label %12, label %25
12: ; preds = %9
%13 = load i8*, i8** %3
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = load i8*, i8** %4
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
store i8 %17, i8* %21
br label %22
22: ; preds = %12
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %9
25: ; preds = %9
%26 = load i8*, i8** %4
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 -1, i32* %2
br label %74
30: ; preds = %25
%31 = load i8*, i8** %3
%32 = call i32 @words(i8* %31)
%33 = icmp ne i32 %32, 3
br i1 %33, label %34, label %35
34: ; preds = %30
store i32 -1, i32* %2
br label %74
35: ; preds = %30
%36 = load i8*, i8** %3
%37 = call i8* @strstr(i8* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i8* %37, i8** %6
%38 = load i8*, i8** %6
%39 = load i8*, i8** %3
%40 = ptrtoint i8* %38 to i64
%41 = ptrtoint i8* %39 to i64
%42 = sub i64 %40, %41
%43 = trunc i64 %42 to i32
store i32 %43, i32* %7
%44 = load i8*, i8** %4
%45 = call i8* @realloc(i8* %44, i32 8)
store i8* %45, i8** %4
store i32 0, i32* %5
br label %46
46: ; preds = %61, %35
%47 = load i32, i32* %5
%48 = icmp slt i32 %47, 8
br i1 %48, label %49, label %64
49: ; preds = %46
%50 = load i8*, i8** %3
%51 = load i32, i32* %5
%52 = load i32, i32* %7
%53 = add nsw i32 %51, %52
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %50, i64 %54
%56 = load i8, i8* %55
%57 = load i8*, i8** %4
%58 = load i32, i32* %5
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
store i8 %56, i8* %60
br label %61
61: ; preds = %49
%62 = load i32, i32* %5
%63 = add nsw i32 %62, 1
store i32 %63, i32* %5
br label %46
64: ; preds = %46
%65 = load i8*, i8** %4
%66 = call i64 @strcmp(i8* %65, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %73
68: ; preds = %64
%69 = load i8*, i8** %4
%70 = call i64 @strcmp(i8* %69, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %73
72: ; preds = %68
store i32 -1, i32* %2
br label %74
73: ; preds = %68, %64
store i32 0, i32* %2
br label %74
74: ; preds = %73, %72, %34, %29
%75 = load i32, i32* %2
ret i32 %75
}

LLVM IR (-O2):
@.str = [5 x i8] c"GET \00"
@.str.1 = [6 x i8] c"HTTP/\00"
@.str.2 = [9 x i8] c"HTTP/1.0\00"
@.str.3 = [9 x i8] c"HTTP/1.1\00"
define i32 @checkGet(i8* %0) {
%2 = tail call dereferenceable_or_null(4) i8* @malloc(i32 4)
%3 = bitcast i8* %0 to i32*
%4 = bitcast i8* %2 to i32*
%5 = load i32, i32* %3
store i32 %5, i32* %4
%6 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %55
8: ; preds = %1
%9 = tail call i32 @words(i8* %0)
%10 = icmp eq i32 %9, 3
br i1 %10, label %11, label %55
11: ; preds = %8
%12 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%13 = ptrtoint i8* %12 to i64
%14 = ptrtoint i8* %0 to i64
%15 = sub i64 %13, %14
%16 = tail call i8* @realloc(i8* %2, i32 8)
%17 = shl i64 %15, 32
%18 = ashr exact i64 %17, 32
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
store i8 %20, i8* %16
%21 = add nsw i64 %18, 1
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = load i8, i8* %22
%24 = getelementptr inbounds i8, i8* %16, i64 1
store i8 %23, i8* %24
%25 = add nsw i64 %18, 2
%26 = getelementptr inbounds i8, i8* %0, i64 %25
%27 = load i8, i8* %26
%28 = getelementptr inbounds i8, i8* %16, i64 2
store i8 %27, i8* %28
%29 = add nsw i64 %18, 3
%30 = getelementptr inbounds i8, i8* %0, i64 %29
%31 = load i8, i8* %30
%32 = getelementptr inbounds i8, i8* %16, i64 3
store i8 %31, i8* %32
%33 = add nsw i64 %18, 4
%34 = getelementptr inbounds i8, i8* %0, i64 %33
%35 = load i8, i8* %34
%36 = getelementptr inbounds i8, i8* %16, i64 4
store i8 %35, i8* %36
%37 = add nsw i64 %18, 5
%38 = getelementptr inbounds i8, i8* %0, i64 %37
%39 = load i8, i8* %38
%40 = getelementptr inbounds i8, i8* %16, i64 5
store i8 %39, i8* %40
%41 = add nsw i64 %18, 6
%42 = getelementptr inbounds i8, i8* %0, i64 %41
%43 = load i8, i8* %42
%44 = getelementptr inbounds i8, i8* %16, i64 6
store i8 %43, i8* %44
%45 = add nsw i64 %18, 7
%46 = getelementptr inbounds i8, i8* %0, i64 %45
%47 = load i8, i8* %46
%48 = getelementptr inbounds i8, i8* %16, i64 7
store i8 %47, i8* %48
%49 = tail call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%50 = icmp eq i64 %49, 0
br i1 %50, label %54, label %51
51: ; preds = %11
%52 = tail call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %51, %11
br label %55
55: ; preds = %54, %51, %8, %1
%56 = phi i32 [ -1, %1 ], [ -1, %8 ], [ 0, %54 ], [ -1, %51 ]
ret i32 %56
}