#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 tree {
  int dummy;
};
struct node {
  int dummy;
};

/* Variables and functions */
struct node *tree_min_node(struct tree *);
struct node *tree_next_node(struct tree *, struct node *);
struct node *tree_remove_node(struct tree *, struct node *);
__attribute__((unused)) void tree_destroy_node(struct tree *t,
                                               void (*free_cb)(struct node *)) {
  {
    struct node *e, *__tmp;
    for (e = tree_min_node(t);
         (e != NULL) && (__tmp = tree_next_node(t, e), e != NULL); e = __tmp) {
      free_cb(tree_remove_node(t, e));
    }
  };
}


x86 assembly (clang, -O0):
<tree_destroy_node>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <tree_min_node@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x21(%rbp)
je     1179 <tree_destroy_node+0x49>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <tree_next_node@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1189 <tree_destroy_node+0x59>
jmp    11b4 <tree_destroy_node+0x84>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <tree_remove_node@plt>
mov    %rax,%rdi
mov    -0x30(%rbp),%rax
call   *%rax
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    114d <tree_destroy_node+0x1d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tree_destroy_node>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <tree_min_node@plt>
test   %rax,%rax
je     1177 <tree_destroy_node+0x47>
mov    %rax,%rbx
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <tree_next_node@plt>
mov    %rax,%r12
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <tree_remove_node@plt>
mov    %rax,%rdi
call   *%r14
mov    %r12,%rbx
test   %r12,%r12
jne    1150 <tree_destroy_node+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tree = type { i32 }
%struct.node = type { i32 }
define void @tree_destroy_node(%struct.tree* %0, void (%struct.node*)* %1) {
%3 = alloca %struct.tree*
%4 = alloca void (%struct.node*)*
%5 = alloca %struct.node*
%6 = alloca %struct.node*
store %struct.tree* %0, %struct.tree** %3
store void (%struct.node*)* %1, void (%struct.node*)** %4
%7 = load %struct.tree*, %struct.tree** %3
%8 = call %struct.node* @tree_min_node(%struct.tree* %7)
store %struct.node* %8, %struct.node** %5
br label %9
9: ; preds = %25, %2
%10 = load %struct.node*, %struct.node** %5
%11 = icmp ne %struct.node* %10, null
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = load %struct.tree*, %struct.tree** %3
%14 = load %struct.node*, %struct.node** %5
%15 = call %struct.node* @tree_next_node(%struct.tree* %13, %struct.node* %14)
store %struct.node* %15, %struct.node** %6
%16 = load %struct.node*, %struct.node** %5
%17 = icmp ne %struct.node* %16, null
br label %18
18: ; preds = %12, %9
%19 = phi i1 [ false, %9 ], [ %17, %12 ]
br i1 %19, label %20, label %27
20: ; preds = %18
%21 = load void (%struct.node*)*, void (%struct.node*)** %4
%22 = load %struct.tree*, %struct.tree** %3
%23 = load %struct.node*, %struct.node** %5
%24 = call %struct.node* @tree_remove_node(%struct.tree* %22, %struct.node* %23)
br label %25
25: ; preds = %20
%26 = load %struct.node*, %struct.node** %6
store %struct.node* %26, %struct.node** %5
br label %9
27: ; preds = %18
ret void
}

LLVM IR (-O2):
%struct.tree = type { i32 }
%struct.node = type { i32 }
define void @tree_destroy_node(%struct.tree* %0, void (%struct.node*)* nocapture %1) {
%3 = tail call %struct.node* @tree_min_node(%struct.tree* %0)
%4 = icmp eq %struct.node* %3, null
br i1 %4, label %10, label %5
5: ; preds = %2, %5
%6 = phi %struct.node* [ %7, %5 ], [ %3, %2 ]
%7 = tail call %struct.node* @tree_next_node(%struct.tree* %0, %struct.node* %6)
%8 = tail call %struct.node* @tree_remove_node(%struct.tree* %0, %struct.node* %6)
tail call void %1(%struct.node* %8)
%9 = icmp eq %struct.node* %7, null
br i1 %9, label %10, label %5
10: ; preds = %5, %2
ret void
}