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

/* Variables and functions */
int /*<<< orphan*/ failure(char *);
int /*<<< orphan*/ list_end(struct list_node *);
struct list_node *list_head(struct list *);
struct list_node *list_tail(struct list *);
void test_empty_ends(struct list *list) {
  struct list_node *head = list_head(list);
  struct list_node *tail = list_tail(list);
  if (head != tail)
    failure("empty list head should equal tail");
  if (!list_end(head))
    failure("empty list head should have been end");
}


x86 assembly (clang, -O0):
<test_empty_ends>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <list_head@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <list_tail@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     1180 <test_empty_ends+0x40>
lea    0xe85(%rip),%rdi
call   1040 <failure@plt>
mov    -0x10(%rbp),%rdi
call   1060 <list_end@plt>
cmp    $0x0,%eax
jne    119e <test_empty_ends+0x5e>
lea    0xe89(%rip),%rdi
call   1040 <failure@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_empty_ends>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <list_head@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <list_tail@plt>
cmp    %rax,%r14
je     1168 <test_empty_ends+0x28>
lea    0xe9d(%rip),%rdi
call   1040 <failure@plt>
mov    %r14,%rdi
call   1060 <list_end@plt>
test   %eax,%eax
je     117c <test_empty_ends+0x3c>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe9f(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <failure@plt>

LLVM IR (-O0):
%struct.list = type { i32 }
%struct.list_node = type { i32 }
@.str = [34 x i8] c"empty list head should equal tail\00"
@.str.1 = [37 x i8] c"empty list head should have been end\00"
define void @test_empty_ends(%struct.list* %0) {
%2 = alloca %struct.list*
%3 = alloca %struct.list_node*
%4 = alloca %struct.list_node*
store %struct.list* %0, %struct.list** %2
%5 = load %struct.list*, %struct.list** %2
%6 = call %struct.list_node* @list_head(%struct.list* %5)
store %struct.list_node* %6, %struct.list_node** %3
%7 = load %struct.list*, %struct.list** %2
%8 = call %struct.list_node* @list_tail(%struct.list* %7)
store %struct.list_node* %8, %struct.list_node** %4
%9 = load %struct.list_node*, %struct.list_node** %3
%10 = load %struct.list_node*, %struct.list_node** %4
%11 = icmp ne %struct.list_node* %9, %10
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @failure(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %1
%15 = load %struct.list_node*, %struct.list_node** %3
%16 = call i32 @list_end(%struct.list_node* %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %14
%19 = call i32 @failure(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
ret void
}

LLVM IR (-O2):
%struct.list = type { i32 }
%struct.list_node = type { i32 }
@.str = [34 x i8] c"empty list head should equal tail\00"
@.str.1 = [37 x i8] c"empty list head should have been end\00"
define void @test_empty_ends(%struct.list* %0) {
%2 = tail call %struct.list_node* @list_head(%struct.list* %0)
%3 = tail call %struct.list_node* @list_tail(%struct.list* %0)
%4 = icmp eq %struct.list_node* %2, %3
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = tail call i32 @failure(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %1
%8 = tail call i32 @list_end(%struct.list_node* %2)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @failure(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
ret void
}