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

/* Variables and functions */
struct tree *tree_find(struct tree *, void *,
                       int (*)(void const *, void const *, void *), void *);
int tree_rank(struct tree *, void *,
              int (*)(void const *, void const *, void *), void *);
int tree_range_size(struct tree *tree, void *lo, void *hi,
                    int (*compare)(const void *a, const void *b, void *context),
                    void *context) {
  struct tree *node;
  node = tree_find(tree, hi, compare, context);
  if (node != NULL) {
    return tree_rank(tree, hi, compare, context) -
           tree_rank(tree, lo, compare, context) + 1;
  } else {
    return tree_rank(tree, hi, compare, context) -
           tree_rank(tree, lo, compare, context);
  }
}


x86 assembly (clang, -O0):
<tree_range_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1030 <tree_find@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     119f <tree_range_size+0x7f>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1040 <tree_rank@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1040 <tree_rank@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
sub    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11d6 <tree_range_size+0xb6>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1040 <tree_rank@plt>
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1040 <tree_rank@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tree_range_size>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r13
mov    %rdx,%r15
mov    %rsi,(%rsp)
mov    %rdi,%rbx
mov    %rdx,%rsi
mov    %rcx,%rdx
mov    %r8,%rcx
call   1030 <tree_find@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
mov    %r14,%rcx
call   1040 <tree_rank@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    (%rsp),%rsi
mov    %r13,%rdx
mov    %r14,%rcx
call   1040 <tree_rank@plt>
cmp    $0x1,%r12
sbb    $0xffffffff,%ebp
sub    %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tree = type { i32 }
define i32 @tree_range_size(%struct.tree* %0, i8* %1, i8* %2, i32 (i8*, i8*, i8*)* %3, i8* %4) {
%6 = alloca i32
%7 = alloca %struct.tree*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32 (i8*, i8*, i8*)*
%11 = alloca i8*
%12 = alloca %struct.tree*
store %struct.tree* %0, %struct.tree** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i32 (i8*, i8*, i8*)* %3, i32 (i8*, i8*, i8*)** %10
store i8* %4, i8** %11
%13 = load %struct.tree*, %struct.tree** %7
%14 = load i8*, i8** %9
%15 = load i32 (i8*, i8*, i8*)*, i32 (i8*, i8*, i8*)** %10
%16 = load i8*, i8** %11
%17 = call %struct.tree* @tree_find(%struct.tree* %13, i8* %14, i32 (i8*, i8*, i8*)* %15, i8* %16)
store %struct.tree* %17, %struct.tree** %12
%18 = load %struct.tree*, %struct.tree** %12
%19 = icmp ne %struct.tree* %18, null
br i1 %19, label %20, label %33
20: ; preds = %5
%21 = load %struct.tree*, %struct.tree** %7
%22 = load i8*, i8** %9
%23 = load i32 (i8*, i8*, i8*)*, i32 (i8*, i8*, i8*)** %10
%24 = load i8*, i8** %11
%25 = call i32 @tree_rank(%struct.tree* %21, i8* %22, i32 (i8*, i8*, i8*)* %23, i8* %24)
%26 = load %struct.tree*, %struct.tree** %7
%27 = load i8*, i8** %8
%28 = load i32 (i8*, i8*, i8*)*, i32 (i8*, i8*, i8*)** %10
%29 = load i8*, i8** %11
%30 = call i32 @tree_rank(%struct.tree* %26, i8* %27, i32 (i8*, i8*, i8*)* %28, i8* %29)
%31 = sub nsw i32 %25, %30
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %45
33: ; preds = %5
%34 = load %struct.tree*, %struct.tree** %7
%35 = load i8*, i8** %9
%36 = load i32 (i8*, i8*, i8*)*, i32 (i8*, i8*, i8*)** %10
%37 = load i8*, i8** %11
%38 = call i32 @tree_rank(%struct.tree* %34, i8* %35, i32 (i8*, i8*, i8*)* %36, i8* %37)
%39 = load %struct.tree*, %struct.tree** %7
%40 = load i8*, i8** %8
%41 = load i32 (i8*, i8*, i8*)*, i32 (i8*, i8*, i8*)** %10
%42 = load i8*, i8** %11
%43 = call i32 @tree_rank(%struct.tree* %39, i8* %40, i32 (i8*, i8*, i8*)* %41, i8* %42)
%44 = sub nsw i32 %38, %43
store i32 %44, i32* %6
br label %45
45: ; preds = %33, %20
%46 = load i32, i32* %6
ret i32 %46
}

LLVM IR (-O2):
%struct.tree = type { i32 }
define i32 @tree_range_size(%struct.tree* %0, i8* %1, i8* %2, i32 (i8*, i8*, i8*)* %3, i8* %4) {
%6 = tail call %struct.tree* @tree_find(%struct.tree* %0, i8* %2, i32 (i8*, i8*, i8*)* %3, i8* %4)
%7 = icmp ne %struct.tree* %6, null
%8 = tail call i32 @tree_rank(%struct.tree* %0, i8* %2, i32 (i8*, i8*, i8*)* %3, i8* %4)
%9 = tail call i32 @tree_rank(%struct.tree* %0, i8* %1, i32 (i8*, i8*, i8*)* %3, i8* %4)
%10 = zext i1 %7 to i32
%11 = add i32 %8, %10
%12 = sub i32 %11, %9
ret i32 %12
}