#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 */
struct node *delete_node(struct node *, int);
int height(struct node *);
struct node *insert(struct node *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int main() {
  struct node *root = NULL;
  const int n = 1024;
  for (int i = 0; i < n; i++) {
    root = insert(root, i);
  }
  puts("");
  printf(" %d ", height(root));
  puts("");
  for (int i = 0; i < n / 2; i++) {
    root = delete_node(root, i);
  }
  printf("after delete");
  puts("");
  printf(" %d ", height(root));
  puts("");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x400,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x400,-0x18(%rbp)
jge    11a0 <main+0x50>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1060 <insert@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1175 <main+0x25>
lea    0xe5d(%rip),%rdi
call   1030 <puts@plt>
mov    -0x10(%rbp),%rdi
call   1070 <height@plt>
mov    %eax,%esi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe38(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x200,-0x1c(%rbp)
jge    1203 <main+0xb3>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <delete_node@plt>
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d8 <main+0x88>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdec(%rip),%rdi
call   1030 <puts@plt>
mov    -0x10(%rbp),%rdi
call   1070 <height@plt>
mov    %eax,%esi
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdc7(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <insert@plt>
mov    %rax,%rbx
add    $0x1,%ebp
cmp    $0x400,%ebp
jne    1160 <main+0x10>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1070 <height@plt>
lea    0xe6f(%rip),%rdi
xor    %ebp,%ebp
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <delete_node@plt>
mov    %rax,%rbx
add    $0x1,%ebp
cmp    $0x200,%ebp
jne    11b0 <main+0x60>
lea    0xe36(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1070 <height@plt>
lea    0xe11(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.node = type { i32 }
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c" %d \00"
@.str.2 = [13 x i8] c"after delete\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.node*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store %struct.node* null, %struct.node** %2
store i32 1024, i32* %3
store i32 0, i32* %4
br label %6
6: ; preds = %13, %0
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 1024
br i1 %8, label %9, label %16
9: ; preds = %6
%10 = load %struct.node*, %struct.node** %2
%11 = load i32, i32* %4
%12 = call %struct.node* @insert(%struct.node* %10, i32 %11)
store %struct.node* %12, %struct.node** %2
br label %13
13: ; preds = %9
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 1
store i32 %15, i32* %4
br label %6
16: ; preds = %6
%17 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%18 = load %struct.node*, %struct.node** %2
%19 = call i32 @height(%struct.node* %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %22
22: ; preds = %29, %16
%23 = load i32, i32* %5
%24 = icmp slt i32 %23, 512
br i1 %24, label %25, label %32
25: ; preds = %22
%26 = load %struct.node*, %struct.node** %2
%27 = load i32, i32* %5
%28 = call %struct.node* @delete_node(%struct.node* %26, i32 %27)
store %struct.node* %28, %struct.node** %2
br label %29
29: ; preds = %25
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %22
32: ; preds = %22
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%35 = load %struct.node*, %struct.node** %2
%36 = call i32 @height(%struct.node* %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.node = type { i32 }
@.str.1 = [5 x i8] c" %d \00"
@.str.2 = [13 x i8] c"after delete\00"
define i32 @main() {
br label %6
1: ; preds = %6
%2 = tail call i32 @putchar(i32 10)
%3 = tail call i32 @height(%struct.node* %9)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = tail call i32 @putchar(i32 10)
br label %18
6: ; preds = %0, %6
%7 = phi i32 [ 0, %0 ], [ %10, %6 ]
%8 = phi %struct.node* [ null, %0 ], [ %9, %6 ]
%9 = tail call %struct.node* @insert(%struct.node* %8, i32 %7)
%10 = add nuw nsw i32 %7, 1
%11 = icmp eq i32 %10, 1024
br i1 %11, label %1, label %6
12: ; preds = %18
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call i32 @putchar(i32 10)
%15 = tail call i32 @height(%struct.node* %21)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = tail call i32 @putchar(i32 10)
ret i32 0
18: ; preds = %1, %18
%19 = phi i32 [ 0, %1 ], [ %22, %18 ]
%20 = phi %struct.node* [ %9, %1 ], [ %21, %18 ]
%21 = tail call %struct.node* @delete_node(%struct.node* %20, i32 %19)
%22 = add nuw nsw i32 %19, 1
%23 = icmp eq i32 %22, 512
br i1 %23, label %12, label %18
}