#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 */
typedef int /*<<< orphan*/ line;

/* Variables and functions */
int get_next_line(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int sscanf(char *, char *, char *, ...);
scalar_t__ strcmp(char *, char *);
int get_directory(char *buffer, char *directory, char *getline) {
  char line[4096] = {0};
  char get[4096] = {0};
  char http[4096] = {0};
  char from[4096] = {0};
  char useragent[4096] = {0};
  int position = 0;
  position = get_next_line(buffer, getline, position);
  if (position == -1)
    return -1;
  if ((sscanf(getline, "%s %s %s", get, directory, http) != 3) ||
      (strcmp(get, "GET") != 0) || (strcmp(http, "HTTP/1.1") != 0))
    return -1;
  position = get_next_line(buffer, line, position);
  if (position == -1)
    return -1;
  sscanf(line, "%s", from);
  if (strcmp(from, "From:") != 0 && strcmp(from, "Host:") != 0)
    return -1;
  memset(line, 0, sizeof(line));
  get_next_line(buffer, line, position);
  sscanf(line, "%s", useragent);
  if (strcmp(useragent, "User-Agent:") != 0)
    return -1;
  return 1;
}


x86 assembly (clang, -O0):
<get_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x5030,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x1020(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1030 <memset@plt>
lea    -0x2020(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1030 <memset@plt>
lea    -0x3020(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1030 <memset@plt>
lea    -0x4020(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1030 <memset@plt>
lea    -0x5020(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1030 <memset@plt>
movl   $0x0,-0x5024(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x5024(%rbp),%edx
call   1060 <get_next_line@plt>
mov    %eax,-0x5024(%rbp)
cmpl   $0xffffffff,-0x5024(%rbp)
jne    11f2 <get_directory+0xb2>
movl   $0xffffffff,-0x4(%rbp)
jmp    1371 <get_directory+0x231>
mov    -0x20(%rbp),%rdi
lea    -0x2020(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x3020(%rbp),%r8
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x3,%eax
jne    1259 <get_directory+0x119>
lea    -0x2020(%rbp),%rdi
lea    0xddc(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1259 <get_directory+0x119>
lea    -0x3020(%rbp),%rdi
lea    0xdc3(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1265 <get_directory+0x125>
movl   $0xffffffff,-0x4(%rbp)
jmp    1371 <get_directory+0x231>
mov    -0x10(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
mov    -0x5024(%rbp),%edx
call   1060 <get_next_line@plt>
mov    %eax,-0x5024(%rbp)
cmpl   $0xffffffff,-0x5024(%rbp)
jne    129a <get_directory+0x15a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1371 <get_directory+0x231>
lea    -0x1020(%rbp),%rdi
lea    -0x4020(%rbp),%rdx
lea    0xd57(%rip),%rsi
mov    $0x0,%al
call   1050 <sscanf@plt>
lea    -0x4020(%rbp),%rdi
lea    0xd52(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     12fc <get_directory+0x1bc>
lea    -0x4020(%rbp),%rdi
lea    0xd3b(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     12fc <get_directory+0x1bc>
movl   $0xffffffff,-0x4(%rbp)
jmp    1371 <get_directory+0x231>
lea    -0x1020(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
mov    -0x5024(%rbp),%edx
call   1060 <get_next_line@plt>
lea    -0x1020(%rbp),%rdi
lea    -0x5020(%rbp),%rdx
lea    0xccc(%rip),%rsi
mov    $0x0,%al
call   1050 <sscanf@plt>
lea    -0x5020(%rbp),%rdi
lea    0xcd3(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     136a <get_directory+0x22a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1371 <get_directory+0x231>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x5030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_directory>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x5000,%rsp
mov    %rdx,%rbp
mov    %rsi,%r12
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x1000,%edx
xor    %esi,%esi
call   1030 <memset@plt>
lea    0x3000(%rsp),%rdi
mov    $0x1000,%edx
xor    %esi,%esi
call   1030 <memset@plt>
lea    0x2000(%rsp),%rdi
mov    $0x1000,%edx
xor    %esi,%esi
call   1030 <memset@plt>
lea    0x1000(%rsp),%rdi
mov    $0x1000,%edx
xor    %esi,%esi
call   1030 <memset@plt>
lea    0x4000(%rsp),%rdi
mov    $0x1000,%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
xor    %edx,%edx
call   1060 <get_next_line@plt>
mov    $0xffffffff,%r15d
cmp    $0xffffffff,%eax
je     122c <get_directory+0xec>
mov    %eax,%ebx
lea    0xe28(%rip),%rsi
lea    0x3000(%rsp),%rdx
lea    0x2000(%rsp),%r8
mov    %rbp,%rdi
mov    %r12,%rcx
xor    %eax,%eax
call   1050 <sscanf@plt>
cmp    $0x3,%eax
jne    122c <get_directory+0xec>
lea    0xe08(%rip),%rsi
lea    0x3000(%rsp),%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    122c <get_directory+0xec>
lea    0xdf3(%rip),%rsi
lea    0x2000(%rsp),%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     123f <get_directory+0xff>
mov    %r15d,%eax
add    $0x5000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   1060 <get_next_line@plt>
cmp    $0xffffffff,%eax
je     122c <get_directory+0xec>
mov    %eax,%ebx
lea    0xdac(%rip),%rsi
mov    %rsp,%rdi
lea    0x1000(%rsp),%rbp
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
lea    0xda0(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     129c <get_directory+0x15c>
lea    0xd92(%rip),%rsi
lea    0x1000(%rsp),%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    122c <get_directory+0xec>
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1030 <memset@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1060 <get_next_line@plt>
lea    0xd44(%rip),%rsi
lea    0x4000(%rsp),%rbx
mov    %rbp,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
lea    0xd44(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
neg    %rax
sbb    %r15d,%r15d
or     $0x1,%r15d
jmp    122c <get_directory+0xec>

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

LLVM IR (-O2):
@.str = [9 x i8] c"%s %s %s\00"
@.str.1 = [4 x i8] c"GET\00"
@.str.2 = [9 x i8] c"HTTP/1.1\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [6 x i8] c"From:\00"
@.str.5 = [6 x i8] c"Host:\00"
@.str.6 = [12 x i8] c"User-Agent:\00"
define i32 @get_directory(i8* %0, i8* %1, i8* %2) {
%4 = alloca [4096 x i8]
%5 = alloca [4096 x i8]
%6 = alloca [4096 x i8]
%7 = alloca [4096 x i8]
%8 = alloca [4096 x i8]
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%14 = tail call i32 @get_next_line(i8* %0, i8* %2, i32 0)
%15 = icmp eq i32 %14, -1
br i1 %15, label %42, label %16
16: ; preds = %3
%17 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %10, i8* %1, i8* %11)
%18 = icmp eq i32 %17, 3
br i1 %18, label %19, label %42
19: ; preds = %16
%20 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %42
22: ; preds = %19
%23 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %42
25: ; preds = %22
%26 = call i32 @get_next_line(i8* %0, i8* %9, i32 %14)
%27 = icmp eq i32 %26, -1
br i1 %27, label %42, label %28
28: ; preds = %25
%29 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%30 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %28
%33 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %32, %28
%36 = call i32 @memset(i8* %9, i32 0, i32 4096)
%37 = call i32 @get_next_line(i8* %0, i8* %9, i32 %26)
%38 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%39 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
%41 = select i1 %40, i32 1, i32 -1
br label %42
42: ; preds = %35, %32, %25, %16, %19, %22, %3
%43 = phi i32 [ -1, %3 ], [ -1, %22 ], [ -1, %19 ], [ -1, %16 ], [ -1, %25 ], [ -1, %32 ], [ %41, %35 ]
ret i32 %43
}