#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 */

/* Variables and functions */
int /*<<< orphan*/ CRYPTO_MEM_CHECK_ON;
int /*<<< orphan*/ CRYPTO_mem_ctrl(int /*<<< orphan*/);
int CRYPTO_mem_leaks_fp(int /*<<< orphan*/);
int /*<<< orphan*/ CRYPTO_set_mem_debug(int);
int /*<<< orphan*/ OPENSSL_free(char *);
char *OPENSSL_malloc(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *getenv(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  char *p;
  char *lost;
  int noleak;
  p = getenv("OPENSSL_DEBUG_MEMORY");
  if (p != NULL && strcmp(p, "on") == 0)
    CRYPTO_set_mem_debug(1);
  CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
  lost = OPENSSL_malloc(3);
  if (lost == NULL) {
    fprintf(stderr, "OPENSSL_malloc failed\n");
    return 1;
  }
  if (argv[1] && strcmp(argv[1], "freeit") == 0) {
    OPENSSL_free(lost);
    lost = NULL;
  }
  noleak = CRYPTO_mem_leaks_fp(stderr);
  if (noleak == -1)
    return 1;
  return ((lost != NULL) ^ (noleak == 0));
}


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)
lea    0xe63(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d5 <main+0x55>
mov    -0x18(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11d5 <main+0x55>
mov    $0x1,%edi
call   10a0 <CRYPTO_set_mem_debug@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1090 <CRYPTO_mem_ctrl@plt>
mov    $0x3,%edi
call   1070 <OPENSSL_malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121d <main+0x9d>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a1 <main+0x121>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     125b <main+0xdb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf4(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    125b <main+0xdb>
mov    -0x20(%rbp),%rdi
call   1080 <OPENSSL_free@plt>
movq   $0x0,-0x20(%rbp)
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
call   1040 <CRYPTO_mem_leaks_fp@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1282 <main+0x102>
movl   $0x1,-0x4(%rbp)
jmp    12a1 <main+0x121>
cmpq   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
cmpl   $0x0,-0x24(%rbp)
sete   %cl
and    $0x1,%cl
movzbl %cl,%ecx
xor    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xe72(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11b6 <main+0x36>
lea    0xe76(%rip),%rsi
mov    %rax,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11b6 <main+0x36>
mov    $0x1,%edi
call   10a0 <CRYPTO_set_mem_debug@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1090 <CRYPTO_mem_ctrl@plt>
mov    $0x3,%edi
call   1070 <OPENSSL_malloc@plt>
test   %rax,%rax
je     121f <main+0x9f>
mov    %rax,%rbx
mov    0x8(%r14),%rdi
test   %rdi,%rdi
je     11fa <main+0x7a>
lea    0xe49(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11fa <main+0x7a>
mov    %rbx,%rdi
call   1080 <OPENSSL_free@plt>
xor    %ebx,%ebx
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
call   1040 <CRYPTO_mem_leaks_fp@plt>
cmp    $0xffffffff,%eax
je     1234 <main+0xb4>
test   %rbx,%rbx
setne  %cl
test   %eax,%eax
sete   %al
xor    %cl,%al
movzbl %al,%eax
jmp    1239 <main+0xb9>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
lea    0xde9(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [21 x i8] c"OPENSSL_DEBUG_MEMORY\00"
@.str.1 = [3 x i8] c"on\00"
@CRYPTO_MEM_CHECK_ON = global i32 0
@stderr = global i32 0
@.str.2 = [23 x i8] c"OPENSSL_malloc failed\0A\00"
@.str.3 = [7 x i8] c"freeit\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i8* @getenv(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8*, i8** %6
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @CRYPTO_set_mem_debug(i32 1)
br label %18
18: ; preds = %16, %12, %2
%19 = load i32, i32* @CRYPTO_MEM_CHECK_ON
%20 = call i32 @CRYPTO_mem_ctrl(i32 %19)
%21 = call i8* @OPENSSL_malloc(i32 3)
store i8* %21, i8** %7
%22 = load i8*, i8** %7
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %55
27: ; preds = %18
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %41
32: ; preds = %27
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %32
%39 = load i8*, i8** %7
%40 = call i32 @OPENSSL_free(i8* %39)
store i8* null, i8** %7
br label %41
41: ; preds = %38, %32, %27
%42 = load i32, i32* @stderr
%43 = call i32 @CRYPTO_mem_leaks_fp(i32 %42)
store i32 %43, i32* %8
%44 = load i32, i32* %8
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %47
46: ; preds = %41
store i32 1, i32* %3
br label %55
47: ; preds = %41
%48 = load i8*, i8** %7
%49 = icmp ne i8* %48, null
%50 = zext i1 %49 to i32
%51 = load i32, i32* %8
%52 = icmp eq i32 %51, 0
%53 = zext i1 %52 to i32
%54 = xor i32 %50, %53
store i32 %54, i32* %3
br label %55
55: ; preds = %47, %46, %24
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@.str = [21 x i8] c"OPENSSL_DEBUG_MEMORY\00"
@.str.1 = [3 x i8] c"on\00"
@CRYPTO_MEM_CHECK_ON = global i32 0
@stderr = global i32 0
@.str.2 = [23 x i8] c"OPENSSL_malloc failed\0A\00"
@.str.3 = [7 x i8] c"freeit\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @CRYPTO_set_mem_debug(i32 1)
br label %10
10: ; preds = %8, %5, %2
%11 = load i32, i32* @CRYPTO_MEM_CHECK_ON
%12 = tail call i32 @CRYPTO_mem_ctrl(i32 %11)
%13 = tail call i8* @OPENSSL_malloc(i32 3)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %37
18: ; preds = %10
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = icmp eq i8* %20, null
br i1 %21, label %27, label %22
22: ; preds = %18
%23 = tail call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = tail call i32 @OPENSSL_free(i8* %13)
br label %27
27: ; preds = %25, %22, %18
%28 = phi i8* [ null, %25 ], [ %13, %22 ], [ %13, %18 ]
%29 = load i32, i32* @stderr
%30 = tail call i32 @CRYPTO_mem_leaks_fp(i32 %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %37, label %32
32: ; preds = %27
%33 = icmp ne i8* %28, null
%34 = icmp eq i32 %30, 0
%35 = xor i1 %33, %34
%36 = zext i1 %35 to i32
br label %37
37: ; preds = %27, %32, %15
%38 = phi i32 [ 1, %15 ], [ %36, %32 ], [ 1, %27 ]
ret i32 %38
}