#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 fibonacci(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
double mod_1(double);
int /*<<< orphan*/ stderr;
void fibonacci_lattice_2D(double *x, int k) {
  int i;
  int f1 = fibonacci(k - 1);
  int f2 = fibonacci(k);
  if (k < 3) {
    fprintf(stderr, "k must be >= 3.\n");
    return;
  }
  for (i = 0; i < f2 - 1; i++) {
    x[2 * i + 0] = (double)i / (double)f2;
    x[2 * i + 1] = mod_1((double)(i * f1) / (double)f2);
  }
}


x86 assembly (clang, -O0):
<fibonacci_lattice_2D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
sub    $0x1,%edi
call   1040 <fibonacci@plt>
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <fibonacci@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x3,-0xc(%rbp)
jge    117c <fibonacci_lattice_2D+0x4c>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
lea    0xe8e(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11f3 <fibonacci_lattice_2D+0xc3>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11f3 <fibonacci_lattice_2D+0xc3>
cvtsi2sdl -0x10(%rbp),%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
shl    $0x1,%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
cvtsi2sd %eax,%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1050 <mod_1@plt>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1183 <fibonacci_lattice_2D+0x53>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fibonacci_lattice_2D>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r13
lea    -0x1(%r15),%edi
call   1040 <fibonacci@plt>
mov    %eax,%r14d
mov    %r15d,%edi
call   1040 <fibonacci@plt>
cmp    $0x3,%r15d
jge    117e <fibonacci_lattice_2D+0x4e>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
lea    0xe95(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fprintf@plt>
mov    %eax,%r12d
cmp    $0x2,%eax
jl     11dc <fibonacci_lattice_2D+0xac>
cvtsi2sd %r12d,%xmm0
movsd  %xmm0,(%rsp)
add    $0xffffffff,%r12d
add    $0x8,%r13
xor    %ebp,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  (%rsp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%r13)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
divsd  %xmm1,%xmm0
call   1050 <mod_1@plt>
movsd  %xmm0,0x0(%r13)
add    $0x1,%rbx
add    %r14d,%ebp
add    $0x10,%r13
cmp    %rbx,%r12
jne    11a0 <fibonacci_lattice_2D+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [17 x i8] c"k must be >= 3.\0A\00"
define void @fibonacci_lattice_2D(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store double* %0, double** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = sub nsw i32 %8, 1
%10 = call i32 @fibonacci(i32 %9)
store i32 %10, i32* %6
%11 = load i32, i32* %4
%12 = call i32 @fibonacci(i32 %11)
store i32 %12, i32* %7
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 3
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %53
18: ; preds = %2
store i32 0, i32* %5
br label %19
19: ; preds = %50, %18
%20 = load i32, i32* %5
%21 = load i32, i32* %7
%22 = sub nsw i32 %21, 1
%23 = icmp slt i32 %20, %22
br i1 %23, label %24, label %53
24: ; preds = %19
%25 = load i32, i32* %5
%26 = sitofp i32 %25 to double
%27 = load i32, i32* %7
%28 = sitofp i32 %27 to double
%29 = fdiv double %26, %28
%30 = load double*, double** %3
%31 = load i32, i32* %5
%32 = mul nsw i32 2, %31
%33 = add nsw i32 %32, 0
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %30, i64 %34
store double %29, double* %35
%36 = load i32, i32* %5
%37 = load i32, i32* %6
%38 = mul nsw i32 %36, %37
%39 = sitofp i32 %38 to double
%40 = load i32, i32* %7
%41 = sitofp i32 %40 to double
%42 = fdiv double %39, %41
%43 = call double @mod_1(double %42)
%44 = load double*, double** %3
%45 = load i32, i32* %5
%46 = mul nsw i32 2, %45
%47 = add nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %44, i64 %48
store double %43, double* %49
br label %50
50: ; preds = %24
%51 = load i32, i32* %5
%52 = add nsw i32 %51, 1
store i32 %52, i32* %5
br label %19
53: ; preds = %15, %19
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"k must be >= 3.\0A\00"
define void @fibonacci_lattice_2D(double* nocapture writeonly %0, i32 %1) {
%3 = add nsw i32 %1, -1
%4 = tail call i32 @fibonacci(i32 %3)
%5 = tail call i32 @fibonacci(i32 %1)
%6 = icmp slt i32 %1, 3
br i1 %6, label %13, label %7
7: ; preds = %2
%8 = icmp sgt i32 %5, 1
br i1 %8, label %9, label %32
9: ; preds = %7
%10 = add nsw i32 %5, -1
%11 = sitofp i32 %5 to double
%12 = zext i32 %10 to i64
br label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %32
16: ; preds = %9, %16
%17 = phi i64 [ 0, %9 ], [ %30, %16 ]
%18 = trunc i64 %17 to i32
%19 = sitofp i32 %18 to double
%20 = fdiv double %19, %11
%21 = shl nuw nsw i64 %17, 1
%22 = getelementptr inbounds double, double* %0, i64 %21
store double %20, double* %22
%23 = trunc i64 %17 to i32
%24 = mul i32 %4, %23
%25 = sitofp i32 %24 to double
%26 = fdiv double %25, %11
%27 = tail call double @mod_1(double %26)
%28 = or i64 %21, 1
%29 = getelementptr inbounds double, double* %0, i64 %28
store double %27, double* %29
%30 = add nuw nsw i64 %17, 1
%31 = icmp eq i64 %30, %12
br i1 %31, label %32, label %16
32: ; preds = %16, %7, %13
ret void
}