#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_5__ TYPE_1__;

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

/* Variables and functions */
int /*<<< orphan*/ free(TYPE_1__ *);
int /*<<< orphan*/ memset(TYPE_1__ *, int /*<<< orphan*/, int /*<<< orphan*/);
void BUF_MEM_free(BUF_MEM *a) {
  if (a == NULL)
    return;
  if (a->data != NULL) {
    memset(a->data, 0, a->max);
    free(a->data);
  }
  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    113c <BUF_MEM_free+0x1c>
jmp    1174 <BUF_MEM_free+0x54>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     116b <BUF_MEM_free+0x4b>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BUF_MEM_free>:
test   %rdi,%rdi
je     114c <BUF_MEM_free+0x2c>
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%rdi
test   %rdi,%rdi
je     1143 <BUF_MEM_free+0x23>
mov    0x8(%rbx),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    (%rbx),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <free@plt>
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { %struct.TYPE_5__*, i32 }
define void @BUF_MEM_free(%struct.TYPE_5__* %0) {
%2 = alloca %struct.TYPE_5__*
store %struct.TYPE_5__* %0, %struct.TYPE_5__** %2
%3 = load %struct.TYPE_5__*, %struct.TYPE_5__** %2
%4 = icmp eq %struct.TYPE_5__* %3, null
br i1 %4, label %5, label %6
5: ; preds = %1
br label %26
6: ; preds = %1
%7 = load %struct.TYPE_5__*, %struct.TYPE_5__** %2
%8 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %7, i32 0, i32 0
%9 = load %struct.TYPE_5__*, %struct.TYPE_5__** %8
%10 = icmp ne %struct.TYPE_5__* %9, null
br i1 %10, label %11, label %23
11: ; preds = %6
%12 = load %struct.TYPE_5__*, %struct.TYPE_5__** %2
%13 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 0
%14 = load %struct.TYPE_5__*, %struct.TYPE_5__** %13
%15 = load %struct.TYPE_5__*, %struct.TYPE_5__** %2
%16 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %15, i32 0, i32 1
%17 = load i32, i32* %16
%18 = call i32 @memset(%struct.TYPE_5__* %14, i32 0, i32 %17)
%19 = load %struct.TYPE_5__*, %struct.TYPE_5__** %2
%20 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %19, i32 0, i32 0
%21 = load %struct.TYPE_5__*, %struct.TYPE_5__** %20
%22 = call i32 @free(%struct.TYPE_5__* %21)
br label %23
23: ; preds = %11, %6
%24 = load %struct.TYPE_5__*, %struct.TYPE_5__** %2
%25 = call i32 @free(%struct.TYPE_5__* %24)
br label %26
26: ; preds = %23, %5
ret void
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { %struct.TYPE_5__*, i32 }
define void @BUF_MEM_free(%struct.TYPE_5__* %0) {
%2 = icmp eq %struct.TYPE_5__* %0, null
br i1 %2, label %15, label %3
3: ; preds = %1
%4 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %0, i64 0, i32 0
%5 = load %struct.TYPE_5__*, %struct.TYPE_5__** %4
%6 = icmp eq %struct.TYPE_5__* %5, null
br i1 %6, label %13, label %7
7: ; preds = %3
%8 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %0, i64 0, i32 1
%9 = load i32, i32* %8
%10 = tail call i32 @memset(%struct.TYPE_5__* %5, i32 0, i32 %9)
%11 = load %struct.TYPE_5__*, %struct.TYPE_5__** %4
%12 = tail call i32 @free(%struct.TYPE_5__* %11)
br label %13
13: ; preds = %7, %3
%14 = tail call i32 @free(%struct.TYPE_5__* %0)
br label %15
15: ; preds = %1, %13
ret void
}