#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_CMS(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                     int /*<<< orphan*/, int /*<<< orphan*/ *);
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*/ 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, *dcont = 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.pem", "r");
  if (!in)
    goto err;
  cms = PEM_read_bio_CMS(in, NULL, 0, NULL);
  if (!cms)
    goto err;
  dcont = BIO_new_file("smencr.out", "rb");
  if (!in)
    goto err;
  out = BIO_new_file("encrout.txt", "w");
  if (!out)
    goto err;
  if (!CMS_decrypt(cms, rkey, rcert, dcont, out, 0))
    goto err;
  ret = 0;
err:
  if (ret) {
    fprintf(stderr, "Error Decrypting Data\n");
    ERR_print_errors_fp(stderr);
  }
  CMS_ContentInfo_free(cms);
  X509_free(rcert);
  EVP_PKEY_free(rkey);
  BIO_free(in);
  BIO_free(out);
  BIO_free(tbio);
  BIO_free(dcont);
  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)
movq   $0x0,-0x48(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    $0x0,%al
call   1070 <OpenSSL_add_all_algorithms@plt>
mov    $0x0,%al
call   10a0 <ERR_load_crypto_strings@plt>
lea    0xdb6(%rip),%rdi
lea    0xdba(%rip),%rsi
call   10f0 <BIO_new_file@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    126a <main+0x8a>
jmp    1386 <main+0x1a6>
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,-0x38(%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,-0x40(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     12b5 <main+0xd5>
cmpq   $0x0,-0x40(%rbp)
jne    12ba <main+0xda>
jmp    1386 <main+0x1a6>
lea    0xd4c(%rip),%rdi
lea    0xd43(%rip),%rsi
call   10f0 <BIO_new_file@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12e1 <main+0x101>
jmp    1386 <main+0x1a6>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
xor    %edx,%edx
mov    %rcx,%rsi
call   1040 <PEM_read_bio_CMS@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1307 <main+0x127>
jmp    1386 <main+0x1a6>
lea    0xd0a(%rip),%rdi
lea    0xd0e(%rip),%rsi
call   10f0 <BIO_new_file@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    132e <main+0x14e>
jmp    1386 <main+0x1a6>
lea    0xcf1(%rip),%rdi
lea    0xcf6(%rip),%rsi
call   10f0 <BIO_new_file@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1355 <main+0x175>
jmp    1386 <main+0x1a6>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%r8
xor    %r9d,%r9d
call   1030 <CMS_decrypt@plt>
cmp    $0x0,%eax
jne    137f <main+0x19f>
jmp    1386 <main+0x1a6>
movl   $0x0,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     13b3 <main+0x1d3>
mov    0x2c49(%rip),%rax
mov    (%rax),%edi
lea    0xc94(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2c34(%rip),%rax
mov    (%rax),%edi
call   10e0 <ERR_print_errors_fp@plt>
mov    -0x48(%rbp),%rdi
call   1100 <CMS_ContentInfo_free@plt>
mov    -0x38(%rbp),%rdi
call   1090 <X509_free@plt>
mov    -0x40(%rbp),%rdi
call   1050 <EVP_PKEY_free@plt>
mov    -0x18(%rbp),%rdi
call   1080 <BIO_free@plt>
mov    -0x20(%rbp),%rdi
call   1080 <BIO_free@plt>
mov    -0x28(%rbp),%rdi
call   1080 <BIO_free@plt>
mov    -0x30(%rbp),%rdi
call   1080 <BIO_free@plt>
mov    -0x4c(%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   10a0 <ERR_load_crypto_strings@plt>
lea    0xdfb(%rip),%rdi
lea    0xdff(%rip),%rsi
call   10f0 <BIO_new_file@plt>
mov    %rax,%r14
test   %rax,%rax
je     12f9 <main+0x119>
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   10d0 <PEM_read_bio_X509@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   10b0 <BIO_reset@plt>
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   10c0 <PEM_read_bio_PrivateKey@plt>
test   %r15,%r15
mov    %rax,0x10(%rsp)
je     1307 <main+0x127>
mov    %rax,%rbp
test   %rax,%rax
je     1307 <main+0x127>
lea    0xda6(%rip),%rdi
lea    0xd9d(%rip),%rsi
call   10f0 <BIO_new_file@plt>
test   %rax,%rax
je     1305 <main+0x125>
mov    %rax,%r12
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <PEM_read_bio_CMS@plt>
test   %rax,%rax
mov    %r12,0x8(%rsp)
je     138c <main+0x1ac>
mov    %rax,%rbx
lea    0xd73(%rip),%rdi
lea    0xd77(%rip),%rsi
call   10f0 <BIO_new_file@plt>
mov    %rax,%rbp
lea    0xd6b(%rip),%rdi
lea    0xd70(%rip),%rsi
call   10f0 <BIO_new_file@plt>
xor    %r13d,%r13d
test   %rax,%rax
mov    %rbp,(%rsp)
je     1394 <main+0x1b4>
mov    %rax,%r12
mov    %rbx,%rdi
mov    0x10(%rsp),%rsi
mov    %r15,%rdx
mov    %rbp,%rcx
mov    %rax,%r8
xor    %r9d,%r9d
call   1030 <CMS_decrypt@plt>
test   %eax,%eax
jne    133d <main+0x15d>
jmp    1317 <main+0x137>
xor    %eax,%eax
mov    %rax,0x10(%rsp)
xor    %r15d,%r15d
jmp    1307 <main+0x127>
xor    %ebx,%ebx
xor    %eax,%eax
mov    %rax,(%rsp)
xor    %r12d,%r12d
xor    %eax,%eax
mov    %rax,0x8(%rsp)
mov    0x2cc2(%rip),%r13
mov    0x0(%r13),%edi
lea    0xd0b(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x0(%r13),%edi
call   10e0 <ERR_print_errors_fp@plt>
mov    $0x1,%r13d
mov    %rbx,%rdi
call   1100 <CMS_ContentInfo_free@plt>
mov    %r15,%rdi
call   1090 <X509_free@plt>
mov    0x10(%rsp),%rdi
call   1050 <EVP_PKEY_free@plt>
mov    0x8(%rsp),%rdi
call   1080 <BIO_free@plt>
mov    %r12,%rdi
call   1080 <BIO_free@plt>
mov    %r14,%rdi
call   1080 <BIO_free@plt>
mov    (%rsp),%rdi
call   1080 <BIO_free@plt>
mov    %r13d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
mov    %rax,(%rsp)
xor    %ebx,%ebx
xor    %r12d,%r12d
jmp    1317 <main+0x137>

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.pem\00"
@.str.3 = [11 x i8] c"smencr.out\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [12 x i8] c"encrout.txt\00"
@.str.6 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.7 = [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*
%13 = 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* null, i32** %12
store i32 1, i32* %13
%14 = call i32 (...) @OpenSSL_add_all_algorithms()
%15 = call i32 (...) @ERR_load_crypto_strings()
%16 = 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* %16, i32** %8
%17 = load i32*, i32** %8
%18 = icmp ne i32* %17, null
br i1 %18, label %20, label %19
19: ; preds = %2
br label %64
20: ; preds = %2
%21 = load i32*, i32** %8
%22 = call i32* @PEM_read_bio_X509(i32* %21, i32* null, i32 0, i32* null)
store i32* %22, i32** %10
%23 = load i32*, i32** %8
%24 = call i32 @BIO_reset(i32* %23)
%25 = load i32*, i32** %8
%26 = call i32* @PEM_read_bio_PrivateKey(i32* %25, i32* null, i32 0, i32* null)
store i32* %26, i32** %11
%27 = load i32*, i32** %10
%28 = icmp ne i32* %27, null
br i1 %28, label %29, label %32
29: ; preds = %20
%30 = load i32*, i32** %11
%31 = icmp ne i32* %30, null
br i1 %31, label %33, label %32
32: ; preds = %29, %20
br label %64
33: ; preds = %29
%34 = 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* %34, i32** %6
%35 = load i32*, i32** %6
%36 = icmp ne i32* %35, null
br i1 %36, label %38, label %37
37: ; preds = %33
br label %64
38: ; preds = %33
%39 = load i32*, i32** %6
%40 = call i32* @PEM_read_bio_CMS(i32* %39, i32* null, i32 0, i32* null)
store i32* %40, i32** %12
%41 = load i32*, i32** %12
%42 = icmp ne i32* %41, null
br i1 %42, label %44, label %43
43: ; preds = %38
br label %64
44: ; preds = %38
%45 = call i32* @BIO_new_file(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %45, i32** %9
%46 = load i32*, i32** %6
%47 = icmp ne i32* %46, null
br i1 %47, label %49, label %48
48: ; preds = %44
br label %64
49: ; preds = %44
%50 = call i32* @BIO_new_file(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %50, i32** %7
%51 = load i32*, i32** %7
%52 = icmp ne i32* %51, null
br i1 %52, label %54, label %53
53: ; preds = %49
br label %64
54: ; preds = %49
%55 = load i32*, i32** %12
%56 = load i32*, i32** %11
%57 = load i32*, i32** %10
%58 = load i32*, i32** %9
%59 = load i32*, i32** %7
%60 = call i32 @CMS_decrypt(i32* %55, i32* %56, i32* %57, i32* %58, i32* %59, i32 0)
%61 = icmp ne i32 %60, 0
br i1 %61, label %63, label %62
62: ; preds = %54
br label %64
63: ; preds = %54
store i32 0, i32* %13
br label %64
64: ; preds = %63, %62, %53, %48, %43, %37, %32, %19
%65 = load i32, i32* %13
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %72
67: ; preds = %64
%68 = load i32, i32* @stderr
%69 = call i32 @fprintf(i32 %68, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%70 = load i32, i32* @stderr
%71 = call i32 @ERR_print_errors_fp(i32 %70)
br label %72
72: ; preds = %67, %64
%73 = load i32*, i32** %12
%74 = call i32 @CMS_ContentInfo_free(i32* %73)
%75 = load i32*, i32** %10
%76 = call i32 @X509_free(i32* %75)
%77 = load i32*, i32** %11
%78 = call i32 @EVP_PKEY_free(i32* %77)
%79 = load i32*, i32** %6
%80 = call i32 @BIO_free(i32* %79)
%81 = load i32*, i32** %7
%82 = call i32 @BIO_free(i32* %81)
%83 = load i32*, i32** %8
%84 = call i32 @BIO_free(i32* %83)
%85 = load i32*, i32** %9
%86 = call i32 @BIO_free(i32* %85)
%87 = load i32, i32* %13
ret i32 %87
}

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.pem\00"
@.str.3 = [11 x i8] c"smencr.out\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [12 x i8] c"encrout.txt\00"
@.str.6 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.7 = [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 %27, 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 %27
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 %27, label %17
17: ; preds = %14
%18 = tail call i32* @PEM_read_bio_CMS(i32* %15, i32* null, i32 0, i32* null)
%19 = icmp eq i32* %18, null
br i1 %19, label %27, 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 ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%22 = tail call i32* @BIO_new_file(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %27, label %24
24: ; preds = %20
%25 = tail call i32 @CMS_decrypt(i32* %18, i32* %10, i32* %8, i32* %21, i32* %22, i32 0)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %38
27: ; preds = %2, %7, %14, %17, %20, %24
%28 = phi i32* [ %18, %24 ], [ %18, %20 ], [ null, %17 ], [ null, %14 ], [ null, %7 ], [ null, %2 ]
%29 = phi i32* [ %10, %24 ], [ %10, %20 ], [ %10, %17 ], [ %10, %14 ], [ %10, %7 ], [ null, %2 ]
%30 = phi i32* [ %8, %24 ], [ %8, %20 ], [ %8, %17 ], [ %8, %14 ], [ %8, %7 ], [ null, %2 ]
%31 = phi i32* [ %21, %24 ], [ %21, %20 ], [ null, %17 ], [ null, %14 ], [ null, %7 ], [ null, %2 ]
%32 = phi i32* [ %22, %24 ], [ null, %20 ], [ null, %17 ], [ null, %14 ], [ null, %7 ], [ null, %2 ]
%33 = phi i32* [ %15, %24 ], [ %15, %20 ], [ %15, %17 ], [ null, %14 ], [ null, %7 ], [ null, %2 ]
%34 = load i32, i32* @stderr
%35 = tail call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%36 = load i32, i32* @stderr
%37 = tail call i32 @ERR_print_errors_fp(i32 %36)
br label %38
38: ; preds = %27, %24
%39 = phi i32 [ 1, %27 ], [ 0, %24 ]
%40 = phi i32* [ %28, %27 ], [ %18, %24 ]
%41 = phi i32* [ %29, %27 ], [ %10, %24 ]
%42 = phi i32* [ %30, %27 ], [ %8, %24 ]
%43 = phi i32* [ %31, %27 ], [ %21, %24 ]
%44 = phi i32* [ %32, %27 ], [ %22, %24 ]
%45 = phi i32* [ %33, %27 ], [ %15, %24 ]
%46 = tail call i32 @CMS_ContentInfo_free(i32* %40)
%47 = tail call i32 @X509_free(i32* %42)
%48 = tail call i32 @EVP_PKEY_free(i32* %41)
%49 = tail call i32 @BIO_free(i32* %45)
%50 = tail call i32 @BIO_free(i32* %44)
%51 = tail call i32 @BIO_free(i32* %5)
%52 = tail call i32 @BIO_free(i32* %43)
ret i32 %39
}