#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_get(struct list_cursor *, void **);
int /*<<< orphan*/ cctools_list_seek(struct list_cursor *, int);
void *cctools_list_peek_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_cursor_destroy(cur);
  return item;
}


x86 assembly (clang, -O0):
<cctools_list_peek_tail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116c <cctools_list_peek_tail+0x2c>
movq   $0x0,-0x8(%rbp)
jmp    11a5 <cctools_list_peek_tail+0x65>
mov    -0x10(%rbp),%rdi
call   1060 <cctools_list_cursor_create@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0xffffffff,%esi
call   1050 <cctools_list_seek@plt>
mov    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <cctools_list_get@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_peek_tail>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
test   %rdi,%rdi
je     1184 <cctools_list_peek_tail+0x44>
call   1060 <cctools_list_cursor_create@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0xffffffff,%esi
call   1050 <cctools_list_seek@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <cctools_list_get@plt>
mov    %rbx,%rdi
call   1040 <cctools_list_cursor_destroy@plt>
mov    0x8(%rsp),%rax
jmp    1186 <cctools_list_peek_tail+0x46>
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_peek_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 %19
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_cursor_destroy(%struct.list_cursor* %16)
%18 = load i8*, i8** %4
store i8* %18, i8** %2
br label %19
19: ; preds = %9, %8
%20 = load i8*, i8** %2
ret i8* %20
}

LLVM IR (-O2):
%struct.list = type { i32 }
%struct.list_cursor = type { i32 }
define i8* @cctools_list_peek_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 %11, 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_cursor_destroy(%struct.list_cursor* %6)
%10 = load i8*, i8** %2
br label %11
11: ; preds = %1, %5
%12 = phi i8* [ %10, %5 ], [ null, %1 ]
ret i8* %12
}