#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 */
struct bst {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ bst_empty(struct bst *);
int /*<<< orphan*/ bst_remove(struct bst **const, void *,
                              int (*)(void const *, void const *));
void *bst_rightmost(struct bst *);
int /*<<< orphan*/ free(void *);
void bst_destroy(struct bst **const t,
                 int (*compar)(const void *, const void *)) {
  void *data = NULL;
  assert(t != NULL);
  while (!bst_empty(*t)) {
    data = bst_rightmost(*t);
    bst_remove(t, data, compar);
    if (data != NULL)
      free(data);
  }
}


x86 assembly (clang, -O0):
<bst_destroy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <bst_empty@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    119b <bst_destroy+0x4b>
jmp    11d5 <bst_destroy+0x85>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1070 <bst_rightmost@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <bst_remove@plt>
cmpq   $0x0,-0x18(%rbp)
je     11d0 <bst_destroy+0x80>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    117a <bst_destroy+0x2a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bst_destroy>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1060 <assert@plt>
nopl   0x0(%rax)
mov    (%r15),%rdi
call   1050 <bst_empty@plt>
test   %eax,%eax
jne    11a4 <bst_destroy+0x54>
mov    (%r15),%rdi
call   1070 <bst_rightmost@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
mov    %r14,%rdx
call   1040 <bst_remove@plt>
test   %rbx,%rbx
je     1170 <bst_destroy+0x20>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1170 <bst_destroy+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.bst = type { i32 }
define void @bst_destroy(%struct.bst** %0, i32 (i8*, i8*)* %1) {
%3 = alloca %struct.bst**
%4 = alloca i32 (i8*, i8*)*
%5 = alloca i8*
store %struct.bst** %0, %struct.bst*** %3
store i32 (i8*, i8*)* %1, i32 (i8*, i8*)** %4
store i8* null, i8** %5
%6 = load %struct.bst**, %struct.bst*** %3
%7 = icmp ne %struct.bst** %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
br label %10
10: ; preds = %29, %2
%11 = load %struct.bst**, %struct.bst*** %3
%12 = load %struct.bst*, %struct.bst** %11
%13 = call i32 @bst_empty(%struct.bst* %12)
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
br i1 %15, label %16, label %30
16: ; preds = %10
%17 = load %struct.bst**, %struct.bst*** %3
%18 = load %struct.bst*, %struct.bst** %17
%19 = call i8* @bst_rightmost(%struct.bst* %18)
store i8* %19, i8** %5
%20 = load %struct.bst**, %struct.bst*** %3
%21 = load i8*, i8** %5
%22 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %4
%23 = call i32 @bst_remove(%struct.bst** %20, i8* %21, i32 (i8*, i8*)* %22)
%24 = load i8*, i8** %5
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %29
26: ; preds = %16
%27 = load i8*, i8** %5
%28 = call i32 @free(i8* %27)
br label %29
29: ; preds = %26, %16
br label %10
30: ; preds = %10
ret void
}

LLVM IR (-O2):
%struct.bst = type { i32 }
define void @bst_destroy(%struct.bst** %0, i32 (i8*, i8*)* %1) {
%3 = icmp ne %struct.bst** %0, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = load %struct.bst*, %struct.bst** %0
%7 = tail call i32 @bst_empty(%struct.bst* %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %2, %16
%10 = load %struct.bst*, %struct.bst** %0
%11 = tail call i8* @bst_rightmost(%struct.bst* %10)
%12 = tail call i32 @bst_remove(%struct.bst** %0, i8* %11, i32 (i8*, i8*)* %1)
%13 = icmp eq i8* %11, null
br i1 %13, label %16, label %14
14: ; preds = %9
%15 = tail call i32 @free(i8* %11)
br label %16
16: ; preds = %14, %9
%17 = load %struct.bst*, %struct.bst** %0
%18 = tail call i32 @bst_empty(%struct.bst* %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %9, label %20
20: ; preds = %16, %2
ret void
}