#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 /*<<< orphan*/ printf(char *, unsigned long);
int /*<<< orphan*/ scanf(char *, unsigned int *, unsigned int *);
int main() {
  int i;
  unsigned int k, n;
  unsigned long int gfib[41];
  scanf("%d %d", &n, &k);
  gfib[0] = 0;
  gfib[1] = 1;
  gfib[2] = 1;
  for (i = 3; i <= 40; i++) {
    gfib[i] = gfib[i - 1] + k * gfib[i - 2];
  }
  printf("%ld\n", gfib[n]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <scanf@plt>
movq   $0x0,-0x160(%rbp)
movq   $0x1,-0x158(%rbp)
movq   $0x1,-0x150(%rbp)
movl   $0x3,-0x8(%rbp)
cmpl   $0x28,-0x8(%rbp)
jg     11ba <main+0x9a>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x160(%rbp,%rax,8),%rcx
ff
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%edx
sub    $0x2,%edx
movslq %edx,%rdx
imul   -0x160(%rbp,%rdx,8),%rax
ff ff
add    %rax,%rcx
movslq -0x8(%rbp),%rax
mov    %rcx,-0x160(%rbp,%rax,8)
ff
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116e <main+0x4e>
mov    -0x10(%rbp),%eax
mov    -0x160(%rbp,%rax,8),%rsi
ff
lea    0xe3a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x158,%rsp
lea    0xee2(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1040 <scanf@plt>
movaps 0xebc(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movq   $0x1,0x20(%rsp)
mov    0xc(%rsp),%eax
lea    0x1(%rax),%rdx
mov    %rdx,0x28(%rsp)
mov    $0x5,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    -0x8(%rsp,%rcx,8),%rsi
imul   %rax,%rsi
add    %rdx,%rsi
mov    %rsi,0x8(%rsp,%rcx,8)
cmp    $0x29,%rcx
je     119d <main+0x7d>
mov    (%rsp,%rcx,8),%rdx
imul   %rax,%rdx
add    %rsi,%rdx
mov    %rdx,0x10(%rsp,%rcx,8)
add    $0x2,%rcx
jmp    1170 <main+0x50>
mov    0x8(%rsp),%eax
mov    0x10(%rsp,%rax,8),%rsi
lea    0xe69(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x158,%rsp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [41 x i64]
store i32 0, i32* %1
%6 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %4, i32* %3)
%7 = getelementptr inbounds [41 x i64], [41 x i64]* %5, i64 0, i64 0
store i64 0, i64* %7
%8 = getelementptr inbounds [41 x i64], [41 x i64]* %5, i64 0, i64 1
store i64 1, i64* %8
%9 = getelementptr inbounds [41 x i64], [41 x i64]* %5, i64 0, i64 2
store i64 1, i64* %9
store i32 3, i32* %2
br label %10
10: ; preds = %31, %0
%11 = load i32, i32* %2
%12 = icmp sle i32 %11, 40
br i1 %12, label %13, label %34
13: ; preds = %10
%14 = load i32, i32* %2
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [41 x i64], [41 x i64]* %5, i64 0, i64 %16
%18 = load i64, i64* %17
%19 = load i32, i32* %3
%20 = zext i32 %19 to i64
%21 = load i32, i32* %2
%22 = sub nsw i32 %21, 2
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [41 x i64], [41 x i64]* %5, i64 0, i64 %23
%25 = load i64, i64* %24
%26 = mul i64 %20, %25
%27 = add i64 %18, %26
%28 = load i32, i32* %2
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [41 x i64], [41 x i64]* %5, i64 0, i64 %29
store i64 %27, i64* %30
br label %31
31: ; preds = %13
%32 = load i32, i32* %2
%33 = add nsw i32 %32, 1
store i32 %33, i32* %2
br label %10
34: ; preds = %10
%35 = load i32, i32* %4
%36 = zext i32 %35 to i64
%37 = getelementptr inbounds [41 x i64], [41 x i64]* %5, i64 0, i64 %36
%38 = load i64, i64* %37
%39 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [41 x i64]
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast [41 x i64]* %3 to i8*
%7 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %1)
%8 = bitcast [41 x i64]* %3 to <2 x i64>*
store <2 x i64> <i64 0, i64 1>, <2 x i64>* %8
%9 = getelementptr inbounds [41 x i64], [41 x i64]* %3, i64 0, i64 2
store i64 1, i64* %9
%10 = load i32, i32* %1
%11 = zext i32 %10 to i64
%12 = add nuw nsw i64 %11, 1
%13 = getelementptr inbounds [41 x i64], [41 x i64]* %3, i64 0, i64 3
store i64 %12, i64* %13
br label %14
14: ; preds = %26, %0
%15 = phi i64 [ 4, %0 ], [ %33, %26 ]
%16 = phi i64 [ %12, %0 ], [ %31, %26 ]
%17 = phi i64 [ 3, %0 ], [ %24, %26 ]
%18 = add nsw i64 %17, -1
%19 = getelementptr inbounds [41 x i64], [41 x i64]* %3, i64 0, i64 %18
%20 = load i64, i64* %19
%21 = mul i64 %20, %11
%22 = add i64 %21, %16
%23 = getelementptr inbounds [41 x i64], [41 x i64]* %3, i64 0, i64 %15
store i64 %22, i64* %23
%24 = or i64 %15, 1
%25 = icmp eq i64 %24, 41
br i1 %25, label %34, label %26
26: ; preds = %14
%27 = add nsw i64 %15, -1
%28 = getelementptr inbounds [41 x i64], [41 x i64]* %3, i64 0, i64 %27
%29 = load i64, i64* %28
%30 = mul i64 %29, %11
%31 = add i64 %30, %22
%32 = getelementptr inbounds [41 x i64], [41 x i64]* %3, i64 0, i64 %24
store i64 %31, i64* %32
%33 = add nuw nsw i64 %15, 2
br label %14
34: ; preds = %14
%35 = load i32, i32* %2
%36 = zext i32 %35 to i64
%37 = getelementptr inbounds [41 x i64], [41 x i64]* %3, i64 0, i64 %36
%38 = load i64, i64* %37
%39 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %38)
ret i32 0
}