#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*/ EVP_PKEY;
typedef int /*<<< orphan*/ CMS_ContentInfo;
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*/ CMS_ContentInfo_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ CMS_decrypt(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *, 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*/ *SMIME_read_CMS(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;
  CMS_ContentInfo *cms = 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;
  cms = SMIME_read_CMS(in, NULL);
  if (!cms)
    goto err;
  out = BIO_new_file("decout.txt", "w");
  if (!out)
    goto err;
  if (!CMS_decrypt(cms, rkey, rcert, NULL, out, 0))
    goto err;
  ret = 0;
err:
  if (ret) {
    fprintf(stderr, "Error Decrypting Data\n");
    ERR_print_errors_fp(stderr);
  }
  if (cms)
    CMS_ContentInfo_free(cms);
  if (rcert)
    X509_free(rcert);
  if (rkey)
    EVP_PKEY_free(rkey);
  if (in)
    BIO_free(in);
  if (out)
    BIO_free(out);
  if (tbio)
    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   10a0 <ERR_load_crypto_strings@plt>
lea    0xdbe(%rip),%rdi
lea    0xdc2(%rip),%rsi
call   10f0 <BIO_new_file@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1262 <main+0x82>
jmp    1352 <main+0x172>
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
xor    %edx,%edx
mov    %rcx,%rsi
call   10d0 <PEM_read_bio_X509@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   10b0 <BIO_reset@plt>
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
xor    %edx,%edx
mov    %rcx,%rsi
call   10c0 <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    1352 <main+0x172>
lea    0xd54(%rip),%rdi
lea    0xd4b(%rip),%rsi
call   10f0 <BIO_new_file@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12d9 <main+0xf9>
jmp    1352 <main+0x172>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <SMIME_read_CMS@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    12fa <main+0x11a>
jmp    1352 <main+0x172>
lea    0xd17(%rip),%rdi
lea    0xd1b(%rip),%rsi
call   10f0 <BIO_new_file@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1321 <main+0x141>
jmp    1352 <main+0x172>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%r8
xor    %eax,%eax
mov    %eax,%ecx
xor    %r9d,%r9d
call   1030 <CMS_decrypt@plt>
cmp    $0x0,%eax
jne    134b <main+0x16b>
jmp    1352 <main+0x172>
movl   $0x0,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     137f <main+0x19f>
mov    0x2c7d(%rip),%rax
mov    (%rax),%edi
lea    0xcb9(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2c68(%rip),%rax
mov    (%rax),%edi
call   10e0 <ERR_print_errors_fp@plt>
cmpq   $0x0,-0x40(%rbp)
je     1393 <main+0x1b3>
mov    -0x40(%rbp),%rdi
call   1100 <CMS_ContentInfo_free@plt>
cmpq   $0x0,-0x30(%rbp)
je     13a7 <main+0x1c7>
mov    -0x30(%rbp),%rdi
call   1090 <X509_free@plt>
cmpq   $0x0,-0x38(%rbp)
je     13bb <main+0x1db>
mov    -0x38(%rbp),%rdi
call   1050 <EVP_PKEY_free@plt>
cmpq   $0x0,-0x18(%rbp)
je     13cf <main+0x1ef>
mov    -0x18(%rbp),%rdi
call   1080 <BIO_free@plt>
cmpq   $0x0,-0x20(%rbp)
je     13e3 <main+0x203>
mov    -0x20(%rbp),%rdi
call   1080 <BIO_free@plt>
cmpq   $0x0,-0x28(%rbp)
je     13f7 <main+0x217>
mov    -0x28(%rbp),%rdi
call   1080 <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
push   %rax
xor    %r12d,%r12d
xor    %eax,%eax
call   1070 <OpenSSL_add_all_algorithms@plt>
xor    %eax,%eax
call   10a0 <ERR_load_crypto_strings@plt>
lea    0xdfd(%rip),%rdi
lea    0xe01(%rip),%rsi
call   10f0 <BIO_new_file@plt>
test   %rax,%rax
mov    %rax,(%rsp)
je     12cb <main+0xeb>
mov    %rax,%rbp
xor    %r12d,%r12d
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   10d0 <PEM_read_bio_X509@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   10b0 <BIO_reset@plt>
mov    %rbp,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   10c0 <PEM_read_bio_PrivateKey@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     12d5 <main+0xf5>
test   %r14,%r14
je     12d5 <main+0xf5>
lea    0xdac(%rip),%rdi
lea    0xda3(%rip),%rsi
call   10f0 <BIO_new_file@plt>
test   %rax,%rax
je     12d2 <main+0xf2>
mov    %rax,%r13
xor    %r15d,%r15d
mov    %rax,%rdi
xor    %esi,%esi
call   1040 <SMIME_read_CMS@plt>
test   %rax,%rax
je     1367 <main+0x187>
mov    %rax,%r12
lea    0xd83(%rip),%rdi
lea    0xd87(%rip),%rsi
call   10f0 <BIO_new_file@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     136f <main+0x18f>
mov    %rax,%r15
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
mov    %rax,%r8
xor    %r9d,%r9d
call   1030 <CMS_decrypt@plt>
test   %eax,%eax
jne    1309 <main+0x129>
jmp    12db <main+0xfb>
xor    %r14d,%r14d
xor    %ebx,%ebx
jmp    12d5 <main+0xf5>
xor    %r12d,%r12d
xor    %r15d,%r15d
xor    %r13d,%r13d
mov    %r14,%rbp
mov    0x2cfb(%rip),%r14
mov    (%r14),%edi
lea    0xd36(%rip),%rsi
call   1060 <fprintf@plt>
mov    (%r14),%edi
mov    %rbp,%r14
call   10e0 <ERR_print_errors_fp@plt>
mov    $0x1,%ebp
test   %r12,%r12
je     1311 <main+0x131>
mov    %r12,%rdi
call   1100 <CMS_ContentInfo_free@plt>
test   %rbx,%rbx
je     131e <main+0x13e>
mov    %rbx,%rdi
call   1090 <X509_free@plt>
test   %r14,%r14
je     132b <main+0x14b>
mov    %r14,%rdi
call   1050 <EVP_PKEY_free@plt>
test   %r13,%r13
mov    (%rsp),%rbx
je     133c <main+0x15c>
mov    %r13,%rdi
call   1080 <BIO_free@plt>
test   %r15,%r15
je     1349 <main+0x169>
mov    %r15,%rdi
call   1080 <BIO_free@plt>
test   %rbx,%rbx
je     1356 <main+0x176>
mov    %rbx,%rdi
call   1080 <BIO_free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r12d,%r12d
jmp    12db <main+0xfb>
xor    %r15d,%r15d
jmp    12db <main+0xfb>

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 = [11 x i8] c"decout.txt\00"
@.str.4 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.5 = [23 x i8] c"Error Decrypting 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_CMS(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 ([11 x i8], [11 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 @CMS_decrypt(i32* %49, i32* %50, i32* %51, i32* null, 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 ([23 x i8], [23 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 = icmp ne i32* %66, null
br i1 %67, label %68, label %71
68: ; preds = %65
%69 = load i32*, i32** %11
%70 = call i32 @CMS_ContentInfo_free(i32* %69)
br label %71
71: ; preds = %68, %65
%72 = load i32*, i32** %9
%73 = icmp ne i32* %72, null
br i1 %73, label %74, label %77
74: ; preds = %71
%75 = load i32*, i32** %9
%76 = call i32 @X509_free(i32* %75)
br label %77
77: ; preds = %74, %71
%78 = load i32*, i32** %10
%79 = icmp ne i32* %78, null
br i1 %79, label %80, label %83
80: ; preds = %77
%81 = load i32*, i32** %10
%82 = call i32 @EVP_PKEY_free(i32* %81)
br label %83
83: ; preds = %80, %77
%84 = load i32*, i32** %6
%85 = icmp ne i32* %84, null
br i1 %85, label %86, label %89
86: ; preds = %83
%87 = load i32*, i32** %6
%88 = call i32 @BIO_free(i32* %87)
br label %89
89: ; preds = %86, %83
%90 = load i32*, i32** %7
%91 = icmp ne i32* %90, null
br i1 %91, label %92, label %95
92: ; preds = %89
%93 = load i32*, i32** %7
%94 = call i32 @BIO_free(i32* %93)
br label %95
95: ; preds = %92, %89
%96 = load i32*, i32** %8
%97 = icmp ne i32* %96, null
br i1 %97, label %98, label %101
98: ; preds = %95
%99 = load i32*, i32** %8
%100 = call i32 @BIO_free(i32* %99)
br label %101
101: ; preds = %98, %95
%102 = load i32, i32* %12
ret i32 %102
}

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 = [11 x i8] c"decout.txt\00"
@.str.4 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.5 = [23 x i8] c"Error Decrypting 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_CMS(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 ([11 x i8], [11 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 @CMS_decrypt(i32* %18, i32* %10, i32* %8, i32* null, i32* %21, i32 0)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %37
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 ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%34 = load i32, i32* @stderr
%35 = tail call i32 @ERR_print_errors_fp(i32 %34)
%36 = icmp eq i32* %27, null
br i1 %36, label %45, label %37
37: ; preds = %23, %26
%38 = phi i32* [ %31, %26 ], [ %15, %23 ]
%39 = phi i32* [ %30, %26 ], [ %21, %23 ]
%40 = phi i32* [ %29, %26 ], [ %8, %23 ]
%41 = phi i32* [ %28, %26 ], [ %10, %23 ]
%42 = phi i32* [ %27, %26 ], [ %18, %23 ]
%43 = phi i32 [ 1, %26 ], [ 0, %23 ]
%44 = tail call i32 @CMS_ContentInfo_free(i32* %42)
br label %45
45: ; preds = %37, %26
%46 = phi i32* [ %38, %37 ], [ %31, %26 ]
%47 = phi i32* [ %39, %37 ], [ %30, %26 ]
%48 = phi i32* [ %40, %37 ], [ %29, %26 ]
%49 = phi i32* [ %41, %37 ], [ %28, %26 ]
%50 = phi i32 [ %43, %37 ], [ 1, %26 ]
%51 = icmp eq i32* %48, null
br i1 %51, label %54, label %52
52: ; preds = %45
%53 = tail call i32 @X509_free(i32* %48)
br label %54
54: ; preds = %52, %45
%55 = icmp eq i32* %49, null
br i1 %55, label %58, label %56
56: ; preds = %54
%57 = tail call i32 @EVP_PKEY_free(i32* %49)
br label %58
58: ; preds = %56, %54
%59 = icmp eq i32* %46, null
br i1 %59, label %62, label %60
60: ; preds = %58
%61 = tail call i32 @BIO_free(i32* %46)
br label %62
62: ; preds = %60, %58
%63 = icmp eq i32* %47, null
br i1 %63, label %66, label %64
64: ; preds = %62
%65 = tail call i32 @BIO_free(i32* %47)
br label %66
66: ; preds = %64, %62
br i1 %6, label %69, label %67
67: ; preds = %66
%68 = tail call i32 @BIO_free(i32* %5)
br label %69
69: ; preds = %67, %66
ret i32 %50
}