#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ md5digest(int /*<<< orphan*/ *, char *);
char *strrchr(char const *, char);
int /*<<< orphan*/ to64(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int mpack_encode(FILE *fpin, const char *fname, const char *note,
                 const char *subject, const char *recipient,
                 const char *reply_to, const char *type, FILE *fpout) {
  const char *cleanfname, *p;
  char digest[25];
  cleanfname = fname;
  if ((p = strrchr(cleanfname, '/')) != NULL)
    cleanfname = p + 1;
  if ((p = strrchr(cleanfname, '\\')) != NULL)
    cleanfname = p + 1;
  if ((p = strrchr(cleanfname, ':')) != NULL)
    cleanfname = p + 1;
  md5digest(fpin, digest);
  fprintf(fpout, "Mime-Version: 1.0\n");
  fprintf(fpout, "From: %s\n", reply_to);
  fprintf(fpout, "To: %s\n", recipient);
  fprintf(fpout, "Subject: %s\n", subject);
  fputs("Content-Type: multipart/mixed; boundary=\"-\"\n", fpout);
  fputs("\nThis is a MIME encoded message.\n\n", fpout);
  if (note != NULL) {
    fputs("---\n\n", fpout);
    fputs(note, fpout);
    fputc('\n', fpout);
  }
  fputs("---\n", fpout);
  fprintf(fpout, "Content-Type: %s; name=\"%s\"\n", type, cleanfname);
  fputs("Content-Transfer-Encoding: base64\n", fpout);
  fprintf(fpout, "Content-Disposition: inline; filename=\"%s\"\n", cleanfname);
  fprintf(fpout, "Content-MD5: %s\n\n", digest);
  to64(fpin, fpout);
  fputs("\n-----\n", fpout);
  return 0;
}


x86 assembly (clang, -O0):
<mpack_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     11b8 <mpack_encode+0x58>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x5c,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     11e0 <mpack_encode+0x80>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     1208 <mpack_encode+0xa8>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1080 <md5digest@plt>
mov    0x18(%rbp),%rdi
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x18(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xddd(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x18(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xdd1(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xdc3(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x18(%rbp),%rsi
lea    0xdbe(%rip),%rdi
call   1050 <fputs@plt>
mov    0x18(%rbp),%rsi
lea    0xddb(%rip),%rdi
call   1050 <fputs@plt>
cmpq   $0x0,-0x18(%rbp)
je     12bf <mpack_encode+0x15f>
mov    0x18(%rbp),%rsi
lea    0xde3(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x18(%rbp),%rdi
mov    0x18(%rbp),%rsi
call   1050 <fputs@plt>
mov    0x18(%rbp),%rsi
mov    $0xa,%edi
call   1060 <fputc@plt>
mov    0x18(%rbp),%rsi
lea    0xe3f(%rip),%rdi
call   1050 <fputs@plt>
mov    0x18(%rbp),%rdi
mov    0x10(%rbp),%rdx
mov    -0x38(%rbp),%rcx
lea    0xda6(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x18(%rbp),%rsi
lea    0xdb1(%rip),%rdi
call   1050 <fputs@plt>
mov    0x18(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xdc0(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x18(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xdd6(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    0x18(%rbp),%rsi
call   1030 <to64@plt>
mov    0x18(%rbp),%rsi
lea    0xdc9(%rip),%rdi
call   1050 <fputs@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpack_encode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,%r14
mov    %r8,(%rsp)
mov    %rcx,0x8(%rsp)
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%r12
mov    0x78(%rsp),%r13
mov    %rsi,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
cmove  %rbp,%rbx
mov    %rbx,%rdi
mov    $0x5c,%esi
call   1040 <strrchr@plt>
lea    0x1(%rax),%rbp
test   %rax,%rax
cmove  %rbx,%rbp
mov    %r12,%rbx
mov    %rbp,%rdi
mov    $0x3a,%esi
call   1040 <strrchr@plt>
lea    0x1(%rax),%r12
test   %rax,%rax
cmove  %rbp,%r12
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <md5digest@plt>
lea    0xe09(%rip),%rdi
mov    $0x12,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1080 <fwrite@plt>
lea    0xe03(%rip),%rsi
mov    %r13,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xdf9(%rip),%rsi
mov    %r13,%rdi
mov    (%rsp),%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xdec(%rip),%rsi
mov    %r13,%rdi
mov    0x8(%rsp),%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xde3(%rip),%rdi
mov    $0x2c,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1080 <fwrite@plt>
lea    0xdf7(%rip),%rdi
mov    $0x22,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1080 <fwrite@plt>
test   %r15,%r15
je     12b0 <mpack_encode+0x140>
lea    0xdfc(%rip),%rdi
mov    $0x5,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1080 <fwrite@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1050 <fputs@plt>
mov    $0xa,%edi
mov    %r13,%rsi
call   1060 <fputc@plt>
lea    0xe52(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1080 <fwrite@plt>
lea    0xdb8(%rip),%rsi
mov    %r13,%rdi
mov    0x70(%rsp),%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xdbc(%rip),%rdi
mov    $0x22,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1080 <fwrite@plt>
lea    0xdc6(%rip),%rsi
mov    %r13,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xdde(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %r13,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <to64@plt>
lea    0xdcf(%rip),%rdi
mov    $0x7,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1080 <fwrite@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Mime-Version: 1.0\0A\00"
@.str.1 = [10 x i8] c"From: %s\0A\00"
@.str.2 = [8 x i8] c"To: %s\0A\00"
@.str.3 = [13 x i8] c"Subject: %s\0A\00"
@.str.4 = [45 x i8] c"Content-Type: multipart/mixed; boundary=\22-\22\0A\00"
@.str.5 = [35 x i8] c"\0AThis is a MIME encoded message.\0A\0A\00"
@.str.6 = [6 x i8] c"---\0A\0A\00"
@.str.7 = [5 x i8] c"---\0A\00"
@.str.8 = [29 x i8] c"Content-Type: %s; name=\22%s\22\0A\00"
@.str.9 = [35 x i8] c"Content-Transfer-Encoding: base64\0A\00"
@.str.10 = [44 x i8] c"Content-Disposition: inline; filename=\22%s\22\0A\00"
@.str.11 = [18 x i8] c"Content-MD5: %s\0A\0A\00"
@.str.12 = [8 x i8] c"\0A-----\0A\00"
define i32 @mpack_encode(i32* %0, i8* %1, i8* %2, i8* %3, i8* %4, i8* %5, i8* %6, i32* %7) {
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i32*
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca [25 x i8]
store i32* %0, i32** %9
store i8* %1, i8** %10
store i8* %2, i8** %11
store i8* %3, i8** %12
store i8* %4, i8** %13
store i8* %5, i8** %14
store i8* %6, i8** %15
store i32* %7, i32** %16
%20 = load i8*, i8** %10
store i8* %20, i8** %17
%21 = load i8*, i8** %17
%22 = call i8* @strrchr(i8* %21, i8 signext 47)
store i8* %22, i8** %18
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %27
24: ; preds = %8
%25 = load i8*, i8** %18
%26 = getelementptr inbounds i8, i8* %25, i64 1
store i8* %26, i8** %17
br label %27
27: ; preds = %24, %8
%28 = load i8*, i8** %17
%29 = call i8* @strrchr(i8* %28, i8 signext 92)
store i8* %29, i8** %18
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i8*, i8** %18
%33 = getelementptr inbounds i8, i8* %32, i64 1
store i8* %33, i8** %17
br label %34
34: ; preds = %31, %27
%35 = load i8*, i8** %17
%36 = call i8* @strrchr(i8* %35, i8 signext 58)
store i8* %36, i8** %18
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = load i8*, i8** %18
%40 = getelementptr inbounds i8, i8* %39, i64 1
store i8* %40, i8** %17
br label %41
41: ; preds = %38, %34
%42 = load i32*, i32** %9
%43 = getelementptr inbounds [25 x i8], [25 x i8]* %19, i64 0, i64 0
%44 = call i32 @md5digest(i32* %42, i8* %43)
%45 = load i32*, i32** %16
%46 = call i32 (i32*, i8*, ...) @fprintf(i32* %45, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%47 = load i32*, i32** %16
%48 = load i8*, i8** %14
%49 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %48)
%50 = load i32*, i32** %16
%51 = load i8*, i8** %13
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %51)
%53 = load i32*, i32** %16
%54 = load i8*, i8** %12
%55 = call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %54)
%56 = load i32*, i32** %16
%57 = call i32 @fputs(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i32* %56)
%58 = load i32*, i32** %16
%59 = call i32 @fputs(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32* %58)
%60 = load i8*, i8** %11
%61 = icmp ne i8* %60, null
br i1 %61, label %62, label %70
62: ; preds = %41
%63 = load i32*, i32** %16
%64 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32* %63)
%65 = load i8*, i8** %11
%66 = load i32*, i32** %16
%67 = call i32 @fputs(i8* %65, i32* %66)
%68 = load i32*, i32** %16
%69 = call i32 @fputc(i8 signext 10, i32* %68)
br label %70
70: ; preds = %62, %41
%71 = load i32*, i32** %16
%72 = call i32 @fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32* %71)
%73 = load i32*, i32** %16
%74 = load i8*, i8** %15
%75 = load i8*, i8** %17
%76 = call i32 (i32*, i8*, ...) @fprintf(i32* %73, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i8* %74, i8* %75)
%77 = load i32*, i32** %16
%78 = call i32 @fputs(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0), i32* %77)
%79 = load i32*, i32** %16
%80 = load i8*, i8** %17
%81 = call i32 (i32*, i8*, ...) @fprintf(i32* %79, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.10, i64 0, i64 0), i8* %80)
%82 = load i32*, i32** %16
%83 = getelementptr inbounds [25 x i8], [25 x i8]* %19, i64 0, i64 0
%84 = call i32 (i32*, i8*, ...) @fprintf(i32* %82, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0), i8* %83)
%85 = load i32*, i32** %9
%86 = load i32*, i32** %16
%87 = call i32 @to64(i32* %85, i32* %86)
%88 = load i32*, i32** %16
%89 = call i32 @fputs(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0), i32* %88)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"Mime-Version: 1.0\0A\00"
@.str.1 = [10 x i8] c"From: %s\0A\00"
@.str.2 = [8 x i8] c"To: %s\0A\00"
@.str.3 = [13 x i8] c"Subject: %s\0A\00"
@.str.4 = [45 x i8] c"Content-Type: multipart/mixed; boundary=\22-\22\0A\00"
@.str.5 = [35 x i8] c"\0AThis is a MIME encoded message.\0A\0A\00"
@.str.6 = [6 x i8] c"---\0A\0A\00"
@.str.7 = [5 x i8] c"---\0A\00"
@.str.8 = [29 x i8] c"Content-Type: %s; name=\22%s\22\0A\00"
@.str.9 = [35 x i8] c"Content-Transfer-Encoding: base64\0A\00"
@.str.10 = [44 x i8] c"Content-Disposition: inline; filename=\22%s\22\0A\00"
@.str.11 = [18 x i8] c"Content-MD5: %s\0A\0A\00"
@.str.12 = [8 x i8] c"\0A-----\0A\00"
define i32 @mpack_encode(i32* %0, i8* %1, i8* %2, i8* %3, i8* %4, i8* %5, i8* %6, i32* %7) {
%9 = alloca [25 x i8]
%10 = getelementptr inbounds [25 x i8], [25 x i8]* %9, i64 0, i64 0
%11 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 47)
%12 = icmp eq i8* %11, null
%13 = getelementptr inbounds i8, i8* %11, i64 1
%14 = select i1 %12, i8* %1, i8* %13
%15 = tail call i8* @strrchr(i8* dereferenceable(1) %14, i8 signext 92)
%16 = icmp eq i8* %15, null
%17 = getelementptr inbounds i8, i8* %15, i64 1
%18 = select i1 %16, i8* %14, i8* %17
%19 = tail call i8* @strrchr(i8* dereferenceable(1) %18, i8 signext 58)
%20 = icmp eq i8* %19, null
%21 = getelementptr inbounds i8, i8* %19, i64 1
%22 = select i1 %20, i8* %18, i8* %21
%23 = call i32 @md5digest(i32* %0, i8* %10)
%24 = call i64 @fwrite(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 18, i64 1, i32* %7)
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%28 = call i64 @fwrite(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i64 44, i64 1, i32* %7)
%29 = call i64 @fwrite(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i64 34, i64 1, i32* %7)
%30 = icmp eq i8* %2, null
br i1 %30, label %35, label %31
31: ; preds = %8
%32 = call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i64 5, i64 1, i32* %7)
%33 = call i32 @fputs(i8* %2, i32* %7)
%34 = call i32 @fputc(i8 signext 10, i32* %7)
br label %35
35: ; preds = %31, %8
%36 = call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i64 4, i64 1, i32* %7)
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i8* %6, i8* %22)
%38 = call i64 @fwrite(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0), i64 34, i64 1, i32* %7)
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.10, i64 0, i64 0), i8* %22)
%40 = call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0), i8* %10)
%41 = call i32 @to64(i32* %0, i32* %7)
%42 = call i64 @fwrite(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0), i64 7, i64 1, i32* %7)
ret i32 0
}