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

/* Variables and functions */
struct cl_node *cl_node_flip_colors(struct cl_node *);
scalar_t__ cl_node_is_red(struct cl_node *);
struct cl_node *cl_node_left(struct cl_node *);
struct cl_node *cl_node_right(struct cl_node *);
struct cl_node *cl_node_rotate_left(struct cl_node *);
struct cl_node *cl_node_rotate_right(struct cl_node *);
struct cl_node *cl_node_lean_left(struct cl_node *n) {
  if (cl_node_is_red(cl_node_right(n)) && !cl_node_is_red(cl_node_left(n)))
    n = cl_node_rotate_left(n);
  if (cl_node_is_red(cl_node_left(n)) &&
      cl_node_is_red(cl_node_left(cl_node_left(n))))
    n = cl_node_rotate_right(n);
  if (cl_node_is_red(cl_node_left(n)) && cl_node_is_red(cl_node_right(n)))
    n = cl_node_flip_colors(n);
  return n;
}


x86 assembly (clang, -O0):
<cl_node_lean_left>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <cl_node_right@plt>
mov    %rax,%rdi
call   1040 <cl_node_is_red@plt>
cmp    $0x0,%rax
je     11af <cl_node_lean_left+0x4f>
mov    -0x8(%rbp),%rdi
call   1070 <cl_node_left@plt>
mov    %rax,%rdi
call   1040 <cl_node_is_red@plt>
cmp    $0x0,%rax
jne    11af <cl_node_lean_left+0x4f>
mov    -0x8(%rbp),%rdi
call   1060 <cl_node_rotate_left@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <cl_node_left@plt>
mov    %rax,%rdi
call   1040 <cl_node_is_red@plt>
cmp    $0x0,%rax
je     11fa <cl_node_lean_left+0x9a>
mov    -0x8(%rbp),%rdi
call   1070 <cl_node_left@plt>
mov    %rax,%rdi
call   1070 <cl_node_left@plt>
mov    %rax,%rdi
call   1040 <cl_node_is_red@plt>
cmp    $0x0,%rax
je     11fa <cl_node_lean_left+0x9a>
mov    -0x8(%rbp),%rdi
call   1080 <cl_node_rotate_right@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <cl_node_left@plt>
mov    %rax,%rdi
call   1040 <cl_node_is_red@plt>
cmp    $0x0,%rax
je     123d <cl_node_lean_left+0xdd>
mov    -0x8(%rbp),%rdi
call   1030 <cl_node_right@plt>
mov    %rax,%rdi
call   1040 <cl_node_is_red@plt>
cmp    $0x0,%rax
je     123d <cl_node_lean_left+0xdd>
mov    -0x8(%rbp),%rdi
call   1050 <cl_node_flip_colors@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cl_node_lean_left>:
push   %rbx
mov    %rdi,%rbx
call   1030 <cl_node_right@plt>
mov    %rax,%rdi
call   1040 <cl_node_is_red@plt>
test   %rax,%rax
je     1196 <cl_node_lean_left+0x36>
mov    %rbx,%rdi
call   1070 <cl_node_left@plt>
mov    %rax,%rdi
call   1040 <cl_node_is_red@plt>
test   %rax,%rax
jne    1196 <cl_node_lean_left+0x36>
mov    %rbx,%rdi
call   1060 <cl_node_rotate_left@plt>
mov    %rax,%rbx
mov    %rbx,%rdi
call   1070 <cl_node_left@plt>
mov    %rax,%rdi
call   1040 <cl_node_is_red@plt>
test   %rax,%rax
je     11d3 <cl_node_lean_left+0x73>
mov    %rbx,%rdi
call   1070 <cl_node_left@plt>
mov    %rax,%rdi
call   1070 <cl_node_left@plt>
mov    %rax,%rdi
call   1040 <cl_node_is_red@plt>
test   %rax,%rax
je     11d3 <cl_node_lean_left+0x73>
mov    %rbx,%rdi
call   1080 <cl_node_rotate_right@plt>
mov    %rax,%rbx
mov    %rbx,%rdi
call   1070 <cl_node_left@plt>
mov    %rax,%rdi
call   1040 <cl_node_is_red@plt>
test   %rax,%rax
je     1206 <cl_node_lean_left+0xa6>
mov    %rbx,%rdi
call   1030 <cl_node_right@plt>
mov    %rax,%rdi
call   1040 <cl_node_is_red@plt>
test   %rax,%rax
je     1206 <cl_node_lean_left+0xa6>
mov    %rbx,%rdi
pop    %rbx
jmp    1050 <cl_node_flip_colors@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.cl_node = type { i32 }
define %struct.cl_node* @cl_node_lean_left(%struct.cl_node* %0) {
%2 = alloca %struct.cl_node*
store %struct.cl_node* %0, %struct.cl_node** %2
%3 = load %struct.cl_node*, %struct.cl_node** %2
%4 = call %struct.cl_node* @cl_node_right(%struct.cl_node* %3)
%5 = call i64 @cl_node_is_red(%struct.cl_node* %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %1
%8 = load %struct.cl_node*, %struct.cl_node** %2
%9 = call %struct.cl_node* @cl_node_left(%struct.cl_node* %8)
%10 = call i64 @cl_node_is_red(%struct.cl_node* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %7
%13 = load %struct.cl_node*, %struct.cl_node** %2
%14 = call %struct.cl_node* @cl_node_rotate_left(%struct.cl_node* %13)
store %struct.cl_node* %14, %struct.cl_node** %2
br label %15
15: ; preds = %12, %7, %1
%16 = load %struct.cl_node*, %struct.cl_node** %2
%17 = call %struct.cl_node* @cl_node_left(%struct.cl_node* %16)
%18 = call i64 @cl_node_is_red(%struct.cl_node* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %29
20: ; preds = %15
%21 = load %struct.cl_node*, %struct.cl_node** %2
%22 = call %struct.cl_node* @cl_node_left(%struct.cl_node* %21)
%23 = call %struct.cl_node* @cl_node_left(%struct.cl_node* %22)
%24 = call i64 @cl_node_is_red(%struct.cl_node* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = load %struct.cl_node*, %struct.cl_node** %2
%28 = call %struct.cl_node* @cl_node_rotate_right(%struct.cl_node* %27)
store %struct.cl_node* %28, %struct.cl_node** %2
br label %29
29: ; preds = %26, %20, %15
%30 = load %struct.cl_node*, %struct.cl_node** %2
%31 = call %struct.cl_node* @cl_node_left(%struct.cl_node* %30)
%32 = call i64 @cl_node_is_red(%struct.cl_node* %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %42
34: ; preds = %29
%35 = load %struct.cl_node*, %struct.cl_node** %2
%36 = call %struct.cl_node* @cl_node_right(%struct.cl_node* %35)
%37 = call i64 @cl_node_is_red(%struct.cl_node* %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = load %struct.cl_node*, %struct.cl_node** %2
%41 = call %struct.cl_node* @cl_node_flip_colors(%struct.cl_node* %40)
store %struct.cl_node* %41, %struct.cl_node** %2
br label %42
42: ; preds = %39, %34, %29
%43 = load %struct.cl_node*, %struct.cl_node** %2
ret %struct.cl_node* %43
}

LLVM IR (-O2):
%struct.cl_node = type { i32 }
define %struct.cl_node* @cl_node_lean_left(%struct.cl_node* %0) {
%2 = tail call %struct.cl_node* @cl_node_right(%struct.cl_node* %0)
%3 = tail call i64 @cl_node_is_red(%struct.cl_node* %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %11, label %5
5: ; preds = %1
%6 = tail call %struct.cl_node* @cl_node_left(%struct.cl_node* %0)
%7 = tail call i64 @cl_node_is_red(%struct.cl_node* %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call %struct.cl_node* @cl_node_rotate_left(%struct.cl_node* %0)
br label %11
11: ; preds = %9, %5, %1
%12 = phi %struct.cl_node* [ %0, %5 ], [ %10, %9 ], [ %0, %1 ]
%13 = tail call %struct.cl_node* @cl_node_left(%struct.cl_node* %12)
%14 = tail call i64 @cl_node_is_red(%struct.cl_node* %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %23, label %16
16: ; preds = %11
%17 = tail call %struct.cl_node* @cl_node_left(%struct.cl_node* %12)
%18 = tail call %struct.cl_node* @cl_node_left(%struct.cl_node* %17)
%19 = tail call i64 @cl_node_is_red(%struct.cl_node* %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %16
%22 = tail call %struct.cl_node* @cl_node_rotate_right(%struct.cl_node* %12)
br label %23
23: ; preds = %21, %16, %11
%24 = phi %struct.cl_node* [ %22, %21 ], [ %12, %16 ], [ %12, %11 ]
%25 = tail call %struct.cl_node* @cl_node_left(%struct.cl_node* %24)
%26 = tail call i64 @cl_node_is_red(%struct.cl_node* %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %34, label %28
28: ; preds = %23
%29 = tail call %struct.cl_node* @cl_node_right(%struct.cl_node* %24)
%30 = tail call i64 @cl_node_is_red(%struct.cl_node* %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %28
%33 = tail call %struct.cl_node* @cl_node_flip_colors(%struct.cl_node* %24)
br label %34
34: ; preds = %32, %28, %23
%35 = phi %struct.cl_node* [ %33, %32 ], [ %24, %28 ], [ %24, %23 ]
ret %struct.cl_node* %35
}