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

/* Variables and functions */
struct avl_tree_node *avl_get_child(struct avl_tree_node *const, int const);
struct avl_tree_node *avl_get_parent(struct avl_tree_node *const);
int /*<<< orphan*/ avl_replace_child(struct avl_tree_node **const,
                                     struct avl_tree_node *const,
                                     struct avl_tree_node *const,
                                     struct avl_tree_node *const);
int /*<<< orphan*/ avl_set_child(struct avl_tree_node *const, int const,
                                 struct avl_tree_node *const);
int /*<<< orphan*/ avl_set_parent(struct avl_tree_node *const,
                                  struct avl_tree_node *const);
__attribute__((always_)) void avl_rotate(struct avl_tree_node **const root_ptr,
                                         struct avl_tree_node *const A,
                                         const int sign) {
  struct avl_tree_node *const B = avl_get_child(A, -sign);
  struct avl_tree_node *const E = avl_get_child(B, +sign);
  struct avl_tree_node *const P = avl_get_parent(A);
  avl_set_child(A, -sign, E);
  avl_set_parent(A, B);
  avl_set_child(B, +sign, A);
  avl_set_parent(B, P);
  if (E)
    avl_set_parent(E, A);
  avl_replace_child(root_ptr, P, A, B);
}


x86 assembly (clang, -O0):
<avl_rotate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
sub    -0x14(%rbp),%esi
call   1030 <avl_get_child@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <avl_get_child@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <avl_get_parent@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
sub    -0x14(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   1040 <avl_set_child@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <avl_set_parent@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1040 <avl_set_child@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <avl_set_parent@plt>
cmpq   $0x0,-0x28(%rbp)
je     11e6 <avl_rotate+0x96>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <avl_set_parent@plt>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1060 <avl_replace_child@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<avl_rotate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,(%rsp)
mov    %edx,%ebp
neg    %ebp
mov    %rsi,%rdi
mov    %ebp,%esi
call   1030 <avl_get_child@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14d,%esi
call   1030 <avl_get_child@plt>
mov    %rax,%r13
mov    %rbx,%rdi
call   1070 <avl_get_parent@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r13,%rdx
call   1040 <avl_set_child@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <avl_set_parent@plt>
mov    %r15,%rdi
mov    %r14d,%esi
mov    %rbx,%rdx
call   1040 <avl_set_child@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <avl_set_parent@plt>
test   %r13,%r13
je     11d0 <avl_rotate+0x80>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1050 <avl_set_parent@plt>
mov    (%rsp),%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <avl_replace_child@plt>

LLVM IR (-O0):
%struct.avl_tree_node = type { i32 }
define void @avl_rotate(%struct.avl_tree_node** %0, %struct.avl_tree_node* %1, i32 %2) {
%4 = alloca %struct.avl_tree_node**
%5 = alloca %struct.avl_tree_node*
%6 = alloca i32
%7 = alloca %struct.avl_tree_node*
%8 = alloca %struct.avl_tree_node*
%9 = alloca %struct.avl_tree_node*
store %struct.avl_tree_node** %0, %struct.avl_tree_node*** %4
store %struct.avl_tree_node* %1, %struct.avl_tree_node** %5
store i32 %2, i32* %6
%10 = load %struct.avl_tree_node*, %struct.avl_tree_node** %5
%11 = load i32, i32* %6
%12 = sub nsw i32 0, %11
%13 = call %struct.avl_tree_node* @avl_get_child(%struct.avl_tree_node* %10, i32 %12)
store %struct.avl_tree_node* %13, %struct.avl_tree_node** %7
%14 = load %struct.avl_tree_node*, %struct.avl_tree_node** %7
%15 = load i32, i32* %6
%16 = call %struct.avl_tree_node* @avl_get_child(%struct.avl_tree_node* %14, i32 %15)
store %struct.avl_tree_node* %16, %struct.avl_tree_node** %8
%17 = load %struct.avl_tree_node*, %struct.avl_tree_node** %5
%18 = call %struct.avl_tree_node* @avl_get_parent(%struct.avl_tree_node* %17)
store %struct.avl_tree_node* %18, %struct.avl_tree_node** %9
%19 = load %struct.avl_tree_node*, %struct.avl_tree_node** %5
%20 = load i32, i32* %6
%21 = sub nsw i32 0, %20
%22 = load %struct.avl_tree_node*, %struct.avl_tree_node** %8
%23 = call i32 @avl_set_child(%struct.avl_tree_node* %19, i32 %21, %struct.avl_tree_node* %22)
%24 = load %struct.avl_tree_node*, %struct.avl_tree_node** %5
%25 = load %struct.avl_tree_node*, %struct.avl_tree_node** %7
%26 = call i32 @avl_set_parent(%struct.avl_tree_node* %24, %struct.avl_tree_node* %25)
%27 = load %struct.avl_tree_node*, %struct.avl_tree_node** %7
%28 = load i32, i32* %6
%29 = load %struct.avl_tree_node*, %struct.avl_tree_node** %5
%30 = call i32 @avl_set_child(%struct.avl_tree_node* %27, i32 %28, %struct.avl_tree_node* %29)
%31 = load %struct.avl_tree_node*, %struct.avl_tree_node** %7
%32 = load %struct.avl_tree_node*, %struct.avl_tree_node** %9
%33 = call i32 @avl_set_parent(%struct.avl_tree_node* %31, %struct.avl_tree_node* %32)
%34 = load %struct.avl_tree_node*, %struct.avl_tree_node** %8
%35 = icmp ne %struct.avl_tree_node* %34, null
br i1 %35, label %36, label %40
36: ; preds = %3
%37 = load %struct.avl_tree_node*, %struct.avl_tree_node** %8
%38 = load %struct.avl_tree_node*, %struct.avl_tree_node** %5
%39 = call i32 @avl_set_parent(%struct.avl_tree_node* %37, %struct.avl_tree_node* %38)
br label %40
40: ; preds = %36, %3
%41 = load %struct.avl_tree_node**, %struct.avl_tree_node*** %4
%42 = load %struct.avl_tree_node*, %struct.avl_tree_node** %9
%43 = load %struct.avl_tree_node*, %struct.avl_tree_node** %5
%44 = load %struct.avl_tree_node*, %struct.avl_tree_node** %7
%45 = call i32 @avl_replace_child(%struct.avl_tree_node** %41, %struct.avl_tree_node* %42, %struct.avl_tree_node* %43, %struct.avl_tree_node* %44)
ret void
}

LLVM IR (-O2):
%struct.avl_tree_node = type { i32 }
define void @avl_rotate(%struct.avl_tree_node** %0, %struct.avl_tree_node* %1, i32 %2) {
%4 = sub nsw i32 0, %2
%5 = tail call %struct.avl_tree_node* @avl_get_child(%struct.avl_tree_node* %1, i32 %4)
%6 = tail call %struct.avl_tree_node* @avl_get_child(%struct.avl_tree_node* %5, i32 %2)
%7 = tail call %struct.avl_tree_node* @avl_get_parent(%struct.avl_tree_node* %1)
%8 = tail call i32 @avl_set_child(%struct.avl_tree_node* %1, i32 %4, %struct.avl_tree_node* %6)
%9 = tail call i32 @avl_set_parent(%struct.avl_tree_node* %1, %struct.avl_tree_node* %5)
%10 = tail call i32 @avl_set_child(%struct.avl_tree_node* %5, i32 %2, %struct.avl_tree_node* %1)
%11 = tail call i32 @avl_set_parent(%struct.avl_tree_node* %5, %struct.avl_tree_node* %7)
%12 = icmp eq %struct.avl_tree_node* %6, null
br i1 %12, label %15, label %13
13: ; preds = %3
%14 = tail call i32 @avl_set_parent(%struct.avl_tree_node* %6, %struct.avl_tree_node* %1)
br label %15
15: ; preds = %13, %3
%16 = tail call i32 @avl_replace_child(%struct.avl_tree_node** %0, %struct.avl_tree_node* %7, %struct.avl_tree_node* %1, %struct.avl_tree_node* %5)
ret void
}