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

/* Variables and functions */
int rand();
int /*<<< orphan*/ split_h(struct node *);
int /*<<< orphan*/ split_v(struct node *);
void split(struct node *cnode) {
  int direction = 0;
  direction = rand() % 2;
  switch (direction) {
  case 0:
    if (!split_h(cnode))
      split_v(cnode);
    break;
  case 1:
    if (!split_v(cnode))
      split_h(cnode);
    break;
  }
}


x86 assembly (clang, -O0):
<split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
xor    %eax,%eax
call   1050 <rand@plt>
mov    %eax,%edx
shr    $0x1f,%edx
mov    %eax,%ecx
add    %edx,%ecx
and    $0xfffffffe,%ecx
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
test   %eax,%eax
je     117f <split+0x4f>
jmp    116e <split+0x3e>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
je     119f <split+0x6f>
jmp    11bf <split+0x8f>
mov    -0x8(%rbp),%rdi
call   1040 <split_h@plt>
cmp    $0x0,%eax
jne    119a <split+0x6a>
mov    -0x8(%rbp),%rdi
call   1030 <split_v@plt>
jmp    11bf <split+0x8f>
mov    -0x8(%rbp),%rdi
call   1030 <split_v@plt>
cmp    $0x0,%eax
jne    11ba <split+0x8a>
mov    -0x8(%rbp),%rdi
call   1040 <split_h@plt>
jmp    11bf <split+0x8f>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <rand@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
and    $0xfffffffe,%ecx
sub    %ecx,%eax
cmp    $0x1,%eax
je     1165 <split+0x35>
test   %eax,%eax
jne    1171 <split+0x41>
mov    %rbx,%rdi
call   1040 <split_h@plt>
test   %eax,%eax
jne    1171 <split+0x41>
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <split_v@plt>
mov    %rbx,%rdi
call   1030 <split_v@plt>
test   %eax,%eax
je     1173 <split+0x43>
pop    %rbx
ret
mov    %rbx,%rdi
pop    %rbx
jmp    1040 <split_h@plt>

LLVM IR (-O0):
%struct.node = type { i32 }
define void @split(%struct.node* %0) {
%2 = alloca %struct.node*
%3 = alloca i32
store %struct.node* %0, %struct.node** %2
store i32 0, i32* %3
%4 = call i32 (...) @rand()
%5 = srem i32 %4, 2
store i32 %5, i32* %3
%6 = load i32, i32* %3
switch i32 %6, label %23 [
i32 0, label %7
i32 1, label %15
]
7: ; preds = %1
%8 = load %struct.node*, %struct.node** %2
%9 = call i32 @split_h(%struct.node* %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %7
%12 = load %struct.node*, %struct.node** %2
%13 = call i32 @split_v(%struct.node* %12)
br label %14
14: ; preds = %11, %7
br label %23
15: ; preds = %1
%16 = load %struct.node*, %struct.node** %2
%17 = call i32 @split_v(%struct.node* %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = load %struct.node*, %struct.node** %2
%21 = call i32 @split_h(%struct.node* %20)
br label %22
22: ; preds = %19, %15
br label %23
23: ; preds = %1, %22, %14
ret void
}

LLVM IR (-O2):
%struct.node = type { i32 }
define void @split(%struct.node* %0) {
%2 = tail call i32 (...) @rand()
%3 = srem i32 %2, 2
switch i32 %3, label %14 [
i32 0, label %4
i32 1, label %9
]
4: ; preds = %1
%5 = tail call i32 @split_h(%struct.node* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %4
%8 = tail call i32 @split_v(%struct.node* %0)
br label %14
9: ; preds = %1
%10 = tail call i32 @split_v(%struct.node* %0)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @split_h(%struct.node* %0)
br label %14
14: ; preds = %9, %12, %4, %7, %1
ret void
}