#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 *strstr(char *, char *);
int find_head_offset(char *upload_data) {
  int head_offset = 0;
  char *pStart = NULL;
  int iestr_offset = 0;
  char *dquote;
  char *dquote1;
  if (upload_data == NULL) {
    return -1;
  }
  pStart = strstr(upload_data, "/octet-stream\x0d\x0a\0x0d\0x0a");
  if (pStart == NULL) {
    pStart = strstr(upload_data, "/x-ns-proxy-autoconfig\x0d\x0a\0x0d\0x0a");
    if (pStart == NULL) {
      pStart = strstr(upload_data, "/macbinary\x0d\x0a\0x0d\0x0a");
      if (pStart == NULL) {
        pStart = strstr(upload_data, "/x-macbinary\x0d\x0a\0x0d\0x0a");
        if (pStart == NULL) {
          pStart = strstr(upload_data, "filename=");
          if (pStart == NULL) {
            return -1;
          } else {
            dquote = strstr(pStart, "\"");
            if (dquote != NULL) {
              dquote1 = strstr(dquote, "\x0d\x0a\0x0d\0x0a");
              if (dquote1 != NULL) {
                iestr_offset = 4;
                pStart = dquote1;
              } else {
                return -1;
              }
            } else {
              return -1;
            }
          }
        } else {
          iestr_offset = 16;
        }
      } else {
        iestr_offset = 14;
      }
    } else {
      iestr_offset = 26;
    }
  } else {
    iestr_offset = 17;
  }
  head_offset = (int)(((unsigned long)pStart) - ((unsigned long)upload_data)) +
                iestr_offset;
  return head_offset;
}


x86 assembly (clang, -O0):
<find_head_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1149 <find_head_offset+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ab <find_head_offset+0x19b>
mov    -0x10(%rbp),%rdi
lea    0xeac(%rip),%rsi
call   1030 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    128d <find_head_offset+0x17d>
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1030 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1281 <find_head_offset+0x171>
mov    -0x10(%rbp),%rdi
lea    0xea7(%rip),%rsi
call   1030 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1275 <find_head_offset+0x165>
mov    -0x10(%rbp),%rdi
lea    0xe9d(%rip),%rsi
call   1030 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1269 <find_head_offset+0x159>
mov    -0x10(%rbp),%rdi
lea    0xea0(%rip),%rsi
call   1030 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f0 <find_head_offset+0xe0>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ab <find_head_offset+0x19b>
mov    -0x20(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1030 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1253 <find_head_offset+0x143>
mov    -0x30(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   1030 <strstr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1242 <find_head_offset+0x132>
movl   $0x4,-0x24(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    124e <find_head_offset+0x13e>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ab <find_head_offset+0x19b>
jmp    125f <find_head_offset+0x14f>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ab <find_head_offset+0x19b>
jmp    1264 <find_head_offset+0x154>
jmp    1270 <find_head_offset+0x160>
movl   $0x10,-0x24(%rbp)
jmp    127c <find_head_offset+0x16c>
movl   $0xe,-0x24(%rbp)
jmp    1288 <find_head_offset+0x178>
movl   $0x1a,-0x24(%rbp)
jmp    1294 <find_head_offset+0x184>
movl   $0x11,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    -0x24(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_head_offset>:
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%ebx
test   %rdi,%rdi
je     11a0 <find_head_offset+0x80>
mov    %rdi,%r14
lea    0xec8(%rip),%rsi
call   1040 <strstr@plt>
test   %rax,%rax
je     1149 <find_head_offset+0x29>
mov    $0x11,%ecx
jmp    1198 <find_head_offset+0x78>
lea    0xec8(%rip),%rsi
mov    %r14,%rdi
call   1040 <strstr@plt>
test   %rax,%rax
je     1164 <find_head_offset+0x44>
mov    $0x1a,%ecx
jmp    1198 <find_head_offset+0x78>
lea    0xece(%rip),%rsi
mov    %r14,%rdi
call   1040 <strstr@plt>
test   %rax,%rax
je     117f <find_head_offset+0x5f>
mov    $0xe,%ecx
jmp    1198 <find_head_offset+0x78>
lea    0xec8(%rip),%rsi
mov    %r14,%rdi
call   1040 <strstr@plt>
test   %rax,%rax
je     11aa <find_head_offset+0x8a>
mov    $0x10,%ecx
mov    %rax,%rbx
sub    %r14d,%ebx
add    %ecx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xebf(%rip),%rsi
mov    %r14,%rdi
call   1040 <strstr@plt>
test   %rax,%rax
je     11a0 <find_head_offset+0x80>
mov    %rax,%rdi
mov    $0x22,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11a0 <find_head_offset+0x80>
lea    0xe8e(%rip),%rsi
mov    %rax,%rdi
call   1040 <strstr@plt>
test   %rax,%rax
je     11a0 <find_head_offset+0x80>
mov    $0x4,%ecx
jmp    1198 <find_head_offset+0x78>

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

LLVM IR (-O2):
@.str = [24 x i8] c"/octet-stream\0D\0A\00x0d\00x0a\00"
@.str.1 = [33 x i8] c"/x-ns-proxy-autoconfig\0D\0A\00x0d\00x0a\00"
@.str.2 = [21 x i8] c"/macbinary\0D\0A\00x0d\00x0a\00"
@.str.3 = [23 x i8] c"/x-macbinary\0D\0A\00x0d\00x0a\00"
@.str.4 = [10 x i8] c"filename=\00"
@.str.6 = [11 x i8] c"\0D\0A\00x0d\00x0a\00"
define i32 @find_head_offset(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %32, label %3
3: ; preds = %1
%4 = tail call i8* @strstr(i8* %0, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %24
6: ; preds = %3
%7 = tail call i8* @strstr(i8* %0, i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %24
9: ; preds = %6
%10 = tail call i8* @strstr(i8* %0, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %24
12: ; preds = %9
%13 = tail call i8* @strstr(i8* %0, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %24
15: ; preds = %12
%16 = tail call i8* @strstr(i8* %0, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %32, label %18
18: ; preds = %15
%19 = tail call i8* @strchr(i8* %16, i32 34)
%20 = icmp eq i8* %19, null
br i1 %20, label %32, label %21
21: ; preds = %18
%22 = tail call i8* @strstr(i8* %19, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%23 = icmp eq i8* %22, null
br i1 %23, label %32, label %24
24: ; preds = %3, %6, %9, %12, %21
%25 = phi i8* [ %22, %21 ], [ %13, %12 ], [ %10, %9 ], [ %7, %6 ], [ %4, %3 ]
%26 = phi i32 [ 4, %21 ], [ 16, %12 ], [ 14, %9 ], [ 26, %6 ], [ 17, %3 ]
%27 = ptrtoint i8* %25 to i64
%28 = ptrtoint i8* %0 to i64
%29 = sub i64 %27, %28
%30 = trunc i64 %29 to i32
%31 = add nsw i32 %26, %30
br label %32
32: ; preds = %18, %21, %15, %1, %24
%33 = phi i32 [ %31, %24 ], [ -1, %1 ], [ -1, %15 ], [ -1, %21 ], [ -1, %18 ]
ret i32 %33
}