#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 */

/* Variables and functions */
int test_recursive_call(int level, void (*callback_func)(void *), void *data) {
  if (level > 0) {
    return test_recursive_call(level - 1, callback_func, data) + level;
  } else if (callback_func != NULL) {
    callback_func(data);
  } else {
    while (1) {
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_recursive_call>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    114b <test_recursive_call+0x3b>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <test_recursive_call@plt>
add    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    117b <test_recursive_call+0x6b>
cmpq   $0x0,-0x10(%rbp)
je     1165 <test_recursive_call+0x55>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rdi
call   *%rax
jmp    116f <test_recursive_call+0x5f>
jmp    116a <test_recursive_call+0x5a>
jmp    116a <test_recursive_call+0x5a>
jmp    1174 <test_recursive_call+0x64>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_recursive_call>:
push   %rbx
test   %edi,%edi
jle    1129 <test_recursive_call+0x29>
lea    -0x1(%rdi),%eax
lea    -0x2(%rdi),%ecx
imul   %rax,%rcx
mov    %eax,%ebx
imul   %eax,%ebx
shr    %rcx
add    %edi,%ebx
sub    %ecx,%ebx
test   %rsi,%rsi
je     1130 <test_recursive_call+0x30>
mov    %rdx,%rdi
call   *%rsi
mov    %ebx,%eax
pop    %rbx
ret
xor    %ebx,%ebx
test   %rsi,%rsi
jne    1120 <test_recursive_call+0x20>
jmp    1130 <test_recursive_call+0x30>

LLVM IR (-O0):
define i32 @test_recursive_call(i32 %0, void (i8*)* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca void (i8*)*
%7 = alloca i8*
store i32 %0, i32* %5
store void (i8*)* %1, void (i8*)** %6
store i8* %2, i8** %7
%8 = load i32, i32* %5
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %3
%11 = load i32, i32* %5
%12 = sub nsw i32 %11, 1
%13 = load void (i8*)*, void (i8*)** %6
%14 = load i8*, i8** %7
%15 = call i32 @test_recursive_call(i32 %12, void (i8*)* %13, i8* %14)
%16 = load i32, i32* %5
%17 = add nsw i32 %15, %16
store i32 %17, i32* %4
br label %28
18: ; preds = %3
%19 = load void (i8*)*, void (i8*)** %6
%20 = icmp ne void (i8*)* %19, null
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load void (i8*)*, void (i8*)** %6
%23 = load i8*, i8** %7
br label %26
24: ; preds = %18
br label %25
25: ; preds = %24, %25
br label %25
26: ; preds = %21
br label %27
27: ; preds = %26
store i32 0, i32* %4
br label %28
28: ; preds = %27, %10
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
define i32 @test_recursive_call(i32 %0, void (i8*)* %1, i8* %2) {
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %16
5: ; preds = %3
%6 = add nsw i32 %0, -1
%7 = mul i32 %6, %6
%8 = zext i32 %6 to i33
%9 = add nsw i32 %0, -2
%10 = zext i32 %9 to i33
%11 = mul i33 %8, %10
%12 = lshr i33 %11, 1
%13 = trunc i33 %12 to i32
%14 = add i32 %7, %0
%15 = sub i32 %14, %13
br label %16
16: ; preds = %5, %3
%17 = phi i32 [ 0, %3 ], [ %15, %5 ]
%18 = icmp eq void (i8*)* %1, null
br i1 %18, label %20, label %19
19: ; preds = %16
tail call void %1(i8* %2)
ret i32 %17
20: ; preds = %16, %20
br label %20
}