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

/* Variables and functions */
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new_file(char *, char *);
int /*<<< orphan*/ CMS_ContentInfo_free(int /*<<< orphan*/ *);
int CMS_STREAM;
int /*<<< orphan*/ *CMS_compress(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ ERR_load_crypto_strings();
int /*<<< orphan*/ ERR_print_errors_fp(int /*<<< orphan*/);
int /*<<< orphan*/ NID_zlib_compression;
int /*<<< orphan*/ OpenSSL_add_all_algorithms();
int /*<<< orphan*/ SMIME_write_CMS(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                   int /*<<< orphan*/ *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  BIO *in = NULL, *out = NULL;
  CMS_ContentInfo *cms = NULL;
  int ret = 1;
  int flags = CMS_STREAM;
  OpenSSL_add_all_algorithms();
  ERR_load_crypto_strings();
  in = BIO_new_file("comp.txt", "r");
  if (!in)
    goto err;
  cms = CMS_compress(in, NID_zlib_compression, flags);
  if (!cms)
    goto err;
  out = BIO_new_file("smcomp.txt", "w");
  if (!out)
    goto err;
  if (!SMIME_write_CMS(out, cms, in, flags))
    goto err;
  ret = 0;
err:
  if (ret) {
    fprintf(stderr, "Error Compressing Data\n");
    ERR_print_errors_fp(stderr);
  }
  if (cms)
    CMS_ContentInfo_free(cms);
  if (in)
    BIO_free(in);
  if (out)
    BIO_free(out);
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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)
movl   $0x1,-0x2c(%rbp)
mov    0x2e14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    $0x0,%al
call   1040 <OpenSSL_add_all_algorithms@plt>
mov    $0x0,%al
call   1080 <ERR_load_crypto_strings@plt>
lea    0xe1e(%rip),%rdi
lea    0xe13(%rip),%rsi
call   10a0 <BIO_new_file@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1206 <main+0x76>
jmp    127f <main+0xef>
mov    -0x18(%rbp),%rdi
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
mov    -0x30(%rbp),%edx
call   1070 <CMS_compress@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    122f <main+0x9f>
jmp    127f <main+0xef>
lea    0xdcc(%rip),%rdi
lea    0xdd0(%rip),%rsi
call   10a0 <BIO_new_file@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1256 <main+0xc6>
jmp    127f <main+0xef>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x30(%rbp),%ecx
call   1050 <SMIME_write_CMS@plt>
cmp    $0x0,%eax
jne    1278 <main+0xe8>
jmp    127f <main+0xef>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     12ac <main+0x11c>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
lea    0xd76(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
call   1090 <ERR_print_errors_fp@plt>
cmpq   $0x0,-0x28(%rbp)
je     12c0 <main+0x130>
mov    -0x28(%rbp),%rdi
call   10b0 <CMS_ContentInfo_free@plt>
cmpq   $0x0,-0x18(%rbp)
je     12d4 <main+0x144>
mov    -0x18(%rbp),%rdi
call   1060 <BIO_free@plt>
cmpq   $0x0,-0x20(%rbp)
je     12e8 <main+0x158>
mov    -0x20(%rbp),%rdi
call   1060 <BIO_free@plt>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e41(%rip),%rax
mov    (%rax),%ebp
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <OpenSSL_add_all_algorithms@plt>
xor    %eax,%eax
call   1080 <ERR_load_crypto_strings@plt>
lea    0xe4c(%rip),%rdi
lea    0xe41(%rip),%rsi
call   10a0 <BIO_new_file@plt>
mov    %rax,%r14
test   %rax,%rax
je     121d <main+0x8d>
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
mov    %ebp,%edx
call   1070 <CMS_compress@plt>
test   %rax,%rax
je     121b <main+0x8b>
mov    %rax,%rbx
lea    0xe14(%rip),%rdi
lea    0xe18(%rip),%rsi
call   10a0 <BIO_new_file@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     121d <main+0x8d>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1050 <SMIME_write_CMS@plt>
test   %eax,%eax
jne    1249 <main+0xb9>
jmp    1220 <main+0x90>
xor    %ebx,%ebx
xor    %r15d,%r15d
mov    0x2da9(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xdde(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x0(%rbp),%edi
call   1090 <ERR_print_errors_fp@plt>
mov    $0x1,%r12d
test   %rbx,%rbx
je     1251 <main+0xc1>
mov    %rbx,%rdi
call   10b0 <CMS_ContentInfo_free@plt>
test   %r14,%r14
je     125e <main+0xce>
mov    %r14,%rdi
call   1060 <BIO_free@plt>
test   %r15,%r15
je     126b <main+0xdb>
mov    %r15,%rdi
call   1060 <BIO_free@plt>
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CMS_STREAM = global i32 0
@.str = [9 x i8] c"comp.txt\00"
@.str.1 = [2 x i8] c"r\00"
@NID_zlib_compression = global i32 0
@.str.2 = [11 x i8] c"smcomp.txt\00"
@.str.3 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.4 = [24 x i8] c"Error Compressing 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
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 1, i32* %9
%11 = load i32, i32* @CMS_STREAM
store i32 %11, i32* %10
%12 = call i32 (...) @OpenSSL_add_all_algorithms()
%13 = call i32 (...) @ERR_load_crypto_strings()
%14 = call i32* @BIO_new_file(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = icmp ne i32* %15, null
br i1 %16, label %18, label %17
17: ; preds = %2
br label %40
18: ; preds = %2
%19 = load i32*, i32** %6
%20 = load i32, i32* @NID_zlib_compression
%21 = load i32, i32* %10
%22 = call i32* @CMS_compress(i32* %19, i32 %20, i32 %21)
store i32* %22, i32** %8
%23 = load i32*, i32** %8
%24 = icmp ne i32* %23, null
br i1 %24, label %26, label %25
25: ; preds = %18
br label %40
26: ; preds = %18
%27 = 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.3, i64 0, i64 0))
store i32* %27, i32** %7
%28 = load i32*, i32** %7
%29 = icmp ne i32* %28, null
br i1 %29, label %31, label %30
30: ; preds = %26
br label %40
31: ; preds = %26
%32 = load i32*, i32** %7
%33 = load i32*, i32** %8
%34 = load i32*, i32** %6
%35 = load i32, i32* %10
%36 = call i32 @SMIME_write_CMS(i32* %32, i32* %33, i32* %34, i32 %35)
%37 = icmp ne i32 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %31
br label %40
39: ; preds = %31
store i32 0, i32* %9
br label %40
40: ; preds = %39, %38, %30, %25, %17
%41 = load i32, i32* %9
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%46 = load i32, i32* @stderr
%47 = call i32 @ERR_print_errors_fp(i32 %46)
br label %48
48: ; preds = %43, %40
%49 = load i32*, i32** %8
%50 = icmp ne i32* %49, null
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = load i32*, i32** %8
%53 = call i32 @CMS_ContentInfo_free(i32* %52)
br label %54
54: ; preds = %51, %48
%55 = load i32*, i32** %6
%56 = icmp ne i32* %55, null
br i1 %56, label %57, label %60
57: ; preds = %54
%58 = load i32*, i32** %6
%59 = call i32 @BIO_free(i32* %58)
br label %60
60: ; preds = %57, %54
%61 = load i32*, i32** %7
%62 = icmp ne i32* %61, null
br i1 %62, label %63, label %66
63: ; preds = %60
%64 = load i32*, i32** %7
%65 = call i32 @BIO_free(i32* %64)
br label %66
66: ; preds = %63, %60
%67 = load i32, i32* %9
ret i32 %67
}

LLVM IR (-O2):
@CMS_STREAM = global i32 0
@.str = [9 x i8] c"comp.txt\00"
@.str.1 = [2 x i8] c"r\00"
@NID_zlib_compression = global i32 0
@.str.2 = [11 x i8] c"smcomp.txt\00"
@.str.3 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.4 = [24 x i8] c"Error Compressing Data\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @CMS_STREAM
%4 = tail call i32 (...) @OpenSSL_add_all_algorithms()
%5 = tail call i32 (...) @ERR_load_crypto_strings()
%6 = tail call i32* @BIO_new_file(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %18, label %8
8: ; preds = %2
%9 = load i32, i32* @NID_zlib_compression
%10 = tail call i32* @CMS_compress(i32* %6, i32 %9, i32 %3)
%11 = icmp eq i32* %10, null
br i1 %11, label %18, label %12
12: ; preds = %8
%13 = 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.3, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = tail call i32 @SMIME_write_CMS(i32* %13, i32* %10, i32* %6, i32 %3)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %2, %8, %12, %15
%19 = phi i32* [ %10, %15 ], [ %10, %12 ], [ null, %8 ], [ null, %2 ]
%20 = phi i32* [ %13, %15 ], [ null, %12 ], [ null, %8 ], [ null, %2 ]
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%23 = load i32, i32* @stderr
%24 = tail call i32 @ERR_print_errors_fp(i32 %23)
%25 = icmp eq i32* %19, null
br i1 %25, label %31, label %26
26: ; preds = %15, %18
%27 = phi i32* [ %20, %18 ], [ %13, %15 ]
%28 = phi i32* [ %19, %18 ], [ %10, %15 ]
%29 = phi i32 [ 1, %18 ], [ 0, %15 ]
%30 = tail call i32 @CMS_ContentInfo_free(i32* %28)
br label %31
31: ; preds = %26, %18
%32 = phi i32* [ %27, %26 ], [ %20, %18 ]
%33 = phi i32 [ %29, %26 ], [ 1, %18 ]
br i1 %7, label %36, label %34
34: ; preds = %31
%35 = tail call i32 @BIO_free(i32* %6)
br label %36
36: ; preds = %34, %31
%37 = icmp eq i32* %32, null
br i1 %37, label %40, label %38
38: ; preds = %36
%39 = tail call i32 @BIO_free(i32* %32)
br label %40
40: ; preds = %38, %36
ret i32 %33
}