#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 avl_root {
  int dummy;
};
typedef void avl_node;

/* Variables and functions */
int /*<<< orphan*/ avl_del_node(struct avl_root *, void *);
void *avl_search(struct avl_root *, int);
struct avl_node *avl_delete(struct avl_root *r, int val) {
  struct avl_node *n;
  n = avl_search(r, val);
  if (!n)
    return ((void *)0);
  avl_del_node(r, n);
  return n;
}


x86 assembly (clang, -O0):
<avl_delete>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <avl_search@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1157 <avl_delete+0x37>
movq   $0x0,-0x8(%rbp)
jmp    116c <avl_delete+0x4c>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <avl_del_node@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<avl_delete>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <avl_search@plt>
test   %rax,%rax
je     1141 <avl_delete+0x21>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <avl_del_node@plt>
jmp    1143 <avl_delete+0x23>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.avl_node = type opaque
%struct.avl_root = type { i32 }
define %struct.avl_node* @avl_delete(%struct.avl_root* %0, i32 %1) {
%3 = alloca %struct.avl_node*
%4 = alloca %struct.avl_root*
%5 = alloca i32
%6 = alloca %struct.avl_node*
store %struct.avl_root* %0, %struct.avl_root** %4
store i32 %1, i32* %5
%7 = load %struct.avl_root*, %struct.avl_root** %4
%8 = load i32, i32* %5
%9 = call i8* @avl_search(%struct.avl_root* %7, i32 %8)
%10 = bitcast i8* %9 to %struct.avl_node*
store %struct.avl_node* %10, %struct.avl_node** %6
%11 = load %struct.avl_node*, %struct.avl_node** %6
%12 = icmp ne %struct.avl_node* %11, null
br i1 %12, label %14, label %13
13: ; preds = %2
store %struct.avl_node* null, %struct.avl_node** %3
br label %20
14: ; preds = %2
%15 = load %struct.avl_root*, %struct.avl_root** %4
%16 = load %struct.avl_node*, %struct.avl_node** %6
%17 = bitcast %struct.avl_node* %16 to i8*
%18 = call i32 @avl_del_node(%struct.avl_root* %15, i8* %17)
%19 = load %struct.avl_node*, %struct.avl_node** %6
store %struct.avl_node* %19, %struct.avl_node** %3
br label %20
20: ; preds = %14, %13
%21 = load %struct.avl_node*, %struct.avl_node** %3
ret %struct.avl_node* %21
}

LLVM IR (-O2):
%struct.avl_node = type opaque
%struct.avl_root = type { i32 }
define %struct.avl_node* @avl_delete(%struct.avl_root* %0, i32 %1) {
%3 = tail call i8* @avl_search(%struct.avl_root* %0, i32 %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = bitcast i8* %3 to %struct.avl_node*
%7 = tail call i32 @avl_del_node(%struct.avl_root* %0, i8* %3)
br label %8
8: ; preds = %2, %5
%9 = phi %struct.avl_node* [ %6, %5 ], [ null, %2 ]
ret %struct.avl_node* %9
}