#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);
  }
  CMS_ContentInfo_free(cms);
  BIO_free(in);
  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>
mov    -0x28(%rbp),%rdi
call   10b0 <CMS_ContentInfo_free@plt>
mov    -0x18(%rbp),%rdi
call   1060 <BIO_free@plt>
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),%r12d
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <OpenSSL_add_all_algorithms@plt>
xor    %eax,%eax
call   1080 <ERR_load_crypto_strings@plt>
lea    0xe4a(%rip),%rdi
lea    0xe3f(%rip),%rsi
call   10a0 <BIO_new_file@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1221 <main+0x91>
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
mov    %r12d,%edx
call   1070 <CMS_compress@plt>
test   %rax,%rax
je     121e <main+0x8e>
mov    %rax,%r14
lea    0xe11(%rip),%rdi
lea    0xe15(%rip),%rsi
call   10a0 <BIO_new_file@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1221 <main+0x91>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r12d,%ecx
call   1050 <SMIME_write_CMS@plt>
test   %eax,%eax
jne    1247 <main+0xb7>
jmp    1224 <main+0x94>
xor    %r14d,%r14d
xor    %r15d,%r15d
mov    0x2da5(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xdda(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x0(%rbp),%edi
call   1090 <ERR_print_errors_fp@plt>
mov    $0x1,%ebp
mov    %r14,%rdi
call   10b0 <CMS_ContentInfo_free@plt>
mov    %rbx,%rdi
call   1060 <BIO_free@plt>
mov    %r15,%rdi
call   1060 <BIO_free@plt>
mov    %ebp,%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 = call i32 @CMS_ContentInfo_free(i32* %49)
%51 = load i32*, i32** %6
%52 = call i32 @BIO_free(i32* %51)
%53 = load i32*, i32** %7
%54 = call i32 @BIO_free(i32* %53)
%55 = load i32, i32* %9
ret i32 %55
}

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 %25
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)
br label %25
25: ; preds = %18, %15
%26 = phi i32 [ 1, %18 ], [ 0, %15 ]
%27 = phi i32* [ %19, %18 ], [ %10, %15 ]
%28 = phi i32* [ %20, %18 ], [ %13, %15 ]
%29 = tail call i32 @CMS_ContentInfo_free(i32* %27)
%30 = tail call i32 @BIO_free(i32* %6)
%31 = tail call i32 @BIO_free(i32* %28)
ret i32 %26
}