.include "include/uskel.s"

.include "include/listops.s"
.include "include/intops.s"
.include "include/io.s"
.include "include/main_exit.s"

# | lag1 | lag2 | -> cont
.thunkcode fibs
	# next value
	thunkto %r11, $plus, $2, 020(%rbp), 030(%rbp)

	# fib call with the next value
	thunkto %r12, $fibs, $2, 030(%rbp), %r11

	# cons list with the lagged arg
	thunkto %r13, $LIST_code, $1, 020(%rbp), %r12

	# TODO simplify
	# replace self with IND
	mov %r13, 010(%rbp)
	movq $IND_code, 0(%rbp)

	mov %rsi, %rbp
	mov %r13, %rsi
	enter_rbp

# || -> cont
.thunkcode fibs0
	thunkto %r12, $INT_code, $1
	thunkto %r11, $INT_code, $0
	thunkto %rbp, $fibs, $2, %r11, %r12
	enter_rbp

.thunkcode main
	thunkto %r12, $fibs0, $0
	thunkto %r11, $INT_code, $20
	thunkto %r11, $list_int_index, $2, %r11, %r12
	thunkto %r11, $print, $1, %r11
	thunkto %rsi, $main_exit, $1, %rsi
	enter %r11