#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*/ forwd(int);
int heading();
int /*<<< orphan*/ hilbert_left(int, int);
int /*<<< orphan*/ setheading(int);
int /*<<< orphan*/ turnleft(int);
int /*<<< orphan*/ turnright(int);
void hilbert_right(int len, int level) {
  int bearing;
  if (level > 0) {
    bearing = heading();
    turnright(90);
    hilbert_left(len, level - 1);
    setheading(bearing);
    forwd(len);
    bearing = heading();
    hilbert_right(len, level - 1);
    setheading(bearing);
    turnright(90);
    forwd(len);
    bearing = heading();
    turnleft(90);
    hilbert_right(len, level - 1);
    setheading(bearing);
    turnright(90);
    forwd(len);
    bearing = heading();
    turnright(90);
    hilbert_left(len, level - 1);
    setheading(bearing);
  }
}


x86 assembly (clang, -O0):
<hilbert_right>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    1252 <hilbert_right+0xe2>
mov    $0x0,%al
call   1080 <heading@plt>
mov    %eax,-0xc(%rbp)
mov    $0x5a,%edi
call   1070 <turnright@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
call   1050 <hilbert_left@plt>
mov    -0xc(%rbp),%edi
call   1060 <setheading@plt>
mov    -0x4(%rbp),%edi
call   1090 <forwd@plt>
mov    $0x0,%al
call   1080 <heading@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
call   1040 <hilbert_right@plt>
mov    -0xc(%rbp),%edi
call   1060 <setheading@plt>
mov    $0x5a,%edi
call   1070 <turnright@plt>
mov    -0x4(%rbp),%edi
call   1090 <forwd@plt>
mov    $0x0,%al
call   1080 <heading@plt>
mov    %eax,-0xc(%rbp)
mov    $0x5a,%edi
call   1030 <turnleft@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
call   1040 <hilbert_right@plt>
mov    -0xc(%rbp),%edi
call   1060 <setheading@plt>
mov    $0x5a,%edi
call   1070 <turnright@plt>
mov    -0x4(%rbp),%edi
call   1090 <forwd@plt>
mov    $0x0,%al
call   1080 <heading@plt>
mov    %eax,-0xc(%rbp)
mov    $0x5a,%edi
call   1070 <turnright@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
call   1050 <hilbert_left@plt>
mov    -0xc(%rbp),%edi
call   1060 <setheading@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hilbert_right>:
test   %esi,%esi
jle    123a <hilbert_right+0xca>
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %edi,%ebp
xor    %eax,%eax
call   1080 <heading@plt>
mov    %eax,%r14d
mov    $0x5a,%edi
call   1070 <turnright@plt>
add    $0xffffffff,%ebx
mov    %ebp,%edi
mov    %ebx,%esi
call   1050 <hilbert_left@plt>
mov    %r14d,%edi
call   1060 <setheading@plt>
mov    %ebp,%edi
call   1090 <forwd@plt>
xor    %eax,%eax
call   1080 <heading@plt>
mov    %eax,%r14d
mov    %ebp,%edi
mov    %ebx,%esi
call   1040 <hilbert_right@plt>
mov    %r14d,%edi
call   1060 <setheading@plt>
mov    $0x5a,%edi
call   1070 <turnright@plt>
mov    %ebp,%edi
call   1090 <forwd@plt>
xor    %eax,%eax
call   1080 <heading@plt>
mov    %eax,%r14d
mov    $0x5a,%edi
call   1030 <turnleft@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1040 <hilbert_right@plt>
mov    %r14d,%edi
call   1060 <setheading@plt>
mov    $0x5a,%edi
call   1070 <turnright@plt>
mov    %ebp,%edi
call   1090 <forwd@plt>
xor    %eax,%eax
call   1080 <heading@plt>
mov    %eax,%r14d
mov    $0x5a,%edi
call   1070 <turnright@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1050 <hilbert_left@plt>
mov    %r14d,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <setheading@plt>
ret

LLVM IR (-O0):
define void @hilbert_right(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %46
8: ; preds = %2
%9 = call i32 (...) @heading()
store i32 %9, i32* %5
%10 = call i32 @turnright(i32 90)
%11 = load i32, i32* %3
%12 = load i32, i32* %4
%13 = sub nsw i32 %12, 1
%14 = call i32 @hilbert_left(i32 %11, i32 %13)
%15 = load i32, i32* %5
%16 = call i32 @setheading(i32 %15)
%17 = load i32, i32* %3
%18 = call i32 @forwd(i32 %17)
%19 = call i32 (...) @heading()
store i32 %19, i32* %5
%20 = load i32, i32* %3
%21 = load i32, i32* %4
%22 = sub nsw i32 %21, 1
%23 = load i32, i32* %5
%24 = call i32 @setheading(i32 %23)
%25 = call i32 @turnright(i32 90)
%26 = load i32, i32* %3
%27 = call i32 @forwd(i32 %26)
%28 = call i32 (...) @heading()
store i32 %28, i32* %5
%29 = call i32 @turnleft(i32 90)
%30 = load i32, i32* %3
%31 = load i32, i32* %4
%32 = sub nsw i32 %31, 1
%33 = load i32, i32* %5
%34 = call i32 @setheading(i32 %33)
%35 = call i32 @turnright(i32 90)
%36 = load i32, i32* %3
%37 = call i32 @forwd(i32 %36)
%38 = call i32 (...) @heading()
store i32 %38, i32* %5
%39 = call i32 @turnright(i32 90)
%40 = load i32, i32* %3
%41 = load i32, i32* %4
%42 = sub nsw i32 %41, 1
%43 = call i32 @hilbert_left(i32 %40, i32 %42)
%44 = load i32, i32* %5
%45 = call i32 @setheading(i32 %44)
br label %46
46: ; preds = %8, %2
ret void
}

LLVM IR (-O2):
define void @hilbert_right(i32 %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %5, label %4
4: ; preds = %2, %5
ret void
5: ; preds = %2
%6 = tail call i32 (...) @heading()
%7 = tail call i32 @turnright(i32 90)
%8 = add nsw i32 %1, -1
%9 = tail call i32 @hilbert_left(i32 %0, i32 %8)
%10 = tail call i32 @setheading(i32 %6)
%11 = tail call i32 @forwd(i32 %0)
%12 = tail call i32 (...) @heading()
tail call void @hilbert_right(i32 %0, i32 %8)
%13 = tail call i32 @setheading(i32 %12)
%14 = tail call i32 @turnright(i32 90)
%15 = tail call i32 @forwd(i32 %0)
%16 = tail call i32 (...) @heading()
%17 = tail call i32 @turnleft(i32 90)
tail call void @hilbert_right(i32 %0, i32 %8)
%18 = tail call i32 @setheading(i32 %16)
%19 = tail call i32 @turnright(i32 90)
%20 = tail call i32 @forwd(i32 %0)
%21 = tail call i32 (...) @heading()
%22 = tail call i32 @turnright(i32 90)
%23 = tail call i32 @hilbert_left(i32 %0, i32 %8)
%24 = tail call i32 @setheading(i32 %21)
br label %4
}