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

/* Variables and functions */
int /*<<< orphan*/ dlist_root_append(struct dlist_root *, int /*<<< orphan*/);
int /*<<< orphan*/ dlist_root_empty(struct dlist_root *);
int dlist_root_length(struct dlist_root *);
int /*<<< orphan*/ dlist_root_pop(struct dlist_root *);
void dlist_root_swap_nodes(struct dlist_root *self, struct dlist_root *other) {
  if (self == other)
    return;
  int other_len = dlist_root_length(other);
  int i;
  while (!dlist_root_empty(self)) {
    dlist_root_append(other, dlist_root_pop(self));
  }
  for (i = 0; i < other_len; i++) {
    dlist_root_append(self, dlist_root_pop(other));
  }
}


x86 assembly (clang, -O0):
<dlist_root_swap_nodes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1163 <dlist_root_swap_nodes+0x23>
jmp    11eb <dlist_root_swap_nodes+0xab>
mov    -0x10(%rbp),%rdi
call   1060 <dlist_root_length@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <dlist_root_empty@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    118d <dlist_root_swap_nodes+0x4d>
jmp    11ae <dlist_root_swap_nodes+0x6e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <dlist_root_pop@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
call   1050 <dlist_root_append@plt>
jmp    116f <dlist_root_swap_nodes+0x2f>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11eb <dlist_root_swap_nodes+0xab>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <dlist_root_pop@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
call   1050 <dlist_root_append@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b5 <dlist_root_swap_nodes+0x75>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dlist_root_swap_nodes>:
push   %rbp
push   %r14
push   %rbx
cmp    %rsi,%rdi
je     11a7 <dlist_root_swap_nodes+0x67>
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1060 <dlist_root_length@plt>
mov    %eax,%ebp
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <dlist_root_empty@plt>
test   %eax,%eax
jne    1180 <dlist_root_swap_nodes+0x40>
mov    %rbx,%rdi
call   1030 <dlist_root_pop@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <dlist_root_append@plt>
jmp    1160 <dlist_root_swap_nodes+0x20>
test   %ebp,%ebp
jle    11a7 <dlist_root_swap_nodes+0x67>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
call   1030 <dlist_root_pop@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <dlist_root_append@plt>
add    $0xffffffff,%ebp
jne    1190 <dlist_root_swap_nodes+0x50>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.dlist_root = type { i32 }
define void @dlist_root_swap_nodes(%struct.dlist_root* %0, %struct.dlist_root* %1) {
%3 = alloca %struct.dlist_root*
%4 = alloca %struct.dlist_root*
%5 = alloca i32
%6 = alloca i32
store %struct.dlist_root* %0, %struct.dlist_root** %3
store %struct.dlist_root* %1, %struct.dlist_root** %4
%7 = load %struct.dlist_root*, %struct.dlist_root** %3
%8 = load %struct.dlist_root*, %struct.dlist_root** %4
%9 = icmp eq %struct.dlist_root* %7, %8
br i1 %9, label %10, label %11
10: ; preds = %2
br label %37
11: ; preds = %2
%12 = load %struct.dlist_root*, %struct.dlist_root** %4
%13 = call i32 @dlist_root_length(%struct.dlist_root* %12)
store i32 %13, i32* %5
br label %14
14: ; preds = %19, %11
%15 = load %struct.dlist_root*, %struct.dlist_root** %3
%16 = call i32 @dlist_root_empty(%struct.dlist_root* %15)
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load %struct.dlist_root*, %struct.dlist_root** %4
%21 = load %struct.dlist_root*, %struct.dlist_root** %3
%22 = call i32 @dlist_root_pop(%struct.dlist_root* %21)
%23 = call i32 @dlist_root_append(%struct.dlist_root* %20, i32 %22)
br label %14
24: ; preds = %14
store i32 0, i32* %6
br label %25
25: ; preds = %34, %24
%26 = load i32, i32* %6
%27 = load i32, i32* %5
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %37
29: ; preds = %25
%30 = load %struct.dlist_root*, %struct.dlist_root** %3
%31 = load %struct.dlist_root*, %struct.dlist_root** %4
%32 = call i32 @dlist_root_pop(%struct.dlist_root* %31)
%33 = call i32 @dlist_root_append(%struct.dlist_root* %30, i32 %32)
br label %34
34: ; preds = %29
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %25
37: ; preds = %10, %25
ret void
}

LLVM IR (-O2):
%struct.dlist_root = type { i32 }
define void @dlist_root_swap_nodes(%struct.dlist_root* %0, %struct.dlist_root* %1) {
%3 = icmp eq %struct.dlist_root* %0, %1
br i1 %3, label %21, label %4
4: ; preds = %2
%5 = tail call i32 @dlist_root_length(%struct.dlist_root* %1)
%6 = tail call i32 @dlist_root_empty(%struct.dlist_root* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %10, %4
%9 = icmp sgt i32 %5, 0
br i1 %9, label %15, label %21
10: ; preds = %4, %10
%11 = tail call i32 @dlist_root_pop(%struct.dlist_root* %0)
%12 = tail call i32 @dlist_root_append(%struct.dlist_root* %1, i32 %11)
%13 = tail call i32 @dlist_root_empty(%struct.dlist_root* %0)
%14 = icmp eq i32 %13, 0
br i1 %14, label %10, label %8
15: ; preds = %8, %15
%16 = phi i32 [ %19, %15 ], [ 0, %8 ]
%17 = tail call i32 @dlist_root_pop(%struct.dlist_root* %1)
%18 = tail call i32 @dlist_root_append(%struct.dlist_root* %0, i32 %17)
%19 = add nuw nsw i32 %16, 1
%20 = icmp eq i32 %19, %5
br i1 %20, label %21, label %15
21: ; preds = %15, %8, %2
ret void
}