int minCostClimbingStairs(int *cost, int costSize) {
  if (costSize <= 1) {
    return 0;
  }
  int m1 = *cost + minCostClimbingStairs(cost + 1, costSize - 1);
  int m2 = *(cost + 1) + minCostClimbingStairs(cost + 2, costSize - 2);
  return m1 > m2 ? m2 : m1;
}


x86 assembly (clang, -O0):
<minCostClimbingStairs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jg     1135 <minCostClimbingStairs+0x25>
movl   $0x0,-0x4(%rbp)
jmp    11a5 <minCostClimbingStairs+0x95>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x4,%rdi
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
call   1030 <minCostClimbingStairs@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
mov    -0x14(%rbp),%esi
sub    $0x2,%esi
call   1030 <minCostClimbingStairs@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    1199 <minCostClimbingStairs+0x89>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    119f <minCostClimbingStairs+0x8f>
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<minCostClimbingStairs>:
xor    %eax,%eax
cmp    $0x1,%esi
jle    1162 <minCostClimbingStairs+0x52>
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
mov    (%rdi),%r15d
add    $0x4,%rdi
lea    -0x1(%r14),%esi
call   1030 <minCostClimbingStairs@plt>
mov    %eax,%ebp
add    %r15d,%ebp
mov    0x4(%rbx),%r15d
add    $0x8,%rbx
add    $0xfffffffe,%r14d
mov    %rbx,%rdi
mov    %r14d,%esi
call   1030 <minCostClimbingStairs@plt>
add    %r15d,%eax
cmp    %eax,%ebp
cmovle %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @minCostClimbingStairs(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = icmp sle i32 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 0, i32* %3
br label %38
11: ; preds = %2
%12 = load i32*, i32** %4
%13 = load i32, i32* %12
%14 = load i32*, i32** %4
%15 = getelementptr inbounds i32, i32* %14, i64 1
%16 = load i32, i32* %5
%17 = sub nsw i32 %16, 1
%18 = call i32 @minCostClimbingStairs(i32* %15, i32 %17)
%19 = add nsw i32 %13, %18
store i32 %19, i32* %6
%20 = load i32*, i32** %4
%21 = getelementptr inbounds i32, i32* %20, i64 1
%22 = load i32, i32* %21
%23 = load i32*, i32** %4
%24 = getelementptr inbounds i32, i32* %23, i64 2
%25 = load i32, i32* %5
%26 = sub nsw i32 %25, 2
%27 = call i32 @minCostClimbingStairs(i32* %24, i32 %26)
%28 = add nsw i32 %22, %27
store i32 %28, i32* %7
%29 = load i32, i32* %6
%30 = load i32, i32* %7
%31 = icmp sgt i32 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %11
%33 = load i32, i32* %7
br label %36
34: ; preds = %11
%35 = load i32, i32* %6
br label %36
36: ; preds = %34, %32
%37 = phi i32 [ %33, %32 ], [ %35, %34 ]
store i32 %37, i32* %3
br label %38
38: ; preds = %36, %10
%39 = load i32, i32* %3
ret i32 %39
}

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