#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*/ DecodeBase64(char *, int);
int /*<<< orphan*/ DecodeQuotedPrintable(char *, int);
char *strstr(char *, char *);
int DecodeHeader(char *encodedstring) {
  char *ptrS, *ptrE;
  if ((ptrS = strstr(encodedstring, "?B?")) ||
      (ptrS = strstr(encodedstring, "?b?"))) {
    ptrS += 3;
    if ((ptrE = strstr(ptrS, "?="))) {
      DecodeBase64(ptrS, ptrE - ptrS);
      return ptrE + 2 - encodedstring;
    }
  } else if ((ptrS = strstr(encodedstring, "?Q?")) ||
             (ptrS = strstr(encodedstring, "?q?"))) {
    ptrS += 3;
    if ((ptrE = strstr(ptrS, "?="))) {
      DecodeQuotedPrintable(ptrS, ptrE - ptrS);
      return ptrE + 2 - encodedstring;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<DecodeHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1178 <DecodeHeader+0x48>
mov    -0x10(%rbp),%rdi
lea    0xe9f(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11d4 <DecodeHeader+0xa4>
mov    -0x18(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11cf <DecodeHeader+0x9f>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1030 <DecodeBase64@plt>
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x4(%rbp)
jmp    1278 <DecodeHeader+0x148>
jmp    1271 <DecodeHeader+0x141>
mov    -0x10(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1210 <DecodeHeader+0xe0>
mov    -0x10(%rbp),%rdi
lea    0xe12(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     126c <DecodeHeader+0x13c>
mov    -0x18(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xde1(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1267 <DecodeHeader+0x137>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1040 <DecodeQuotedPrintable@plt>
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x4(%rbp)
jmp    1278 <DecodeHeader+0x148>
jmp    126c <DecodeHeader+0x13c>
jmp    1271 <DecodeHeader+0x141>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DecodeHeader>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xec1(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1163 <DecodeHeader+0x33>
lea    0xeb1(%rip),%rsi
mov    %r14,%rdi
call   1050 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1194 <DecodeHeader+0x64>
add    $0x3,%rbx
lea    0xe9a(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
je     11ec <DecodeHeader+0xbc>
mov    %rax,%r15
mov    %r15d,%esi
sub    %ebx,%esi
mov    %rbx,%rdi
call   1030 <DecodeBase64@plt>
sub    %r14d,%r15d
add    $0x2,%r15d
jmp    11f2 <DecodeHeader+0xc2>
lea    0xe70(%rip),%rsi
mov    %r14,%rdi
call   1050 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11c2 <DecodeHeader+0x92>
lea    0xe5d(%rip),%rsi
mov    %r14,%rdi
call   1050 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11ec <DecodeHeader+0xbc>
add    $0x3,%rbx
lea    0xe3b(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
je     11ec <DecodeHeader+0xbc>
mov    %rax,%r15
mov    %r15d,%esi
sub    %ebx,%esi
mov    %rbx,%rdi
call   1040 <DecodeQuotedPrintable@plt>
jmp    118b <DecodeHeader+0x5b>
mov    $0x1,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"?B?\00"
@.str.1 = [4 x i8] c"?b?\00"
@.str.2 = [3 x i8] c"?=\00"
@.str.3 = [4 x i8] c"?Q?\00"
@.str.4 = [4 x i8] c"?q?\00"
define i32 @DecodeHeader(i8* %0) {
%2 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %23, label %7
7: ; preds = %4, %1
%8 = phi i8* [ %2, %1 ], [ %5, %4 ]
%9 = getelementptr inbounds i8, i8* %8, i64 3
%10 = tail call i8* @strstr(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %45, label %12
12: ; preds = %7
%13 = ptrtoint i8* %10 to i64
%14 = ptrtoint i8* %9 to i64
%15 = sub i64 %13, %14
%16 = trunc i64 %15 to i32
%17 = tail call i32 @DecodeBase64(i8* %9, i32 %16)
%18 = getelementptr inbounds i8, i8* %10, i64 2
%19 = ptrtoint i8* %18 to i64
%20 = ptrtoint i8* %0 to i64
%21 = sub i64 %19, %20
%22 = trunc i64 %21 to i32
br label %45
23: ; preds = %4
%24 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%28 = icmp eq i8* %27, null
br i1 %28, label %45, label %29
29: ; preds = %26, %23
%30 = phi i8* [ %24, %23 ], [ %27, %26 ]
%31 = getelementptr inbounds i8, i8* %30, i64 3
%32 = tail call i8* @strstr(i8* %31, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp eq i8* %32, null
br i1 %33, label %45, label %34
34: ; preds = %29
%35 = ptrtoint i8* %32 to i64
%36 = ptrtoint i8* %31 to i64
%37 = sub i64 %35, %36
%38 = trunc i64 %37 to i32
%39 = tail call i32 @DecodeQuotedPrintable(i8* %31, i32 %38)
%40 = getelementptr inbounds i8, i8* %32, i64 2
%41 = ptrtoint i8* %40 to i64
%42 = ptrtoint i8* %0 to i64
%43 = sub i64 %41, %42
%44 = trunc i64 %43 to i32
br label %45
45: ; preds = %7, %29, %26, %34, %12
%46 = phi i32 [ %22, %12 ], [ %44, %34 ], [ 1, %26 ], [ 1, %29 ], [ 1, %7 ]
ret i32 %46
}