#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 */
typedef int uint64_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, int);
uint64_t count_children_on_row(uint64_t node_val, uint32_t depth) {
  if (depth < 1 || depth > 30) {
    printf("Depth (%d) out of range.", depth);
    exit(1);
  }
  uint64_t i;
  uint64_t children = 0;
  if (depth == 1) {
    children += node_val + 1;
  } else {
    for (i = 1; i < node_val + 2; i++) {
      children += count_children_on_row(i, depth - 1);
    }
  }
  return children;
}


x86 assembly (clang, -O0):
<count_children_on_row>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jl     1152 <count_children_on_row+0x22>
cmpl   $0x1e,-0x8(%rbp)
jle    116b <count_children_on_row+0x3b>
mov    -0x8(%rbp),%esi
lea    0xea4(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    118d <count_children_on_row+0x5d>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11cc <count_children_on_row+0x9c>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x4(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jge    11c7 <count_children_on_row+0x97>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
call   1040 <count_children_on_row@plt>
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1194 <count_children_on_row+0x64>
jmp    11cc <count_children_on_row+0x9c>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_children_on_row>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
lea    -0x1f(%r14),%eax
cmp    $0xffffffe1,%eax
jbe    11a0 <count_children_on_row+0x70>
mov    %edi,%r15d
cmp    $0x1,%r14d
jne    1155 <count_children_on_row+0x25>
add    $0x1,%r15d
mov    %r15d,%ebp
jmp    1193 <count_children_on_row+0x63>
test   %r15d,%r15d
js     1191 <count_children_on_row+0x61>
add    $0xffffffff,%r14d
neg    %r15d
mov    $0x1,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14d,%esi
call   1040 <count_children_on_row@plt>
add    %eax,%ebp
lea    (%r15,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x2,%eax
jne    1170 <count_children_on_row+0x40>
jmp    1193 <count_children_on_row+0x63>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe59(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"Depth (%d) out of range.\00"
define i32 @count_children_on_row(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 1
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 30
br i1 %11, label %12, label %16
12: ; preds = %9, %2
%13 = load i32, i32* %4
%14 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %9
store i32 0, i32* %6
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
%22 = load i32, i32* %6
%23 = add nsw i32 %22, %21
store i32 %23, i32* %6
br label %41
24: ; preds = %16
store i32 1, i32* %5
br label %25
25: ; preds = %37, %24
%26 = load i32, i32* %5
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 2
%29 = icmp slt i32 %26, %28
br i1 %29, label %30, label %40
30: ; preds = %25
%31 = load i32, i32* %5
%32 = load i32, i32* %4
%33 = sub nsw i32 %32, 1
%34 = call i32 @count_children_on_row(i32 %31, i32 %33)
%35 = load i32, i32* %6
%36 = add nsw i32 %35, %34
store i32 %36, i32* %6
br label %37
37: ; preds = %30
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
br label %25
40: ; preds = %25
br label %41
41: ; preds = %40, %19
%42 = load i32, i32* %6
ret i32 %42
}

LLVM IR (-O2):
@.str = [25 x i8] c"Depth (%d) out of range.\00"
define i32 @count_children_on_row(i32 %0, i32 %1) {
%3 = add i32 %1, -31
%4 = icmp ult i32 %3, -30
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %1)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = icmp eq i32 %1, 1
br i1 %9, label %15, label %10
10: ; preds = %8
%11 = icmp sgt i32 %0, -1
br i1 %11, label %12, label %24
12: ; preds = %10
%13 = add nsw i32 %1, -1
%14 = add i32 %0, 1
br label %17
15: ; preds = %8
%16 = add nsw i32 %0, 1
br label %24
17: ; preds = %12, %17
%18 = phi i32 [ 0, %12 ], [ %21, %17 ]
%19 = phi i32 [ 1, %12 ], [ %22, %17 ]
%20 = tail call i32 @count_children_on_row(i32 %19, i32 %13)
%21 = add nsw i32 %20, %18
%22 = add nuw i32 %19, 1
%23 = icmp eq i32 %19, %14
br i1 %23, label %24, label %17
24: ; preds = %17, %10, %15
%25 = phi i32 [ %16, %15 ], [ 0, %10 ], [ %21, %17 ]
ret i32 %25
}