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

/* Variables and functions */
int /*<<< orphan*/ list_empty(struct list_head *);
int /*<<< orphan*/ list_init_head(struct list_head *);
int /*<<< orphan*/ list_prev(struct list_head *);
int /*<<< orphan*/ sys_list_splice(struct list_head *, int /*<<< orphan*/,
                                   struct list_head *);
void list_splice_back(struct list_head *src, struct list_head *dest) {
  if (!list_empty(src)) {
    sys_list_splice(src, list_prev(dest), dest);
    list_init_head(src);
  }
}


x86 assembly (clang, -O0):
<list_splice_back>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <list_empty@plt>
cmp    $0x0,%eax
jne    118b <list_splice_back+0x4b>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <list_prev@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
call   1030 <sys_list_splice@plt>
mov    -0x8(%rbp),%rdi
call   1040 <list_init_head@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_splice_back>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1060 <list_empty@plt>
test   %eax,%eax
je     115b <list_splice_back+0x1b>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
call   1050 <list_prev@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r14,%rdx
call   1030 <sys_list_splice@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <list_init_head@plt>

LLVM IR (-O0):
%struct.list_head = type { i32 }
define void @list_splice_back(%struct.list_head* %0, %struct.list_head* %1) {
%3 = alloca %struct.list_head*
%4 = alloca %struct.list_head*
store %struct.list_head* %0, %struct.list_head** %3
store %struct.list_head* %1, %struct.list_head** %4
%5 = load %struct.list_head*, %struct.list_head** %3
%6 = call i32 @list_empty(%struct.list_head* %5)
%7 = icmp ne i32 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %2
%9 = load %struct.list_head*, %struct.list_head** %3
%10 = load %struct.list_head*, %struct.list_head** %4
%11 = call i32 @list_prev(%struct.list_head* %10)
%12 = load %struct.list_head*, %struct.list_head** %4
%13 = call i32 @sys_list_splice(%struct.list_head* %9, i32 %11, %struct.list_head* %12)
%14 = load %struct.list_head*, %struct.list_head** %3
%15 = call i32 @list_init_head(%struct.list_head* %14)
br label %16
16: ; preds = %8, %2
ret void
}

LLVM IR (-O2):
%struct.list_head = type { i32 }
define void @list_splice_back(%struct.list_head* %0, %struct.list_head* %1) {
%3 = tail call i32 @list_empty(%struct.list_head* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = tail call i32 @list_prev(%struct.list_head* %1)
%7 = tail call i32 @sys_list_splice(%struct.list_head* %0, i32 %6, %struct.list_head* %1)
%8 = tail call i32 @list_init_head(%struct.list_head* %0)
br label %9
9: ; preds = %5, %2
ret void
}