#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 */
long long scm_page_child(long long, int);
long long scm_grow_leaf(long long x, long long **v, long long c, int d) {
  v[0][c++] = x;
  if (d > 0) {
    c = scm_grow_leaf(scm_page_child(x, 0), v, c, d - 1);
    c = scm_grow_leaf(scm_page_child(x, 1), v, c, d - 1);
    c = scm_grow_leaf(scm_page_child(x, 2), v, c, d - 1);
    c = scm_grow_leaf(scm_page_child(x, 3), v, c, d - 1);
  }
  return c;
}


x86 assembly (clang, -O0):
<scm_grow_leaf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x18(%rbp)
mov    %rdx,(%rax,%rcx,8)
cmpl   $0x0,-0x1c(%rbp)
jle    11fc <scm_grow_leaf+0xdc>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1040 <scm_page_child@plt>
mov    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
call   1030 <scm_grow_leaf@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1040 <scm_page_child@plt>
mov    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
call   1030 <scm_grow_leaf@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2,%esi
call   1040 <scm_page_child@plt>
mov    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
call   1030 <scm_grow_leaf@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3,%esi
call   1040 <scm_page_child@plt>
mov    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
call   1030 <scm_grow_leaf@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scm_grow_leaf>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    (%rsi),%rax
mov    %rdi,(%rax,%rdx,8)
add    $0x1,%rbx
test   %ecx,%ecx
jle    11da <scm_grow_leaf+0xba>
mov    %ecx,%r15d
mov    %rsi,%r14
mov    %rdi,%r12
add    $0x1,%r15d
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
xor    %esi,%esi
call   1040 <scm_page_child@plt>
lea    -0x2(%r15),%ebp
mov    %rax,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1030 <scm_grow_leaf@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    $0x1,%esi
call   1040 <scm_page_child@plt>
mov    %rax,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1030 <scm_grow_leaf@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    $0x2,%esi
call   1040 <scm_page_child@plt>
mov    %rax,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1030 <scm_grow_leaf@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    $0x3,%esi
call   1040 <scm_page_child@plt>
mov    %rax,%r12
mov    (%r14),%rax
mov    %r12,(%rax,%rbx,8)
add    $0x1,%rbx
add    $0xffffffff,%r15d
cmp    $0x1,%r15d
ja     1150 <scm_grow_leaf+0x30>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i64 @scm_grow_leaf(i64 %0, i64** %1, i64 %2, i32 %3) {
%5 = load i64*, i64** %1
%6 = add nsw i64 %2, 1
%7 = getelementptr inbounds i64, i64* %5, i64 %2
store i64 %0, i64* %7
%8 = icmp sgt i32 %3, 0
br i1 %8, label %9, label %25
9: ; preds = %4, %9
%10 = phi i64 [ %22, %9 ], [ %6, %4 ]
%11 = phi i32 [ %14, %9 ], [ %3, %4 ]
%12 = phi i64 [ %20, %9 ], [ %0, %4 ]
%13 = tail call i64 @scm_page_child(i64 %12, i32 0)
%14 = add nsw i32 %11, -1
%15 = tail call i64 @scm_grow_leaf(i64 %13, i64** %1, i64 %10, i32 %14)
%16 = tail call i64 @scm_page_child(i64 %12, i32 1)
%17 = tail call i64 @scm_grow_leaf(i64 %16, i64** %1, i64 %15, i32 %14)
%18 = tail call i64 @scm_page_child(i64 %12, i32 2)
%19 = tail call i64 @scm_grow_leaf(i64 %18, i64** %1, i64 %17, i32 %14)
%20 = tail call i64 @scm_page_child(i64 %12, i32 3)
%21 = load i64*, i64** %1
%22 = add nsw i64 %19, 1
%23 = getelementptr inbounds i64, i64* %21, i64 %19
store i64 %20, i64* %23
%24 = icmp ugt i32 %11, 1
br i1 %24, label %9, label %25
25: ; preds = %9, %4
%26 = phi i64 [ %6, %4 ], [ %22, %9 ]
ret i64 %26
}