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

/* Variables and functions */
int *malloc(int);
int *mavl_add(struct mavl *, int *, int /*<<< orphan*/ *);
int *mavl_get(struct mavl *, int *);
int *intavltree_add(struct mavl *t, int val) {
  int *v = mavl_get(t, &val);
  if (v)
    return v;
  v = malloc(sizeof(int));
  if (!v)
    return NULL;
  *v = val;
  return mavl_add(t, v, NULL);
}


x86 assembly (clang, -O0):
<intavltree_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1030 <mavl_get@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1168 <intavltree_add+0x38>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ac <intavltree_add+0x7c>
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118e <intavltree_add+0x5e>
movq   $0x0,-0x8(%rbp)
jmp    11ac <intavltree_add+0x7c>
mov    -0x14(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <mavl_add@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intavltree_add>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %esi,0xc(%rsp)
lea    0xc(%rsp),%rsi
call   1030 <mavl_get@plt>
test   %rax,%rax
jne    1171 <intavltree_add+0x41>
mov    $0x4,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     116f <intavltree_add+0x3f>
mov    0xc(%rsp),%ecx
mov    %ecx,(%rax)
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %edx,%edx
call   1050 <mavl_add@plt>
jmp    1171 <intavltree_add+0x41>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.mavl = type { i32 }
define i32* @intavltree_add(%struct.mavl* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca %struct.mavl*
%5 = alloca i32
%6 = alloca i32*
store %struct.mavl* %0, %struct.mavl** %4
store i32 %1, i32* %5
%7 = load %struct.mavl*, %struct.mavl** %4
%8 = call i32* @mavl_get(%struct.mavl* %7, i32* %5)
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = load i32*, i32** %6
store i32* %12, i32** %3
br label %24
13: ; preds = %2
%14 = call i32* @malloc(i32 4)
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = icmp ne i32* %15, null
br i1 %16, label %18, label %17
17: ; preds = %13
store i32* null, i32** %3
br label %24
18: ; preds = %13
%19 = load i32, i32* %5
%20 = load i32*, i32** %6
store i32 %19, i32* %20
%21 = load %struct.mavl*, %struct.mavl** %4
%22 = load i32*, i32** %6
%23 = call i32* @mavl_add(%struct.mavl* %21, i32* %22, i32* null)
store i32* %23, i32** %3
br label %24
24: ; preds = %18, %17, %11
%25 = load i32*, i32** %3
ret i32* %25
}

LLVM IR (-O2):
%struct.mavl = type { i32 }
define i32* @intavltree_add(%struct.mavl* %0, i32 %1) {
%3 = alloca i32
store i32 %1, i32* %3
%4 = call i32* @mavl_get(%struct.mavl* %0, i32* %3)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = call i32* @malloc(i32 4)
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = load i32, i32* %3
store i32 %10, i32* %7
%11 = call i32* @mavl_add(%struct.mavl* %0, i32* %7, i32* null)
br label %12
12: ; preds = %6, %2, %9
%13 = phi i32* [ %11, %9 ], [ %4, %2 ], [ null, %6 ]
ret i32* %13
}