#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int flags;
  int /*<<< orphan*/ max;
  int /*<<< orphan*/ *data;
};
typedef TYPE_1__ BUF_MEM;

/* Variables and functions */
int BUF_MEM_FLAG_SECURE;
int /*<<< orphan*/ OPENSSL_clear_free(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ OPENSSL_free(TYPE_1__ *);
int /*<<< orphan*/ OPENSSL_secure_free(int /*<<< orphan*/ *);
void BUF_MEM_free(BUF_MEM *a) {
  if (a == NULL)
    return;
  if (a->data != NULL) {
    if (a->flags & BUF_MEM_FLAG_SECURE)
      OPENSSL_secure_free(a->data);
    else
      OPENSSL_clear_free(a->data, a->max);
  }
  OPENSSL_free(a);
}


x86 assembly (clang, -O0):
<BUF_MEM_free>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    114c <BUF_MEM_free+0x1c>
jmp    11a7 <BUF_MEM_free+0x77>
mov    -0x8(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     119e <BUF_MEM_free+0x6e>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    0x2e88(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1185 <BUF_MEM_free+0x55>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <OPENSSL_secure_free@plt>
jmp    1199 <BUF_MEM_free+0x69>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%esi
call   1040 <OPENSSL_clear_free@plt>
jmp    119e <BUF_MEM_free+0x6e>
mov    -0x8(%rbp),%rdi
call   1050 <OPENSSL_free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BUF_MEM_free>:
test   %rdi,%rdi
je     1156 <BUF_MEM_free+0x26>
push   %rbx
mov    %rdi,%rbx
mov    0x8(%rdi),%rdi
test   %rdi,%rdi
je     115f <BUF_MEM_free+0x2f>
mov    0x2ea7(%rip),%rax
mov    (%rax),%eax
test   %eax,(%rbx)
je     1157 <BUF_MEM_free+0x27>
call   1030 <OPENSSL_secure_free@plt>
jmp    115f <BUF_MEM_free+0x2f>
ret
mov    0x4(%rbx),%esi
call   1040 <OPENSSL_clear_free@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1050 <OPENSSL_free@plt>

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i32, i32* }
@BUF_MEM_FLAG_SECURE = global i32 0
define void @BUF_MEM_free(%struct.TYPE_4__* %0) {
%2 = alloca %struct.TYPE_4__*
store %struct.TYPE_4__* %0, %struct.TYPE_4__** %2
%3 = load %struct.TYPE_4__*, %struct.TYPE_4__** %2
%4 = icmp eq %struct.TYPE_4__* %3, null
br i1 %4, label %5, label %6
5: ; preds = %1
br label %35
6: ; preds = %1
%7 = load %struct.TYPE_4__*, %struct.TYPE_4__** %2
%8 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 2
%9 = load i32*, i32** %8
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %32
11: ; preds = %6
%12 = load %struct.TYPE_4__*, %struct.TYPE_4__** %2
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %12, i32 0, i32 0
%14 = load i32, i32* %13
%15 = load i32, i32* @BUF_MEM_FLAG_SECURE
%16 = and i32 %14, %15
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %11
%19 = load %struct.TYPE_4__*, %struct.TYPE_4__** %2
%20 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %19, i32 0, i32 2
%21 = load i32*, i32** %20
%22 = call i32 @OPENSSL_secure_free(i32* %21)
br label %31
23: ; preds = %11
%24 = load %struct.TYPE_4__*, %struct.TYPE_4__** %2
%25 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %24, i32 0, i32 2
%26 = load i32*, i32** %25
%27 = load %struct.TYPE_4__*, %struct.TYPE_4__** %2
%28 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %27, i32 0, i32 1
%29 = load i32, i32* %28
%30 = call i32 @OPENSSL_clear_free(i32* %26, i32 %29)
br label %31
31: ; preds = %23, %18
br label %32
32: ; preds = %31, %6
%33 = load %struct.TYPE_4__*, %struct.TYPE_4__** %2
%34 = call i32 @OPENSSL_free(%struct.TYPE_4__* %33)
br label %35
35: ; preds = %32, %5
ret void
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i32, i32* }
@BUF_MEM_FLAG_SECURE = global i32 0
define void @BUF_MEM_free(%struct.TYPE_4__* %0) {
%2 = icmp eq %struct.TYPE_4__* %0, null
br i1 %2, label %21, label %3
3: ; preds = %1
%4 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 2
%5 = load i32*, i32** %4
%6 = icmp eq i32* %5, null
br i1 %6, label %19, label %7
7: ; preds = %3
%8 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 0
%9 = load i32, i32* %8
%10 = load i32, i32* @BUF_MEM_FLAG_SECURE
%11 = and i32 %10, %9
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %7
%14 = tail call i32 @OPENSSL_secure_free(i32* %5)
br label %19
15: ; preds = %7
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 1
%17 = load i32, i32* %16
%18 = tail call i32 @OPENSSL_clear_free(i32* %5, i32 %17)
br label %19
19: ; preds = %13, %15, %3
%20 = tail call i32 @OPENSSL_free(%struct.TYPE_4__* %0)
br label %21
21: ; preds = %1, %19
ret void
}