#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*/ X509;
typedef int /*<<< orphan*/ PKCS7;
typedef int /*<<< orphan*/ EVP_PKEY;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new_file(char *, char *);
int /*<<< orphan*/ BIO_reset(int /*<<< orphan*/ *);
int /*<<< orphan*/ ERR_load_crypto_strings();
int /*<<< orphan*/ ERR_print_errors_fp(int /*<<< orphan*/);
int /*<<< orphan*/ EVP_PKEY_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ OpenSSL_add_all_algorithms();
int /*<<< orphan*/ *PEM_read_bio_PrivateKey(int /*<<< orphan*/ *,
                                            int /*<<< orphan*/ *,
                                            int /*<<< orphan*/,
                                            int /*<<< orphan*/ *);
int /*<<< orphan*/ *PEM_read_bio_X509(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *, int /*<<< orphan*/,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ PKCS7_decrypt(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                 int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                 int /*<<< orphan*/);
int /*<<< orphan*/ PKCS7_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *SMIME_read_PKCS7(int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  BIO *in = NULL, *out = NULL, *tbio = NULL;
  X509 *rcert = NULL;
  EVP_PKEY *rkey = NULL;
  PKCS7 *p7 = NULL;
  int ret = 1;
  OpenSSL_add_all_algorithms();
  ERR_load_crypto_strings();
  tbio = BIO_new_file("signer.pem", "r");
  if (!tbio)
    goto err;
  rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
  BIO_reset(tbio);
  rkey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
  if (!rcert || !rkey)
    goto err;
  in = BIO_new_file("smencr.txt", "r");
  if (!in)
    goto err;
  p7 = SMIME_read_PKCS7(in, NULL);
  if (!p7)
    goto err;
  out = BIO_new_file("encrout.txt", "w");
  if (!out)
    goto err;
  if (!PKCS7_decrypt(p7, rkey, rcert, out, 0))
    goto err;
  ret = 0;
err:
  if (ret) {
    fprintf(stderr, "Error Signing Data\n");
    ERR_print_errors_fp(stderr);
  }
  PKCS7_free(p7);
  X509_free(rcert);
  EVP_PKEY_free(rkey);
  BIO_free(in);
  BIO_free(out);
  BIO_free(tbio);
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movl   $0x1,-0x44(%rbp)
mov    $0x0,%al
call   1070 <OpenSSL_add_all_algorithms@plt>
mov    $0x0,%al
call   10b0 <ERR_load_crypto_strings@plt>
lea    0xdbe(%rip),%rdi
lea    0xdc2(%rip),%rsi
call   1100 <BIO_new_file@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1262 <main+0x82>
jmp    134e <main+0x16e>
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
xor    %edx,%edx
mov    %rcx,%rsi
call   10e0 <PEM_read_bio_X509@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   10c0 <BIO_reset@plt>
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
xor    %edx,%edx
mov    %rcx,%rsi
call   10d0 <PEM_read_bio_PrivateKey@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12ad <main+0xcd>
cmpq   $0x0,-0x38(%rbp)
jne    12b2 <main+0xd2>
jmp    134e <main+0x16e>
lea    0xd54(%rip),%rdi
lea    0xd4b(%rip),%rsi
call   1100 <BIO_new_file@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12d9 <main+0xf9>
jmp    134e <main+0x16e>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <SMIME_read_PKCS7@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    12fa <main+0x11a>
jmp    134e <main+0x16e>
lea    0xd17(%rip),%rdi
lea    0xd1c(%rip),%rsi
call   1100 <BIO_new_file@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1321 <main+0x141>
jmp    134e <main+0x16e>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rcx
xor    %r8d,%r8d
call   1040 <PKCS7_decrypt@plt>
cmp    $0x0,%eax
jne    1347 <main+0x167>
jmp    134e <main+0x16e>
movl   $0x0,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     137b <main+0x19b>
mov    0x2c81(%rip),%rax
mov    (%rax),%edi
lea    0xcbe(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2c6c(%rip),%rax
mov    (%rax),%edi
call   10f0 <ERR_print_errors_fp@plt>
mov    -0x40(%rbp),%rdi
call   1080 <PKCS7_free@plt>
mov    -0x30(%rbp),%rdi
call   10a0 <X509_free@plt>
mov    -0x38(%rbp),%rdi
call   1050 <EVP_PKEY_free@plt>
mov    -0x18(%rbp),%rdi
call   1090 <BIO_free@plt>
mov    -0x20(%rbp),%rdi
call   1090 <BIO_free@plt>
mov    -0x28(%rbp),%rdi
call   1090 <BIO_free@plt>
mov    -0x44(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <OpenSSL_add_all_algorithms@plt>
xor    %eax,%eax
call   10b0 <ERR_load_crypto_strings@plt>
lea    0xdfb(%rip),%rdi
lea    0xdff(%rip),%rsi
call   1100 <BIO_new_file@plt>
mov    %rax,%r14
test   %rax,%rax
je     12cd <main+0xed>
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   10e0 <PEM_read_bio_X509@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   10c0 <BIO_reset@plt>
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   10d0 <PEM_read_bio_PrivateKey@plt>
test   %r15,%r15
mov    %rax,0x10(%rsp)
je     12db <main+0xfb>
mov    %rax,%rbp
test   %rax,%rax
je     12db <main+0xfb>
lea    0xdaa(%rip),%rdi
lea    0xda1(%rip),%rsi
call   1100 <BIO_new_file@plt>
test   %rax,%rax
je     12d9 <main+0xf9>
mov    %rax,%r13
mov    %rax,%rdi
xor    %esi,%esi
call   1030 <SMIME_read_PKCS7@plt>
test   %rax,%rax
je     1351 <main+0x171>
mov    %rax,%rbx
lea    0xd84(%rip),%rdi
lea    0xd89(%rip),%rsi
call   1100 <BIO_new_file@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     135c <main+0x17c>
mov    %rbx,%rdi
mov    0x10(%rsp),%rsi
mov    %r15,%rdx
mov    %rax,%rcx
mov    %rax,0x8(%rsp)
xor    %r8d,%r8d
call   1040 <PKCS7_decrypt@plt>
test   %eax,%eax
jne    130b <main+0x12b>
jmp    12e5 <main+0x105>
xor    %eax,%eax
mov    %rax,0x10(%rsp)
xor    %r15d,%r15d
jmp    12db <main+0xfb>
xor    %ebx,%ebx
xor    %eax,%eax
mov    %rax,0x8(%rsp)
xor    %r13d,%r13d
mov    0x2cf4(%rip),%r12
mov    (%r12),%edi
lea    0xd2f(%rip),%rsi
call   1060 <fprintf@plt>
mov    (%r12),%edi
call   10f0 <ERR_print_errors_fp@plt>
mov    $0x1,%r12d
mov    %rbx,%rdi
call   1080 <PKCS7_free@plt>
mov    %r15,%rdi
call   10a0 <X509_free@plt>
mov    0x10(%rsp),%rdi
call   1050 <EVP_PKEY_free@plt>
mov    %r13,%rdi
call   1090 <BIO_free@plt>
mov    0x8(%rsp),%rdi
call   1090 <BIO_free@plt>
mov    %r14,%rdi
call   1090 <BIO_free@plt>
mov    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
mov    %rax,0x8(%rsp)
xor    %ebx,%ebx
jmp    12e5 <main+0x105>
xor    %eax,%eax
mov    %rax,0x8(%rsp)
jmp    12e5 <main+0x105>

LLVM IR (-O0):
@.str = [11 x i8] c"signer.pem\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"smencr.txt\00"
@.str.3 = [12 x i8] c"encrout.txt\00"
@.str.4 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.5 = [20 x i8] c"Error Signing Data\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i32* null, i32** %7
store i32* null, i32** %8
store i32* null, i32** %9
store i32* null, i32** %10
store i32* null, i32** %11
store i32 1, i32* %12
%13 = call i32 (...) @OpenSSL_add_all_algorithms()
%14 = call i32 (...) @ERR_load_crypto_strings()
%15 = call i32* @BIO_new_file(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %8
%16 = load i32*, i32** %8
%17 = icmp ne i32* %16, null
br i1 %17, label %19, label %18
18: ; preds = %2
br label %57
19: ; preds = %2
%20 = load i32*, i32** %8
%21 = call i32* @PEM_read_bio_X509(i32* %20, i32* null, i32 0, i32* null)
store i32* %21, i32** %9
%22 = load i32*, i32** %8
%23 = call i32 @BIO_reset(i32* %22)
%24 = load i32*, i32** %8
%25 = call i32* @PEM_read_bio_PrivateKey(i32* %24, i32* null, i32 0, i32* null)
store i32* %25, i32** %10
%26 = load i32*, i32** %9
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %19
%29 = load i32*, i32** %10
%30 = icmp ne i32* %29, null
br i1 %30, label %32, label %31
31: ; preds = %28, %19
br label %57
32: ; preds = %28
%33 = call i32* @BIO_new_file(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %33, i32** %6
%34 = load i32*, i32** %6
%35 = icmp ne i32* %34, null
br i1 %35, label %37, label %36
36: ; preds = %32
br label %57
37: ; preds = %32
%38 = load i32*, i32** %6
%39 = call i32* @SMIME_read_PKCS7(i32* %38, i32* null)
store i32* %39, i32** %11
%40 = load i32*, i32** %11
%41 = icmp ne i32* %40, null
br i1 %41, label %43, label %42
42: ; preds = %37
br label %57
43: ; preds = %37
%44 = call i32* @BIO_new_file(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %44, i32** %7
%45 = load i32*, i32** %7
%46 = icmp ne i32* %45, null
br i1 %46, label %48, label %47
47: ; preds = %43
br label %57
48: ; preds = %43
%49 = load i32*, i32** %11
%50 = load i32*, i32** %10
%51 = load i32*, i32** %9
%52 = load i32*, i32** %7
%53 = call i32 @PKCS7_decrypt(i32* %49, i32* %50, i32* %51, i32* %52, i32 0)
%54 = icmp ne i32 %53, 0
br i1 %54, label %56, label %55
55: ; preds = %48
br label %57
56: ; preds = %48
store i32 0, i32* %12
br label %57
57: ; preds = %56, %55, %47, %42, %36, %31, %18
%58 = load i32, i32* %12
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %65
60: ; preds = %57
%61 = load i32, i32* @stderr
%62 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%63 = load i32, i32* @stderr
%64 = call i32 @ERR_print_errors_fp(i32 %63)
br label %65
65: ; preds = %60, %57
%66 = load i32*, i32** %11
%67 = call i32 @PKCS7_free(i32* %66)
%68 = load i32*, i32** %9
%69 = call i32 @X509_free(i32* %68)
%70 = load i32*, i32** %10
%71 = call i32 @EVP_PKEY_free(i32* %70)
%72 = load i32*, i32** %6
%73 = call i32 @BIO_free(i32* %72)
%74 = load i32*, i32** %7
%75 = call i32 @BIO_free(i32* %74)
%76 = load i32*, i32** %8
%77 = call i32 @BIO_free(i32* %76)
%78 = load i32, i32* %12
ret i32 %78
}

LLVM IR (-O2):
@.str = [11 x i8] c"signer.pem\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"smencr.txt\00"
@.str.3 = [12 x i8] c"encrout.txt\00"
@.str.4 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.5 = [20 x i8] c"Error Signing Data\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @OpenSSL_add_all_algorithms()
%4 = tail call i32 (...) @ERR_load_crypto_strings()
%5 = tail call i32* @BIO_new_file(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %26, label %7
7: ; preds = %2
%8 = tail call i32* @PEM_read_bio_X509(i32* %5, i32* null, i32 0, i32* null)
%9 = tail call i32 @BIO_reset(i32* %5)
%10 = tail call i32* @PEM_read_bio_PrivateKey(i32* %5, i32* null, i32 0, i32* null)
%11 = icmp ne i32* %8, null
%12 = icmp ne i32* %10, null
%13 = select i1 %11, i1 %12, i1 false
br i1 %13, label %14, label %26
14: ; preds = %7
%15 = tail call i32* @BIO_new_file(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %26, label %17
17: ; preds = %14
%18 = tail call i32* @SMIME_read_PKCS7(i32* %15, i32* null)
%19 = icmp eq i32* %18, null
br i1 %19, label %26, label %20
20: ; preds = %17
%21 = tail call i32* @BIO_new_file(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = tail call i32 @PKCS7_decrypt(i32* %18, i32* %10, i32* %8, i32* %21, i32 0)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %36
26: ; preds = %2, %7, %14, %17, %20, %23
%27 = phi i32* [ %18, %23 ], [ %18, %20 ], [ null, %17 ], [ null, %14 ], [ null, %7 ], [ null, %2 ]
%28 = phi i32* [ %10, %23 ], [ %10, %20 ], [ %10, %17 ], [ %10, %14 ], [ %10, %7 ], [ null, %2 ]
%29 = phi i32* [ %8, %23 ], [ %8, %20 ], [ %8, %17 ], [ %8, %14 ], [ %8, %7 ], [ null, %2 ]
%30 = phi i32* [ %21, %23 ], [ null, %20 ], [ null, %17 ], [ null, %14 ], [ null, %7 ], [ null, %2 ]
%31 = phi i32* [ %15, %23 ], [ %15, %20 ], [ %15, %17 ], [ null, %14 ], [ null, %7 ], [ null, %2 ]
%32 = load i32, i32* @stderr
%33 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%34 = load i32, i32* @stderr
%35 = tail call i32 @ERR_print_errors_fp(i32 %34)
br label %36
36: ; preds = %26, %23
%37 = phi i32 [ 1, %26 ], [ 0, %23 ]
%38 = phi i32* [ %27, %26 ], [ %18, %23 ]
%39 = phi i32* [ %28, %26 ], [ %10, %23 ]
%40 = phi i32* [ %29, %26 ], [ %8, %23 ]
%41 = phi i32* [ %30, %26 ], [ %21, %23 ]
%42 = phi i32* [ %31, %26 ], [ %15, %23 ]
%43 = tail call i32 @PKCS7_free(i32* %38)
%44 = tail call i32 @X509_free(i32* %40)
%45 = tail call i32 @EVP_PKEY_free(i32* %39)
%46 = tail call i32 @BIO_free(i32* %42)
%47 = tail call i32 @BIO_free(i32* %41)
%48 = tail call i32 @BIO_free(i32* %5)
ret i32 %37
}