#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 stailq_entry {
  int dummy;
};
struct stailq {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ stailq_add(struct stailq *, struct stailq_entry *);
int /*<<< orphan*/ stailq_create(struct stailq *);
struct stailq_entry *stailq_first(struct stailq *);
struct stailq_entry *stailq_next(struct stailq_entry *);
void stailq_reverse(struct stailq *head) {
  struct stailq_entry *elem = stailq_first(head), *next;
  stailq_create(head);
  while (elem) {
    next = stailq_next(elem);
    stailq_add(head, elem);
    elem = next;
  }
}


x86 assembly (clang, -O0):
<stailq_reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <stailq_first@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <stailq_create@plt>
cmpq   $0x0,-0x10(%rbp)
je     1194 <stailq_reverse+0x54>
mov    -0x10(%rbp),%rdi
call   1030 <stailq_next@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <stailq_add@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1162 <stailq_reverse+0x22>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stailq_reverse>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1050 <stailq_first@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <stailq_create@plt>
test   %rbx,%rbx
je     117e <stailq_reverse+0x3e>
nopl   (%rax)
mov    %rbx,%rdi
call   1030 <stailq_next@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <stailq_add@plt>
mov    %r15,%rbx
test   %r15,%r15
jne    1160 <stailq_reverse+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stailq = type { i32 }
%struct.stailq_entry = type { i32 }
define void @stailq_reverse(%struct.stailq* %0) {
%2 = alloca %struct.stailq*
%3 = alloca %struct.stailq_entry*
%4 = alloca %struct.stailq_entry*
store %struct.stailq* %0, %struct.stailq** %2
%5 = load %struct.stailq*, %struct.stailq** %2
%6 = call %struct.stailq_entry* @stailq_first(%struct.stailq* %5)
store %struct.stailq_entry* %6, %struct.stailq_entry** %3
%7 = load %struct.stailq*, %struct.stailq** %2
%8 = call i32 @stailq_create(%struct.stailq* %7)
br label %9
9: ; preds = %12, %1
%10 = load %struct.stailq_entry*, %struct.stailq_entry** %3
%11 = icmp ne %struct.stailq_entry* %10, null
br i1 %11, label %12, label %19
12: ; preds = %9
%13 = load %struct.stailq_entry*, %struct.stailq_entry** %3
%14 = call %struct.stailq_entry* @stailq_next(%struct.stailq_entry* %13)
store %struct.stailq_entry* %14, %struct.stailq_entry** %4
%15 = load %struct.stailq*, %struct.stailq** %2
%16 = load %struct.stailq_entry*, %struct.stailq_entry** %3
%17 = call i32 @stailq_add(%struct.stailq* %15, %struct.stailq_entry* %16)
%18 = load %struct.stailq_entry*, %struct.stailq_entry** %4
store %struct.stailq_entry* %18, %struct.stailq_entry** %3
br label %9
19: ; preds = %9
ret void
}

LLVM IR (-O2):
%struct.stailq = type { i32 }
%struct.stailq_entry = type { i32 }
define void @stailq_reverse(%struct.stailq* %0) {
%2 = tail call %struct.stailq_entry* @stailq_first(%struct.stailq* %0)
%3 = tail call i32 @stailq_create(%struct.stailq* %0)
%4 = icmp eq %struct.stailq_entry* %2, null
br i1 %4, label %10, label %5
5: ; preds = %1, %5
%6 = phi %struct.stailq_entry* [ %7, %5 ], [ %2, %1 ]
%7 = tail call %struct.stailq_entry* @stailq_next(%struct.stailq_entry* %6)
%8 = tail call i32 @stailq_add(%struct.stailq* %0, %struct.stailq_entry* %6)
%9 = icmp eq %struct.stailq_entry* %7, null
br i1 %9, label %10, label %5
10: ; preds = %5, %1
ret void
}