#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 *create_tree();
struct node *tree_add(struct node *);
struct node *tree_get_parent(struct node *);
int main() {
  struct node *root = create_tree();
  struct node *left = tree_add(root);
  struct node *leftRight = tree_add(left);
  struct node *leftRightParent = tree_get_parent(leftRight);
  struct node *leftLeft = tree_add(left);
  struct node *leftRightRight = tree_add(leftRight);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <create_tree@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <tree_add@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <tree_add@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <tree_get_parent@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <tree_add@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <tree_add@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <create_tree@plt>
mov    %rax,%rdi
call   1050 <tree_add@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <tree_add@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <tree_get_parent@plt>
mov    %r14,%rdi
call   1050 <tree_add@plt>
mov    %rbx,%rdi
call   1050 <tree_add@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.node = type { i32 }
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.node*
%3 = alloca %struct.node*
%4 = alloca %struct.node*
%5 = alloca %struct.node*
%6 = alloca %struct.node*
%7 = alloca %struct.node*
store i32 0, i32* %1
%8 = call %struct.node* (...) @create_tree()
store %struct.node* %8, %struct.node** %2
%9 = load %struct.node*, %struct.node** %2
%10 = call %struct.node* @tree_add(%struct.node* %9)
store %struct.node* %10, %struct.node** %3
%11 = load %struct.node*, %struct.node** %3
%12 = call %struct.node* @tree_add(%struct.node* %11)
store %struct.node* %12, %struct.node** %4
%13 = load %struct.node*, %struct.node** %4
%14 = call %struct.node* @tree_get_parent(%struct.node* %13)
store %struct.node* %14, %struct.node** %5
%15 = load %struct.node*, %struct.node** %3
%16 = call %struct.node* @tree_add(%struct.node* %15)
store %struct.node* %16, %struct.node** %6
%17 = load %struct.node*, %struct.node** %4
%18 = call %struct.node* @tree_add(%struct.node* %17)
store %struct.node* %18, %struct.node** %7
ret i32 0
}

LLVM IR (-O2):
%struct.node = type { i32 }
define i32 @main() {
%1 = tail call %struct.node* (...) @create_tree()
%2 = tail call %struct.node* @tree_add(%struct.node* %1)
%3 = tail call %struct.node* @tree_add(%struct.node* %2)
%4 = tail call %struct.node* @tree_get_parent(%struct.node* %3)
%5 = tail call %struct.node* @tree_add(%struct.node* %2)
%6 = tail call %struct.node* @tree_add(%struct.node* %3)
ret i32 0
}