#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 list {
  int dummy;
};
struct cursor {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ cursor_delete(struct cursor *);
scalar_t__ cursor_get(struct cursor *);
struct cursor *cursor_new_front(struct list *);
int /*<<< orphan*/ cursor_next(struct cursor *);
scalar_t__ cursor_valid(struct cursor *);
int /*<<< orphan*/ list_delete(struct list *);
int /*<<< orphan*/ value_delete(scalar_t__);
void clear_value_list(struct list *args) {
  struct cursor *c = NULL;
  for (c = cursor_new_front(args); cursor_valid(c); cursor_next(c))
    if (cursor_get(c))
      value_delete(cursor_get(c));
  list_delete(args);
  cursor_delete(c);
}


x86 assembly (clang, -O0):
<clear_value_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <cursor_new_front@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <cursor_valid@plt>
cmp    $0x0,%rax
je     11db <clear_value_list+0x6b>
mov    -0x10(%rbp),%rdi
call   1070 <cursor_get@plt>
cmp    $0x0,%rax
je     11c8 <clear_value_list+0x58>
mov    -0x10(%rbp),%rdi
call   1070 <cursor_get@plt>
mov    %rax,%rdi
call   1050 <value_delete@plt>
jmp    11cd <clear_value_list+0x5d>
mov    -0x10(%rbp),%rdi
call   1040 <cursor_next@plt>
jmp    1191 <clear_value_list+0x21>
mov    -0x8(%rbp),%rdi
call   1060 <list_delete@plt>
mov    -0x10(%rbp),%rdi
call   1080 <cursor_delete@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clear_value_list>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1090 <cursor_new_front@plt>
mov    %rax,%rbx
mov    %rax,%rdi
jmp    119b <clear_value_list+0x2b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1040 <cursor_next@plt>
mov    %rbx,%rdi
call   1030 <cursor_valid@plt>
test   %rax,%rax
je     11c4 <clear_value_list+0x54>
mov    %rbx,%rdi
call   1070 <cursor_get@plt>
test   %rax,%rax
je     1190 <clear_value_list+0x20>
mov    %rbx,%rdi
call   1070 <cursor_get@plt>
mov    %rax,%rdi
call   1050 <value_delete@plt>
jmp    1190 <clear_value_list+0x20>
mov    %r14,%rdi
call   1060 <list_delete@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1080 <cursor_delete@plt>

LLVM IR (-O0):
%struct.list = type { i32 }
%struct.cursor = type { i32 }
define void @clear_value_list(%struct.list* %0) {
%2 = alloca %struct.list*
%3 = alloca %struct.cursor*
store %struct.list* %0, %struct.list** %2
store %struct.cursor* null, %struct.cursor** %3
%4 = load %struct.list*, %struct.list** %2
%5 = call %struct.cursor* @cursor_new_front(%struct.list* %4)
store %struct.cursor* %5, %struct.cursor** %3
br label %6
6: ; preds = %19, %1
%7 = load %struct.cursor*, %struct.cursor** %3
%8 = call i64 @cursor_valid(%struct.cursor* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %22
10: ; preds = %6
%11 = load %struct.cursor*, %struct.cursor** %3
%12 = call i64 @cursor_get(%struct.cursor* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load %struct.cursor*, %struct.cursor** %3
%16 = call i64 @cursor_get(%struct.cursor* %15)
%17 = call i32 @value_delete(i64 %16)
br label %18
18: ; preds = %14, %10
br label %19
19: ; preds = %18
%20 = load %struct.cursor*, %struct.cursor** %3
%21 = call i32 @cursor_next(%struct.cursor* %20)
br label %6
22: ; preds = %6
%23 = load %struct.list*, %struct.list** %2
%24 = call i32 @list_delete(%struct.list* %23)
%25 = load %struct.cursor*, %struct.cursor** %3
%26 = call i32 @cursor_delete(%struct.cursor* %25)
ret void
}

LLVM IR (-O2):
%struct.list = type { i32 }
%struct.cursor = type { i32 }
define void @clear_value_list(%struct.list* %0) {
%2 = tail call %struct.cursor* @cursor_new_front(%struct.list* %0)
%3 = tail call i64 @cursor_valid(%struct.cursor* %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %1, %11
%6 = tail call i64 @cursor_get(%struct.cursor* %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = tail call i64 @cursor_get(%struct.cursor* %2)
%10 = tail call i32 @value_delete(i64 %9)
br label %11
11: ; preds = %5, %8
%12 = tail call i32 @cursor_next(%struct.cursor* %2)
%13 = tail call i64 @cursor_valid(%struct.cursor* %2)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %5
15: ; preds = %11, %1
%16 = tail call i32 @list_delete(%struct.list* %0)
%17 = tail call i32 @cursor_delete(%struct.cursor* %2)
ret void
}