#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, long);
long read_number(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  long i, j;
  long n, k, o;
  if (argc < 3) {
    fprintf(stderr, "usage: %s N K\n", argv[0]);
    exit(1);
  }
  n = read_number(argv[1]);
  k = read_number(argv[2]);
  for (i = 1, j = 0; n > 1; o = i, n--, i = i + (j * k), j = o)
    ;
  printf("%ld\n", i);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1186 <main+0x46>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe89(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <read_number@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <read_number@plt>
mov    %rax,-0x30(%rbp)
movq   $0x1,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x1,-0x28(%rbp)
jle    11fd <main+0xbd>
jmp    11c8 <main+0x88>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
imul   -0x30(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11b8 <main+0x78>
mov    -0x18(%rbp),%rsi
lea    0xe07(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x2,%edi
jle    11b0 <main+0x70>
mov    0x8(%r14),%rdi
call   1050 <read_number@plt>
mov    %rax,%rbx
mov    0x10(%r14),%rdi
call   1050 <read_number@plt>
mov    $0x1,%esi
cmp    $0x2,%rbx
jl     119a <main+0x5a>
add    $0x1,%rbx
mov    $0x1,%esi
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
mov    %rsi,%rdx
imul   %rax,%rcx
mov    %rcx,%rsi
add    %rdx,%rsi
add    $0xffffffffffffffff,%rbx
mov    %rdx,%rcx
cmp    $0x2,%rbx
ja     1180 <main+0x40>
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe3d(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"usage: %s N K\0A\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i64 @read_number(i8* %23)
store i64 %24, i64* %8
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i64 @read_number(i8* %27)
store i64 %28, i64* %9
store i64 1, i64* %6
store i64 0, i64* %7
br label %29
29: ; preds = %33, %20
%30 = load i64, i64* %8
%31 = icmp sgt i64 %30, 1
br i1 %31, label %32, label %43
32: ; preds = %29
br label %33
33: ; preds = %32
%34 = load i64, i64* %6
store i64 %34, i64* %10
%35 = load i64, i64* %8
%36 = add nsw i64 %35, -1
store i64 %36, i64* %8
%37 = load i64, i64* %6
%38 = load i64, i64* %7
%39 = load i64, i64* %9
%40 = mul nsw i64 %38, %39
%41 = add nsw i64 %37, %40
store i64 %41, i64* %6
%42 = load i64, i64* %10
store i64 %42, i64* %7
br label %29
43: ; preds = %29
%44 = load i64, i64* %6
%45 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %44)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"usage: %s N K\0A\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @read_number(i8* %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i64 @read_number(i8* %14)
%16 = icmp sgt i64 %12, 1
br i1 %16, label %17, label %25
17: ; preds = %9, %17
%18 = phi i64 [ %23, %17 ], [ 1, %9 ]
%19 = phi i64 [ %18, %17 ], [ 0, %9 ]
%20 = phi i64 [ %21, %17 ], [ %12, %9 ]
%21 = add nsw i64 %20, -1
%22 = mul nsw i64 %19, %15
%23 = add nsw i64 %18, %22
%24 = icmp ugt i64 %20, 2
br i1 %24, label %17, label %25
25: ; preds = %17, %9
%26 = phi i64 [ 1, %9 ], [ %23, %17 ]
%27 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %26)
ret i32 0
}