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

/* Variables and functions */
struct list_cursor *cctools_list_cursor_create(struct list *);
int /*<<< orphan*/ cctools_list_cursor_destroy(struct list_cursor *);
int /*<<< orphan*/ cctools_list_drop(struct list_cursor *);
int /*<<< orphan*/ cctools_list_get(struct list_cursor *, void **);
int /*<<< orphan*/ cctools_list_seek(struct list_cursor *, int);
void *cctools_list_pop_tail(struct list *l) {
  void *item = NULL;
  if (!l)
    return NULL;
  struct list_cursor *cur = cctools_list_cursor_create(l);
  cctools_list_seek(cur, -1);
  cctools_list_get(cur, &item);
  cctools_list_drop(cur);
  cctools_list_cursor_destroy(cur);
  return item;
}


x86 assembly (clang, -O0):
<cctools_list_pop_tail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117c <cctools_list_pop_tail+0x2c>
movq   $0x0,-0x8(%rbp)
jmp    11be <cctools_list_pop_tail+0x6e>
mov    -0x10(%rbp),%rdi
call   1070 <cctools_list_cursor_create@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0xffffffff,%esi
call   1060 <cctools_list_seek@plt>
mov    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <cctools_list_get@plt>
mov    -0x20(%rbp),%rdi
call   1050 <cctools_list_drop@plt>
mov    -0x20(%rbp),%rdi
call   1040 <cctools_list_cursor_destroy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cctools_list_pop_tail>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
test   %rdi,%rdi
je     119c <cctools_list_pop_tail+0x4c>
call   1070 <cctools_list_cursor_create@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0xffffffff,%esi
call   1060 <cctools_list_seek@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <cctools_list_get@plt>
mov    %rbx,%rdi
call   1050 <cctools_list_drop@plt>
mov    %rbx,%rdi
call   1040 <cctools_list_cursor_destroy@plt>
mov    0x8(%rsp),%rax
jmp    119e <cctools_list_pop_tail+0x4e>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.list = type { i32 }
%struct.list_cursor = type { i32 }
define i8* @cctools_list_pop_tail(%struct.list* %0) {
%2 = alloca i8*
%3 = alloca %struct.list*
%4 = alloca i8*
%5 = alloca %struct.list_cursor*
store %struct.list* %0, %struct.list** %3
store i8* null, i8** %4
%6 = load %struct.list*, %struct.list** %3
%7 = icmp ne %struct.list* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store i8* null, i8** %2
br label %21
9: ; preds = %1
%10 = load %struct.list*, %struct.list** %3
%11 = call %struct.list_cursor* @cctools_list_cursor_create(%struct.list* %10)
store %struct.list_cursor* %11, %struct.list_cursor** %5
%12 = load %struct.list_cursor*, %struct.list_cursor** %5
%13 = call i32 @cctools_list_seek(%struct.list_cursor* %12, i32 -1)
%14 = load %struct.list_cursor*, %struct.list_cursor** %5
%15 = call i32 @cctools_list_get(%struct.list_cursor* %14, i8** %4)
%16 = load %struct.list_cursor*, %struct.list_cursor** %5
%17 = call i32 @cctools_list_drop(%struct.list_cursor* %16)
%18 = load %struct.list_cursor*, %struct.list_cursor** %5
%19 = call i32 @cctools_list_cursor_destroy(%struct.list_cursor* %18)
%20 = load i8*, i8** %4
store i8* %20, i8** %2
br label %21
21: ; preds = %9, %8
%22 = load i8*, i8** %2
ret i8* %22
}

LLVM IR (-O2):
%struct.list = type { i32 }
%struct.list_cursor = type { i32 }
define i8* @cctools_list_pop_tail(%struct.list* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%4 = icmp eq %struct.list* %0, null
br i1 %4, label %12, label %5
5: ; preds = %1
%6 = tail call %struct.list_cursor* @cctools_list_cursor_create(%struct.list* %0)
%7 = tail call i32 @cctools_list_seek(%struct.list_cursor* %6, i32 -1)
%8 = call i32 @cctools_list_get(%struct.list_cursor* %6, i8** %2)
%9 = call i32 @cctools_list_drop(%struct.list_cursor* %6)
%10 = call i32 @cctools_list_cursor_destroy(%struct.list_cursor* %6)
%11 = load i8*, i8** %2
br label %12
12: ; preds = %1, %5
%13 = phi i8* [ %11, %5 ], [ null, %1 ]
ret i8* %13
}