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

/* Variables and functions */
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new_file(char *, char *);
int /*<<< orphan*/ ERR_load_crypto_strings();
int /*<<< orphan*/ ERR_print_errors_fp(int /*<<< orphan*/);
int /*<<< orphan*/ OpenSSL_add_all_algorithms();
int /*<<< orphan*/ *PEM_read_bio_X509(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *, int /*<<< orphan*/,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ PKCS7_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ PKCS7_verify(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ *SMIME_read_PKCS7(int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ **);
int /*<<< orphan*/ X509_STORE_add_cert(int /*<<< orphan*/ *,
                                       int /*<<< orphan*/ *);
int /*<<< orphan*/ *X509_STORE_new();
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, *cont = NULL;
  X509_STORE *st = NULL;
  X509 *cacert = NULL;
  PKCS7 *p7 = NULL;
  int ret = 1;
  OpenSSL_add_all_algorithms();
  ERR_load_crypto_strings();
  st = X509_STORE_new();
  tbio = BIO_new_file("cacert.pem", "r");
  if (!tbio)
    goto err;
  cacert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
  if (!cacert)
    goto err;
  if (!X509_STORE_add_cert(st, cacert))
    goto err;
  in = BIO_new_file("smout.txt", "r");
  if (!in)
    goto err;
  p7 = SMIME_read_PKCS7(in, &cont);
  if (!p7)
    goto err;
  out = BIO_new_file("smver.txt", "w");
  if (!out)
    goto err;
  if (!PKCS7_verify(p7, NULL, st, cont, out, 0)) {
    fprintf(stderr, "Verification Failure\n");
    goto err;
  }
  fprintf(stderr, "Verification Successful\n");
  ret = 0;
err:
  if (ret) {
    fprintf(stderr, "Error Verifying Data\n");
    ERR_print_errors_fp(stderr);
  }
  PKCS7_free(p7);
  X509_free(cacert);
  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)
movq   $0x0,-0x48(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    $0x0,%al
call   1060 <OpenSSL_add_all_algorithms@plt>
mov    $0x0,%al
call   10c0 <ERR_load_crypto_strings@plt>
mov    $0x0,%al
call   10a0 <X509_STORE_new@plt>
mov    %rax,-0x38(%rbp)
lea    0xdbb(%rip),%rdi
lea    0xdbf(%rip),%rsi
call   10f0 <BIO_new_file@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1265 <main+0x95>
jmp    1370 <main+0x1a0>
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,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    128b <main+0xbb>
jmp    1370 <main+0x1a0>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1080 <X509_STORE_add_cert@plt>
cmp    $0x0,%eax
jne    12a6 <main+0xd6>
jmp    1370 <main+0x1a0>
lea    0xd60(%rip),%rdi
lea    0xd57(%rip),%rsi
call   10f0 <BIO_new_file@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12cd <main+0xfd>
jmp    1370 <main+0x1a0>
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <SMIME_read_PKCS7@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    12ee <main+0x11e>
jmp    1370 <main+0x1a0>
lea    0xd22(%rip),%rdi
lea    0xd25(%rip),%rsi
call   10f0 <BIO_new_file@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1315 <main+0x145>
jmp    1370 <main+0x1a0>
mov    -0x48(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%r8
xor    %eax,%eax
mov    %eax,%esi
xor    %r9d,%r9d
call   1030 <PKCS7_verify@plt>
cmp    $0x0,%eax
jne    1354 <main+0x184>
mov    0x2c9f(%rip),%rax
mov    (%rax),%edi
lea    0xcd9(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1370 <main+0x1a0>
mov    0x2c85(%rip),%rax
mov    (%rax),%edi
lea    0xcd5(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     139d <main+0x1cd>
mov    0x2c5f(%rip),%rax
mov    (%rax),%edi
lea    0xcc8(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2c4a(%rip),%rax
mov    (%rax),%edi
call   10e0 <ERR_print_errors_fp@plt>
mov    -0x48(%rbp),%rdi
call   1070 <PKCS7_free@plt>
mov    -0x40(%rbp),%rdi
call   10b0 <X509_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    -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
movq   $0x0,0x8(%rsp)
xor    %r15d,%r15d
xor    %eax,%eax
call   1060 <OpenSSL_add_all_algorithms@plt>
xor    %eax,%eax
call   10c0 <ERR_load_crypto_strings@plt>
xor    %eax,%eax
call   10a0 <X509_STORE_new@plt>
mov    %rax,%rbp
lea    0xdf7(%rip),%rdi
lea    0xdfb(%rip),%rsi
call   10f0 <BIO_new_file@plt>
test   %rax,%rax
mov    %rax,0x10(%rsp)
je     12ec <main+0x11c>
xor    %r15d,%r15d
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   10d0 <PEM_read_bio_X509@plt>
mov    $0x0,%r12d
mov    $0x0,%ebx
mov    $0x0,%r13d
test   %rax,%rax
je     12ff <main+0x12f>
mov    %rax,%r14
mov    %rbp,%rdi
mov    %rax,%rsi
call   1080 <X509_STORE_add_cert@plt>
test   %eax,%eax
je     12f3 <main+0x123>
lea    0xda2(%rip),%rdi
lea    0xd99(%rip),%rsi
call   10f0 <BIO_new_file@plt>
test   %rax,%rax
je     12f3 <main+0x123>
mov    %rax,%r15
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1040 <SMIME_read_PKCS7@plt>
test   %rax,%rax
je     12f6 <main+0x126>
mov    %rax,%r13
lea    0xd7c(%rip),%rdi
lea    0xd7f(%rip),%rsi
call   10f0 <BIO_new_file@plt>
test   %rax,%rax
je     1360 <main+0x190>
mov    %rax,%r12
mov    0x8(%rsp),%rcx
mov    %rbp,%rdx
xor    %ebp,%ebp
mov    %r13,%rdi
xor    %esi,%esi
mov    %rax,%r8
xor    %r9d,%r9d
call   1030 <PKCS7_verify@plt>
mov    0x2d0c(%rip),%rcx
mov    (%rcx),%edi
test   %eax,%eax
je     1365 <main+0x195>
lea    0xd54(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1325 <main+0x155>
xor    %r12d,%r12d
xor    %ebx,%ebx
jmp    12fc <main+0x12c>
xor    %r15d,%r15d
xor    %r12d,%r12d
mov    %r14,%rbx
xor    %r13d,%r13d
mov    0x2cda(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xd42(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
call   10e0 <ERR_print_errors_fp@plt>
mov    $0x1,%ebp
mov    %rbx,%r14
mov    %r13,%rdi
call   1070 <PKCS7_free@plt>
mov    %r14,%rdi
call   10b0 <X509_free@plt>
mov    %r15,%rdi
call   1090 <BIO_free@plt>
mov    %r12,%rdi
call   1090 <BIO_free@plt>
mov    0x10(%rsp),%rdi
call   1090 <BIO_free@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r12d,%r12d
jmp    1371 <main+0x1a1>
lea    0xcb7(%rip),%rsi
call   1050 <fprintf@plt>
mov    %r14,%rbx
jmp    12ff <main+0x12f>

LLVM IR (-O0):
@.str = [11 x i8] c"cacert.pem\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"smout.txt\00"
@.str.3 = [10 x i8] c"smver.txt\00"
@.str.4 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.5 = [22 x i8] c"Verification Failure\0A\00"
@.str.6 = [25 x i8] c"Verification Successful\0A\00"
@.str.7 = [22 x i8] c"Error Verifying 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* (...) @X509_STORE_new()
store i32* %16, i32** %10
%17 = 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* %17, i32** %8
%18 = load i32*, i32** %8
%19 = icmp ne i32* %18, null
br i1 %19, label %21, label %20
20: ; preds = %2
br label %62
21: ; preds = %2
%22 = load i32*, i32** %8
%23 = call i32* @PEM_read_bio_X509(i32* %22, i32* null, i32 0, i32* null)
store i32* %23, i32** %11
%24 = load i32*, i32** %11
%25 = icmp ne i32* %24, null
br i1 %25, label %27, label %26
26: ; preds = %21
br label %62
27: ; preds = %21
%28 = load i32*, i32** %10
%29 = load i32*, i32** %11
%30 = call i32 @X509_STORE_add_cert(i32* %28, i32* %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %27
br label %62
33: ; preds = %27
%34 = call i32* @BIO_new_file(i8* getelementptr inbounds ([10 x i8], [10 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 %62
38: ; preds = %33
%39 = load i32*, i32** %6
%40 = call i32* @SMIME_read_PKCS7(i32* %39, i32** %9)
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 %62
44: ; preds = %38
%45 = call i32* @BIO_new_file(i8* getelementptr inbounds ([10 x i8], [10 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* %45, i32** %7
%46 = load i32*, i32** %7
%47 = icmp ne i32* %46, null
br i1 %47, label %49, label %48
48: ; preds = %44
br label %62
49: ; preds = %44
%50 = load i32*, i32** %12
%51 = load i32*, i32** %10
%52 = load i32*, i32** %9
%53 = load i32*, i32** %7
%54 = call i32 @PKCS7_verify(i32* %50, i32* null, i32* %51, i32* %52, i32* %53, i32 0)
%55 = icmp ne i32 %54, 0
br i1 %55, label %59, label %56
56: ; preds = %49
%57 = load i32, i32* @stderr
%58 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %62
59: ; preds = %49
%60 = load i32, i32* @stderr
%61 = call i32 @fprintf(i32 %60, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %13
br label %62
62: ; preds = %59, %56, %48, %43, %37, %32, %26, %20
%63 = load i32, i32* %13
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %70
65: ; preds = %62
%66 = load i32, i32* @stderr
%67 = call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%68 = load i32, i32* @stderr
%69 = call i32 @ERR_print_errors_fp(i32 %68)
br label %70
70: ; preds = %65, %62
%71 = load i32*, i32** %12
%72 = call i32 @PKCS7_free(i32* %71)
%73 = load i32*, i32** %11
%74 = call i32 @X509_free(i32* %73)
%75 = load i32*, i32** %6
%76 = call i32 @BIO_free(i32* %75)
%77 = load i32*, i32** %7
%78 = call i32 @BIO_free(i32* %77)
%79 = load i32*, i32** %8
%80 = call i32 @BIO_free(i32* %79)
%81 = load i32, i32* %13
ret i32 %81
}

LLVM IR (-O2):
@.str = [11 x i8] c"cacert.pem\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"smout.txt\00"
@.str.3 = [10 x i8] c"smver.txt\00"
@.str.4 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.5 = [22 x i8] c"Verification Failure\0A\00"
@.str.6 = [25 x i8] c"Verification Successful\0A\00"
@.str.7 = [22 x i8] c"Error Verifying Data\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
store i32* null, i32** %3
%5 = tail call i32 (...) @OpenSSL_add_all_algorithms()
%6 = tail call i32 (...) @ERR_load_crypto_strings()
%7 = tail call i32* (...) @X509_STORE_new()
%8 = 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))
%9 = icmp eq i32* %8, null
br i1 %9, label %34, label %10
10: ; preds = %2
%11 = tail call i32* @PEM_read_bio_X509(i32* %8, i32* null, i32 0, i32* null)
%12 = icmp eq i32* %11, null
br i1 %12, label %34, label %13
13: ; preds = %10
%14 = tail call i32 @X509_STORE_add_cert(i32* %7, i32* %11)
%15 = icmp eq i32 %14, 0
br i1 %15, label %34, label %16
16: ; preds = %13
%17 = tail call i32* @BIO_new_file(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %34, label %19
19: ; preds = %16
%20 = call i32* @SMIME_read_PKCS7(i32* %17, i32** %3)
%21 = icmp eq i32* %20, null
br i1 %21, label %34, label %22
22: ; preds = %19
%23 = call i32* @BIO_new_file(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %34, label %25
25: ; preds = %22
%26 = load i32*, i32** %3
%27 = call i32 @PKCS7_verify(i32* %20, i32* null, i32* %7, i32* %26, i32* %23, i32 0)
%28 = icmp eq i32 %27, 0
%29 = load i32, i32* @stderr
br i1 %28, label %30, label %32
30: ; preds = %25
%31 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %34
32: ; preds = %25
%33 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
br label %43
34: ; preds = %30, %22, %19, %16, %13, %10, %2
%35 = phi i32* [ null, %2 ], [ null, %10 ], [ null, %13 ], [ null, %16 ], [ %17, %19 ], [ %17, %22 ], [ %17, %30 ]
%36 = phi i32* [ null, %2 ], [ null, %10 ], [ null, %13 ], [ null, %16 ], [ null, %19 ], [ null, %22 ], [ %23, %30 ]
%37 = phi i32* [ null, %2 ], [ null, %10 ], [ %11, %13 ], [ %11, %16 ], [ %11, %19 ], [ %11, %22 ], [ %11, %30 ]
%38 = phi i32* [ null, %2 ], [ null, %10 ], [ null, %13 ], [ null, %16 ], [ null, %19 ], [ %20, %22 ], [ %20, %30 ]
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%41 = load i32, i32* @stderr
%42 = call i32 @ERR_print_errors_fp(i32 %41)
br label %43
43: ; preds = %32, %34
%44 = phi i32 [ 1, %34 ], [ 0, %32 ]
%45 = phi i32* [ %38, %34 ], [ %20, %32 ]
%46 = phi i32* [ %37, %34 ], [ %11, %32 ]
%47 = phi i32* [ %36, %34 ], [ %23, %32 ]
%48 = phi i32* [ %35, %34 ], [ %17, %32 ]
%49 = call i32 @PKCS7_free(i32* %45)
%50 = call i32 @X509_free(i32* %46)
%51 = call i32 @BIO_free(i32* %48)
%52 = call i32 @BIO_free(i32* %47)
%53 = call i32 @BIO_free(i32* %8)
ret i32 %44
}