#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);
  }
  if (p7)
    PKCS7_free(p7);
  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   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>
cmpq   $0x0,-0x40(%rbp)
je     138f <main+0x1af>
mov    -0x40(%rbp),%rdi
call   1080 <PKCS7_free@plt>
cmpq   $0x0,-0x30(%rbp)
je     13a3 <main+0x1c3>
mov    -0x30(%rbp),%rdi
call   10a0 <X509_free@plt>
cmpq   $0x0,-0x38(%rbp)
je     13b7 <main+0x1d7>
mov    -0x38(%rbp),%rdi
call   1050 <EVP_PKEY_free@plt>
cmpq   $0x0,-0x18(%rbp)
je     13cb <main+0x1eb>
mov    -0x18(%rbp),%rdi
call   1090 <BIO_free@plt>
cmpq   $0x0,-0x20(%rbp)
je     13df <main+0x1ff>
mov    -0x20(%rbp),%rdi
call   1090 <BIO_free@plt>
cmpq   $0x0,-0x28(%rbp)
je     13f3 <main+0x213>
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
push   %rax
xor    %r12d,%r12d
xor    %eax,%eax
call   1070 <OpenSSL_add_all_algorithms@plt>
xor    %eax,%eax
call   10b0 <ERR_load_crypto_strings@plt>
lea    0xdfd(%rip),%rdi
lea    0xe01(%rip),%rsi
call   1100 <BIO_new_file@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12c7 <main+0xe7>
xor    %r12d,%r12d
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   10e0 <PEM_read_bio_X509@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   10c0 <BIO_reset@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   10d0 <PEM_read_bio_PrivateKey@plt>
test   %r14,%r14
mov    %rax,(%rsp)
je     12d5 <main+0xf5>
test   %rax,%rax
je     12d5 <main+0xf5>
lea    0xdaf(%rip),%rdi
lea    0xda6(%rip),%rsi
call   1100 <BIO_new_file@plt>
test   %rax,%rax
je     12d2 <main+0xf2>
mov    %rax,%r13
xor    %r15d,%r15d
mov    %rax,%rdi
xor    %esi,%esi
call   1030 <SMIME_read_PKCS7@plt>
test   %rax,%rax
je     135e <main+0x17e>
mov    %rax,%r12
lea    0xd86(%rip),%rdi
lea    0xd8b(%rip),%rsi
call   1100 <BIO_new_file@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1366 <main+0x186>
mov    %rax,%r15
mov    %r12,%rdi
mov    (%rsp),%rsi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %r8d,%r8d
call   1040 <PKCS7_decrypt@plt>
test   %eax,%eax
jne    1303 <main+0x123>
jmp    12db <main+0xfb>
xor    %eax,%eax
mov    %rax,(%rsp)
xor    %r14d,%r14d
jmp    12d5 <main+0xf5>
xor    %r12d,%r12d
xor    %r15d,%r15d
xor    %r13d,%r13d
mov    0x2cfe(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xd3a(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
call   10f0 <ERR_print_errors_fp@plt>
mov    $0x1,%ebp
test   %r12,%r12
je     130b <main+0x12b>
mov    %r12,%rdi
call   1080 <PKCS7_free@plt>
test   %r14,%r14
je     1318 <main+0x138>
mov    %r14,%rdi
call   10a0 <X509_free@plt>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     1326 <main+0x146>
call   1050 <EVP_PKEY_free@plt>
test   %r13,%r13
je     1333 <main+0x153>
mov    %r13,%rdi
call   1090 <BIO_free@plt>
test   %r15,%r15
je     1340 <main+0x160>
mov    %r15,%rdi
call   1090 <BIO_free@plt>
test   %rbx,%rbx
je     134d <main+0x16d>
mov    %rbx,%rdi
call   1090 <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 = [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 = icmp ne i32* %66, null
br i1 %67, label %68, label %71
68: ; preds = %65
%69 = load i32*, i32** %11
%70 = call i32 @PKCS7_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 = [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 %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 ([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)
%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 @PKCS7_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
}