#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*/ MIMEH_decode_qp(char *);
scalar_t__ XAM_strncasecmp(char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
char *strpbrk(char *, char *);
char *strrchr(char *, char);
scalar_t__ strstr(char *, char *);
int /*<<< orphan*/ zstrncpy(char *, char *, int);
int MIMEH_parse_filename(char *dest, char *raw) {
  char c = '\0';
  char *p, *q, *n;
  int qp_encode = 0;
  int quoted = 0;
  char tmp[1023 + 1];
  n = strpbrk(raw, "\n\r;");
  if (n) {
    c = *n;
    *n = '\0';
  }
  zstrncpy(tmp, raw, 1023);
  p = tmp;
  if (XAM_strncasecmp(p, "\"3d", 3) == 0) {
    qp_encode = 1;
    quoted = 1;
    p += 3;
  } else if (XAM_strncasecmp(p, "3d\"", 3) == 0) {
    qp_encode = 1;
    quoted = 1;
    p += 3;
  } else if (XAM_strncasecmp(p, "3d", 2) == 0) {
    qp_encode = 1;
    quoted = 0;
    p += 2;
  } else if ((*p) == '\"') {
    qp_encode = 0;
    quoted = 1;
    p++;
  }
  if ((qp_encode) && (strstr(p, "=OA=")))
    qp_encode = 1;
  else
    qp_encode = 0;
  snprintf(dest, 128, "%s", p);
  if (qp_encode)
    MIMEH_decode_qp(dest);
  if (quoted) {
    q = strrchr(dest, '\"');
    if (q)
      *q = '\0';
  }
  if (n)
    *n = c;
  return 0;
}


x86 assembly (clang, -O0):
<MIMEH_parse_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1070 <strpbrk@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11c4 <MIMEH_parse_filename+0x54>
mov    -0x30(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x440(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x3ff,%edx
call   1080 <zstrncpy@plt>
lea    -0x440(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe15(%rip),%rsi
mov    $0x3,%edx
call   1060 <XAM_strncasecmp@plt>
cmp    $0x0,%rax
jne    1222 <MIMEH_parse_filename+0xb2>
movl   $0x1,-0x34(%rbp)
movl   $0x1,-0x38(%rbp)
mov    -0x20(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x20(%rbp)
jmp    12d7 <MIMEH_parse_filename+0x167>
mov    -0x20(%rbp),%rdi
lea    0xddb(%rip),%rsi
mov    $0x3,%edx
call   1060 <XAM_strncasecmp@plt>
cmp    $0x0,%rax
jne    1260 <MIMEH_parse_filename+0xf0>
movl   $0x1,-0x34(%rbp)
movl   $0x1,-0x38(%rbp)
mov    -0x20(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x20(%rbp)
jmp    12d2 <MIMEH_parse_filename+0x162>
mov    -0x20(%rbp),%rdi
lea    0xd9a(%rip),%rsi
mov    $0x2,%edx
call   1060 <XAM_strncasecmp@plt>
cmp    $0x0,%rax
jne    129e <MIMEH_parse_filename+0x12e>
movl   $0x1,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
jmp    12cd <MIMEH_parse_filename+0x15d>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    12c8 <MIMEH_parse_filename+0x158>
movl   $0x0,-0x34(%rbp)
movl   $0x1,-0x38(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    12cd <MIMEH_parse_filename+0x15d>
jmp    12d2 <MIMEH_parse_filename+0x162>
jmp    12d7 <MIMEH_parse_filename+0x167>
cmpl   $0x0,-0x34(%rbp)
je     1307 <MIMEH_parse_filename+0x197>
mov    -0x20(%rbp),%rdi
lea    0xd20(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     1307 <MIMEH_parse_filename+0x197>
movl   $0x1,-0x34(%rbp)
jmp    130e <MIMEH_parse_filename+0x19e>
movl   $0x0,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x80,%esi
lea    0xcef(%rip),%rdx
call   1040 <snprintf@plt>
cmpl   $0x0,-0x34(%rbp)
je     133a <MIMEH_parse_filename+0x1ca>
mov    -0x8(%rbp),%rdi
call   1030 <MIMEH_decode_qp@plt>
cmpl   $0x0,-0x38(%rbp)
je     136d <MIMEH_parse_filename+0x1fd>
mov    -0x8(%rbp),%rdi
mov    $0x22,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1368 <MIMEH_parse_filename+0x1f8>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
jmp    136d <MIMEH_parse_filename+0x1fd>
cmpq   $0x0,-0x30(%rbp)
je     1381 <MIMEH_parse_filename+0x211>
mov    -0x11(%rbp),%cl
mov    -0x30(%rbp),%rax
mov    %cl,(%rax)
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MIMEH_parse_filename>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe72(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strpbrk@plt>
mov    %rax,%r15
test   %rax,%rax
je     11a7 <MIMEH_parse_filename+0x37>
mov    (%r15),%r13b
movb   $0x0,(%r15)
jmp    11aa <MIMEH_parse_filename+0x3a>
xor    %r13d,%r13d
mov    %rsp,%r12
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x3ff,%edx
call   1080 <zstrncpy@plt>
lea    0xe40(%rip),%rsi
mov    %r12,%rdi
mov    $0x3,%edx
call   1060 <XAM_strncasecmp@plt>
mov    $0x3,%ebx
test   %rax,%rax
je     1240 <MIMEH_parse_filename+0xd0>
lea    0xe26(%rip),%rsi
mov    %rsp,%rdi
mov    $0x3,%edx
call   1060 <XAM_strncasecmp@plt>
test   %rax,%rax
je     1240 <MIMEH_parse_filename+0xd0>
lea    0xe0a(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x2,%edx
call   1060 <XAM_strncasecmp@plt>
test   %rax,%rax
je     1244 <MIMEH_parse_filename+0xd4>
mov    (%rsp),%bpl
cmp    $0x22,%bpl
lea    0x1(%rsp),%rax
cmove  %rax,%rbx
lea    0xde9(%rip),%rdx
mov    %r14,%rdi
mov    $0x80,%esi
mov    %rbx,%rcx
call   1040 <snprintf@plt>
cmp    $0x22,%bpl
je     128a <MIMEH_parse_filename+0x11a>
jmp    129f <MIMEH_parse_filename+0x12f>
xor    %ebp,%ebp
jmp    124c <MIMEH_parse_filename+0xdc>
mov    $0x1,%bpl
mov    $0x2,%ebx
add    %rsp,%rbx
lea    0xdb6(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strstr@plt>
mov    %rax,%r12
lea    0xda9(%rip),%rdx
mov    %r14,%rdi
mov    $0x80,%esi
mov    %rbx,%rcx
call   1040 <snprintf@plt>
test   %r12,%r12
je     1285 <MIMEH_parse_filename+0x115>
mov    %r14,%rdi
call   1030 <MIMEH_decode_qp@plt>
test   %bpl,%bpl
jne    129f <MIMEH_parse_filename+0x12f>
mov    %r14,%rdi
mov    $0x22,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     129f <MIMEH_parse_filename+0x12f>
movb   $0x0,(%rax)
test   %r15,%r15
je     12a7 <MIMEH_parse_filename+0x137>
mov    %r13b,(%r15)
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"\0A\0D;\00"
@.str.1 = [4 x i8] c"\223d\00"
@.str.2 = [4 x i8] c"3d\22\00"
@.str.3 = [3 x i8] c"3d\00"
@.str.4 = [5 x i8] c"=OA=\00"
@.str.5 = [3 x i8] c"%s\00"
define i32 @MIMEH_parse_filename(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca [1024 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8 0, i8* %5
store i32 0, i32* %9
store i32 0, i32* %10
%12 = load i8*, i8** %4
%13 = call i8* @strpbrk(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %8
%14 = load i8*, i8** %8
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i8*, i8** %8
%18 = load i8, i8* %17
store i8 %18, i8* %5
%19 = load i8*, i8** %8
store i8 0, i8* %19
br label %20
20: ; preds = %16, %2
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%22 = load i8*, i8** %4
%23 = call i32 @zstrncpy(i8* %21, i8* %22, i32 1023)
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
store i8* %24, i8** %6
%25 = load i8*, i8** %6
%26 = call i64 @XAM_strncasecmp(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %20
store i32 1, i32* %9
store i32 1, i32* %10
%29 = load i8*, i8** %6
%30 = getelementptr inbounds i8, i8* %29, i64 3
store i8* %30, i8** %6
br label %56
31: ; preds = %20
%32 = load i8*, i8** %6
%33 = call i64 @XAM_strncasecmp(i8* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %31
store i32 1, i32* %9
store i32 1, i32* %10
%36 = load i8*, i8** %6
%37 = getelementptr inbounds i8, i8* %36, i64 3
store i8* %37, i8** %6
br label %55
38: ; preds = %31
%39 = load i8*, i8** %6
%40 = call i64 @XAM_strncasecmp(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %38
store i32 1, i32* %9
store i32 0, i32* %10
%43 = load i8*, i8** %6
%44 = getelementptr inbounds i8, i8* %43, i64 2
store i8* %44, i8** %6
br label %54
45: ; preds = %38
%46 = load i8*, i8** %6
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 34
br i1 %49, label %50, label %53
50: ; preds = %45
store i32 0, i32* %9
store i32 1, i32* %10
%51 = load i8*, i8** %6
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %6
br label %53
53: ; preds = %50, %45
br label %54
54: ; preds = %53, %42
br label %55
55: ; preds = %54, %35
br label %56
56: ; preds = %55, %28
%57 = load i32, i32* %9
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %64
59: ; preds = %56
%60 = load i8*, i8** %6
%61 = call i64 @strstr(i8* %60, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %64
63: ; preds = %59
store i32 1, i32* %9
br label %65
64: ; preds = %59, %56
store i32 0, i32* %9
br label %65
65: ; preds = %64, %63
%66 = load i8*, i8** %3
%67 = load i8*, i8** %6
%68 = call i32 @snprintf(i8* %66, i32 128, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %67)
%69 = load i32, i32* %9
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %65
%72 = load i8*, i8** %3
%73 = call i32 @MIMEH_decode_qp(i8* %72)
br label %74
74: ; preds = %71, %65
%75 = load i32, i32* %10
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %85
77: ; preds = %74
%78 = load i8*, i8** %3
%79 = call i8* @strrchr(i8* %78, i8 signext 34)
store i8* %79, i8** %7
%80 = load i8*, i8** %7
%81 = icmp ne i8* %80, null
br i1 %81, label %82, label %84
82: ; preds = %77
%83 = load i8*, i8** %7
store i8 0, i8* %83
br label %84
84: ; preds = %82, %77
br label %85
85: ; preds = %84, %74
%86 = load i8*, i8** %8
%87 = icmp ne i8* %86, null
br i1 %87, label %88, label %91
88: ; preds = %85
%89 = load i8, i8* %5
%90 = load i8*, i8** %8
store i8 %89, i8* %90
br label %91
91: ; preds = %88, %85
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"\0A\0D;\00"
@.str.1 = [4 x i8] c"\223d\00"
@.str.2 = [4 x i8] c"3d\22\00"
@.str.3 = [3 x i8] c"3d\00"
@.str.4 = [5 x i8] c"=OA=\00"
@.str.5 = [3 x i8] c"%s\00"
define i32 @MIMEH_parse_filename(i8* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i8* @strpbrk(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = load i8, i8* %5
store i8 0, i8* %5
br label %9
9: ; preds = %7, %2
%10 = phi i8 [ %8, %7 ], [ 0, %2 ]
%11 = call i32 @zstrncpy(i8* %4, i8* %1, i32 1023)
%12 = call i64 @XAM_strncasecmp(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %26, label %14
14: ; preds = %9
%15 = call i64 @XAM_strncasecmp(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %14
%18 = call i64 @XAM_strncasecmp(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%19 = icmp eq i64 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %17
%21 = load i8, i8* %4
%22 = icmp eq i8 %21, 34
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 1
%24 = select i1 %22, i8* %23, i8* %4
%25 = call i32 @snprintf(i8* %0, i32 128, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %24)
br i1 %22, label %36, label %40
26: ; preds = %17, %14, %9
%27 = phi i64 [ 3, %9 ], [ 3, %14 ], [ 2, %17 ]
%28 = phi i1 [ false, %9 ], [ false, %14 ], [ true, %17 ]
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %27
%30 = call i64 @strstr(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
%32 = call i32 @snprintf(i8* %0, i32 128, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %29)
br i1 %31, label %33, label %34
33: ; preds = %26
br i1 %28, label %40, label %36
34: ; preds = %26
%35 = call i32 @MIMEH_decode_qp(i8* %0)
br i1 %28, label %40, label %36
36: ; preds = %20, %33, %34
%37 = call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 34)
%38 = icmp eq i8* %37, null
br i1 %38, label %40, label %39
39: ; preds = %36
store i8 0, i8* %37
br label %40
40: ; preds = %20, %33, %36, %39, %34
br i1 %6, label %42, label %41
41: ; preds = %40
store i8 %10, i8* %5
br label %42
42: ; preds = %41, %40
ret i32 0
}