#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 linked_list {
  int dummy;
};

/* Variables and functions */
void *fg_list_pop_front(struct linked_list *const);
scalar_t__ fg_list_size(struct linked_list *const);
int /*<<< orphan*/ free(void *);
int fg_list_clear(struct linked_list *const list) {
  if (!list)
    return -1;
  while (fg_list_size(list)) {
    void *data = fg_list_pop_front(list);
    free(data);
  }
  return 0;
}


x86 assembly (clang, -O0):
<fg_list_clear>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1153 <fg_list_clear+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    118d <fg_list_clear+0x5d>
jmp    1158 <fg_list_clear+0x28>
mov    -0x10(%rbp),%rdi
call   1050 <fg_list_size@plt>
cmp    $0x0,%rax
je     1186 <fg_list_clear+0x56>
mov    -0x10(%rbp),%rdi
call   1040 <fg_list_pop_front@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    1158 <fg_list_clear+0x28>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fg_list_clear>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     116f <fg_list_clear+0x3f>
mov    %rdi,%rbx
call   1050 <fg_list_size@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1174 <fg_list_clear+0x44>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <fg_list_pop_front@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1050 <fg_list_size@plt>
test   %rax,%rax
jne    1150 <fg_list_clear+0x20>
jmp    1174 <fg_list_clear+0x44>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.linked_list = type { i32 }
define i32 @fg_list_clear(%struct.linked_list* %0) {
%2 = alloca i32
%3 = alloca %struct.linked_list*
%4 = alloca i8*
store %struct.linked_list* %0, %struct.linked_list** %3
%5 = load %struct.linked_list*, %struct.linked_list** %3
%6 = icmp ne %struct.linked_list* %5, null
br i1 %6, label %8, label %7
7: ; preds = %1
store i32 -1, i32* %2
br label %19
8: ; preds = %1
br label %9
9: ; preds = %13, %8
%10 = load %struct.linked_list*, %struct.linked_list** %3
%11 = call i64 @fg_list_size(%struct.linked_list* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = load %struct.linked_list*, %struct.linked_list** %3
%15 = call i8* @fg_list_pop_front(%struct.linked_list* %14)
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = call i32 @free(i8* %16)
br label %9
18: ; preds = %9
store i32 0, i32* %2
br label %19
19: ; preds = %18, %7
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
%struct.linked_list = type { i32 }
define i32 @fg_list_clear(%struct.linked_list* %0) {
%2 = icmp eq %struct.linked_list* %0, null
br i1 %2, label %11, label %3
3: ; preds = %1
%4 = tail call i64 @fg_list_size(%struct.linked_list* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %3, %6
%7 = tail call i8* @fg_list_pop_front(%struct.linked_list* %0)
%8 = tail call i32 @free(i8* %7)
%9 = tail call i64 @fg_list_size(%struct.linked_list* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %6
11: ; preds = %6, %3, %1
%12 = phi i32 [ -1, %1 ], [ 0, %3 ], [ 0, %6 ]
ret i32 %12
}