#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 ipow(int, int);
int calculate_number_of_nodes(int md, int Nr, int Nh) {
  int n_nodes;
  if (md == 1) {
    n_nodes = Nh + 1;
  } else {
    n_nodes = (Nh - Nr) * ipow(md, Nr) + (ipow(md, Nr + 1) - 1) / (md - 1);
  }
  return n_nodes;
}


x86 assembly (clang, -O0):
<calculate_number_of_nodes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x1,-0x4(%rbp)
jne    1139 <calculate_number_of_nodes+0x29>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117c <calculate_number_of_nodes+0x6c>
mov    -0xc(%rbp),%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <ipow@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
add    $0x1,%esi
call   1030 <ipow@plt>
sub    $0x1,%eax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate_number_of_nodes>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
cmp    $0x1,%edi
jne    1123 <calculate_number_of_nodes+0x13>
add    $0x1,%ebp
jmp    1152 <calculate_number_of_nodes+0x42>
mov    %esi,%r14d
mov    %edi,%ebx
sub    %esi,%ebp
call   1030 <ipow@plt>
mov    %eax,%r15d
imul   %ebp,%r15d
add    $0x1,%r14d
mov    %ebx,%edi
mov    %r14d,%esi
call   1030 <ipow@plt>
add    $0xffffffff,%eax
add    $0xffffffff,%ebx
cltd
idiv   %ebx
mov    %eax,%ebp
add    %r15d,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @calculate_number_of_nodes(i32 %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %0, 1
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = add nsw i32 %2, 1
br label %17
7: ; preds = %3
%8 = sub nsw i32 %2, %1
%9 = tail call i32 @ipow(i32 %0, i32 %1)
%10 = mul nsw i32 %9, %8
%11 = add nsw i32 %1, 1
%12 = tail call i32 @ipow(i32 %0, i32 %11)
%13 = add nsw i32 %12, -1
%14 = add nsw i32 %0, -1
%15 = sdiv i32 %13, %14
%16 = add nsw i32 %15, %10
br label %17
17: ; preds = %7, %5
%18 = phi i32 [ %6, %5 ], [ %16, %7 ]
ret i32 %18
}