#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 util_list {
  int dummy;
};
struct target {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ target_free(struct target *);
int /*<<< orphan*/ util_list_free(struct util_list *);
struct target *util_list_next(struct util_list *, struct target *);
int /*<<< orphan*/ util_list_remove(struct util_list *, struct target *);
struct target *util_list_start(struct util_list *);
void table_free(struct util_list *table) {
  struct target *target, *n;
  for (target = util_list_start(table), n = util_list_next(table, target);
       target != NULL; target = n, n = util_list_next(table, target)) {
    util_list_remove(table, target);
    target_free(target);
  }
  util_list_free(table);
}


x86 assembly (clang, -O0):
<table_free>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <util_list_start@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <util_list_next@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b9 <table_free+0x69>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <util_list_remove@plt>
mov    -0x10(%rbp),%rdi
call   1060 <target_free@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <util_list_next@plt>
mov    %rax,-0x18(%rbp)
jmp    117a <table_free+0x2a>
mov    -0x8(%rbp),%rdi
call   1070 <util_list_free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<table_free>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1050 <util_list_start@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <util_list_next@plt>
test   %rbx,%rbx
je     1199 <table_free+0x49>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <util_list_remove@plt>
mov    %rbx,%rdi
call   1060 <target_free@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <util_list_next@plt>
mov    %r15,%rbx
test   %r15,%r15
jne    1170 <table_free+0x20>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <util_list_free@plt>

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

LLVM IR (-O2):
%struct.util_list = type { i32 }
%struct.target = type { i32 }
define void @table_free(%struct.util_list* %0) {
%2 = tail call %struct.target* @util_list_start(%struct.util_list* %0)
%3 = tail call %struct.target* @util_list_next(%struct.util_list* %0, %struct.target* %2)
%4 = icmp eq %struct.target* %2, null
br i1 %4, label %12, label %5
5: ; preds = %1, %5
%6 = phi %struct.target* [ %10, %5 ], [ %3, %1 ]
%7 = phi %struct.target* [ %6, %5 ], [ %2, %1 ]
%8 = tail call i32 @util_list_remove(%struct.util_list* %0, %struct.target* %7)
%9 = tail call i32 @target_free(%struct.target* %7)
%10 = tail call %struct.target* @util_list_next(%struct.util_list* %0, %struct.target* %6)
%11 = icmp eq %struct.target* %6, null
br i1 %11, label %12, label %5
12: ; preds = %5, %1
%13 = tail call i32 @util_list_free(%struct.util_list* %0)
ret void
}