int stepProblemByRecursion(int stepNumber) {
  if (stepNumber < 1) {
    return 0;
  }
  if (stepNumber == 1) {
    return 1;
  } else if (stepNumber == 2) {
    return 2;
  } else if (stepNumber == 3) {
    return 4;
  } else {
    return stepProblemByRecursion(stepNumber - 1) +
           stepProblemByRecursion(stepNumber - 2) +
           stepProblemByRecursion(stepNumber - 3);
  }
}


x86 assembly (clang, -O0):
<stepProblemByRecursion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jge    1131 <stepProblemByRecursion+0x21>
movl   $0x0,-0x4(%rbp)
jmp    11ab <stepProblemByRecursion+0x9b>
cmpl   $0x1,-0x8(%rbp)
jne    1147 <stepProblemByRecursion+0x37>
movl   $0x1,-0x4(%rbp)
jmp    11ab <stepProblemByRecursion+0x9b>
cmpl   $0x2,-0x8(%rbp)
jne    115d <stepProblemByRecursion+0x4d>
movl   $0x2,-0x4(%rbp)
jmp    11ab <stepProblemByRecursion+0x9b>
cmpl   $0x3,-0x8(%rbp)
jne    1173 <stepProblemByRecursion+0x63>
movl   $0x4,-0x4(%rbp)
jmp    11ab <stepProblemByRecursion+0x9b>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
call   1030 <stepProblemByRecursion@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x2,%edi
call   1030 <stepProblemByRecursion@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x3,%edi
call   1030 <stepProblemByRecursion@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stepProblemByRecursion>:
push   %rbp
push   %r14
push   %rbx
test   %edi,%edi
jle    1149 <stepProblemByRecursion+0x39>
mov    %edi,%ebx
xor    %r14d,%r14d
nopl   (%rax)
lea    -0x1(%rbx),%edi
cmp    $0x2,%edi
jb     1155 <stepProblemByRecursion+0x45>
cmp    $0x3,%ebx
je     1150 <stepProblemByRecursion+0x40>
call   1030 <stepProblemByRecursion@plt>
mov    %eax,%ebp
lea    -0x2(%rbx),%edi
call   1030 <stepProblemByRecursion@plt>
add    $0xfffffffd,%ebx
add    %r14d,%ebp
add    %eax,%ebp
mov    %ebp,%r14d
jmp    1120 <stepProblemByRecursion+0x10>
xor    %r14d,%r14d
xor    %ebx,%ebx
jmp    1155 <stepProblemByRecursion+0x45>
mov    $0x4,%ebx
add    %ebx,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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