#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 pow2(int);
int end_interval(int count, int start, int max) {
  if (count == 0)
    return start;
  else if (count == 1)
    return max;
  else
    return end_interval(count - 1, start, max) +
           (max - start) * pow2(count - 1);
}


x86 assembly (clang, -O0):
<end_interval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1146 <end_interval+0x26>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1193 <end_interval+0x73>
cmpl   $0x1,-0x8(%rbp)
jne    115b <end_interval+0x3b>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1193 <end_interval+0x73>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <end_interval@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
call   1030 <pow2@plt>
mov    -0x18(%rbp),%ecx
mov    %eax,%edx
mov    -0x14(%rbp),%eax
imul   %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<end_interval>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
test   %edi,%edi
je     115d <end_interval+0x3d>
mov    %edx,%ebx
mov    %edi,%ebp
cmp    $0x1,%edi
je     1160 <end_interval+0x40>
add    $0xffffffff,%ebp
mov    %ebp,%edi
mov    %r14d,%esi
mov    %ebx,%edx
call   1040 <end_interval@plt>
mov    %eax,%r15d
sub    %r14d,%ebx
mov    %ebp,%edi
call   1030 <pow2@plt>
imul   %ebx,%eax
add    %r15d,%eax
mov    %eax,%ebx
jmp    1160 <end_interval+0x40>
mov    %r14d,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @end_interval(i32 %0, i32 %1, i32 %2) {
switch i32 %0, label %7 [
i32 0, label %5
i32 1, label %4
]
4: ; preds = %3
br label %5
5: ; preds = %4, %3, %7
%6 = phi i32 [ %13, %7 ], [ %2, %4 ], [ %1, %3 ]
ret i32 %6
7: ; preds = %3
%8 = add nsw i32 %0, -1
%9 = tail call i32 @end_interval(i32 %8, i32 %1, i32 %2)
%10 = sub nsw i32 %2, %1
%11 = tail call i32 @pow2(i32 %8)
%12 = mul nsw i32 %11, %10
%13 = add nsw i32 %12, %9
br label %5
}