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

/* Variables and functions */
int /*<<< orphan*/ active_list_add(struct active_list *, struct active_list *);
struct active_list *active_list_prev(struct active_list *,
                                     struct active_list *);
struct active_list *active_list_move_node(struct active_list *old_head,
                                          struct active_list *new_head,
                                          struct active_list *node) {
  struct active_list *prev;
  if (!old_head || !new_head || !node)
    return NULL;
  if (old_head == new_head)
    return node;
  prev = active_list_prev(old_head, node);
  active_list_add(new_head, node);
  return prev;
}


x86 assembly (clang, -O0):
<active_list_move_node>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1155 <active_list_move_node+0x35>
cmpq   $0x0,-0x18(%rbp)
je     1155 <active_list_move_node+0x35>
cmpq   $0x0,-0x20(%rbp)
jne    1162 <active_list_move_node+0x42>
movq   $0x0,-0x8(%rbp)
jmp    11a3 <active_list_move_node+0x83>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    117d <active_list_move_node+0x5d>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a3 <active_list_move_node+0x83>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <active_list_prev@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <active_list_add@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<active_list_move_node>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
test   %rdi,%rdi
je     115f <active_list_move_node+0x3f>
mov    %rsi,%rbx
test   %rsi,%rsi
je     115f <active_list_move_node+0x3f>
mov    %rdx,%r14
test   %rdx,%rdx
je     115f <active_list_move_node+0x3f>
cmp    %rbx,%rdi
je     115c <active_list_move_node+0x3c>
mov    %r14,%rsi
call   1040 <active_list_prev@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <active_list_add@plt>
mov    %r15,%rax
jmp    115f <active_list_move_node+0x3f>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.active_list = type { i32 }
define %struct.active_list* @active_list_move_node(%struct.active_list* %0, %struct.active_list* %1, %struct.active_list* %2) {
%4 = alloca %struct.active_list*
%5 = alloca %struct.active_list*
%6 = alloca %struct.active_list*
%7 = alloca %struct.active_list*
%8 = alloca %struct.active_list*
store %struct.active_list* %0, %struct.active_list** %5
store %struct.active_list* %1, %struct.active_list** %6
store %struct.active_list* %2, %struct.active_list** %7
%9 = load %struct.active_list*, %struct.active_list** %5
%10 = icmp ne %struct.active_list* %9, null
br i1 %10, label %11, label %17
11: ; preds = %3
%12 = load %struct.active_list*, %struct.active_list** %6
%13 = icmp ne %struct.active_list* %12, null
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load %struct.active_list*, %struct.active_list** %7
%16 = icmp ne %struct.active_list* %15, null
br i1 %16, label %18, label %17
17: ; preds = %14, %11, %3
store %struct.active_list* null, %struct.active_list** %4
br label %32
18: ; preds = %14
%19 = load %struct.active_list*, %struct.active_list** %5
%20 = load %struct.active_list*, %struct.active_list** %6
%21 = icmp eq %struct.active_list* %19, %20
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = load %struct.active_list*, %struct.active_list** %7
store %struct.active_list* %23, %struct.active_list** %4
br label %32
24: ; preds = %18
%25 = load %struct.active_list*, %struct.active_list** %5
%26 = load %struct.active_list*, %struct.active_list** %7
%27 = call %struct.active_list* @active_list_prev(%struct.active_list* %25, %struct.active_list* %26)
store %struct.active_list* %27, %struct.active_list** %8
%28 = load %struct.active_list*, %struct.active_list** %6
%29 = load %struct.active_list*, %struct.active_list** %7
%30 = call i32 @active_list_add(%struct.active_list* %28, %struct.active_list* %29)
%31 = load %struct.active_list*, %struct.active_list** %8
store %struct.active_list* %31, %struct.active_list** %4
br label %32
32: ; preds = %24, %22, %17
%33 = load %struct.active_list*, %struct.active_list** %4
ret %struct.active_list* %33
}

LLVM IR (-O2):
%struct.active_list = type { i32 }
define %struct.active_list* @active_list_move_node(%struct.active_list* %0, %struct.active_list* %1, %struct.active_list* %2) {
%4 = icmp ne %struct.active_list* %0, null
%5 = icmp ne %struct.active_list* %1, null
%6 = and i1 %4, %5
%7 = icmp ne %struct.active_list* %2, null
%8 = and i1 %6, %7
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = icmp eq %struct.active_list* %0, %1
br i1 %10, label %14, label %11
11: ; preds = %9
%12 = tail call %struct.active_list* @active_list_prev(%struct.active_list* %0, %struct.active_list* %2)
%13 = tail call i32 @active_list_add(%struct.active_list* %1, %struct.active_list* %2)
br label %14
14: ; preds = %9, %3, %11
%15 = phi %struct.active_list* [ %12, %11 ], [ null, %3 ], [ %2, %9 ]
ret %struct.active_list* %15
}