#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ countWays(int, unsigned long long *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int steps = 0;
  printf("Please enter number of steps: ");
  scanf("%i", &steps);
  unsigned long long int *cache = (unsigned long long int *)calloc(
      steps + 1, sizeof(unsigned long long int));
  for (int i = 0; i <= steps; i++) {
    cache[i] = 0;
  }
  printf("Number of ways is: %llu\n", countWays(steps, cache));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb4(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x8(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11b9 <main+0x79>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118f <main+0x4f>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <countWays@plt>
mov    %eax,%esi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
lea    0xe9d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeae(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x4(%rsp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%r14
mov    0x4(%rsp),%ebx
test   %ebx,%ebx
js     11a9 <main+0x59>
lea    0x8(,%rbx,8),%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <countWays@plt>
lea    0xe68(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Please enter number of steps: \00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [25 x i8] c"Number of ways is: %llu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64*
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %2
%8 = add nsw i32 %7, 1
%9 = call i64 @calloc(i32 %8, i32 8)
%10 = inttoptr i64 %9 to i64*
store i64* %10, i64** %3
store i32 0, i32* %4
br label %11
11: ; preds = %20, %0
%12 = load i32, i32* %4
%13 = load i32, i32* %2
%14 = icmp sle i32 %12, %13
br i1 %14, label %15, label %23
15: ; preds = %11
%16 = load i64*, i64** %3
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i64, i64* %16, i64 %18
store i64 0, i64* %19
br label %20
20: ; preds = %15
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %11
23: ; preds = %11
%24 = load i32, i32* %2
%25 = load i64*, i64** %3
%26 = call i32 @countWays(i32 %24, i64* %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %26)
ret i32 0
}

LLVM IR (-O2):
@.str = [31 x i8] c"Please enter number of steps: \00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [25 x i8] c"Number of ways is: %llu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = add nsw i32 %5, 1
%7 = call i64 @calloc(i32 %6, i32 8)
%8 = load i32, i32* %1
%9 = icmp slt i32 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %0
%11 = inttoptr i64 %7 to i8*
%12 = zext i32 %8 to i64
%13 = shl nuw nsw i64 %12, 3
%14 = add nuw nsw i64 %13, 8
br label %15
15: ; preds = %10, %0
%16 = inttoptr i64 %7 to i64*
%17 = call i32 @countWays(i32 %8, i64* %16)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %17)
ret i32 0
}