#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*/ go_forward(void *, int);
int /*<<< orphan*/ turn_left(int);
void hilbert_recurse(void *img, int n, int parity, int dist) {
  if (n == 0)
    return;
  turn_left(parity * 90);
  hilbert_recurse(img, n - 1, -parity, dist);
  go_forward(img, dist);
  turn_left(-parity * 90);
  hilbert_recurse(img, n - 1, +parity, dist);
  go_forward(img, dist);
  hilbert_recurse(img, n - 1, +parity, dist);
  turn_left(-parity * 90);
  go_forward(img, dist);
  hilbert_recurse(img, n - 1, -parity, dist);
  turn_left(parity * 90);
}


x86 assembly (clang, -O0):
<hilbert_recurse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1154 <hilbert_recurse+0x24>
jmp    11fc <hilbert_recurse+0xcc>
imul   $0x5a,-0x10(%rbp),%edi
call   1050 <turn_left@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
xor    %edx,%edx
sub    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1030 <hilbert_recurse@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <go_forward@plt>
xor    %eax,%eax
sub    -0x10(%rbp),%eax
imul   $0x5a,%eax,%edi
call   1050 <turn_left@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1030 <hilbert_recurse@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <go_forward@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1030 <hilbert_recurse@plt>
xor    %eax,%eax
sub    -0x10(%rbp),%eax
imul   $0x5a,%eax,%edi
call   1050 <turn_left@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <go_forward@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
xor    %edx,%edx
sub    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1030 <hilbert_recurse@plt>
imul   $0x5a,-0x10(%rbp),%edi
call   1050 <turn_left@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hilbert_recurse>:
test   %esi,%esi
je     11ef <hilbert_recurse+0xbf>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%r13d
mov    %esi,%ebp
mov    %rdi,%rbx
imul   $0x5a,%edx,%edi
mov    %edi,0x4(%rsp)
call   1050 <turn_left@plt>
add    $0xffffffff,%ebp
mov    %r13d,%r12d
neg    %r12d
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r12d,%edx
mov    %r15d,%ecx
call   1030 <hilbert_recurse@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1040 <go_forward@plt>
imul   $0xffffffa6,%r13d,%r14d
mov    %r14d,%edi
call   1050 <turn_left@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r13d,%edx
mov    %r15d,%ecx
call   1030 <hilbert_recurse@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1040 <go_forward@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r13d,%edx
mov    %r15d,%ecx
call   1030 <hilbert_recurse@plt>
mov    %r14d,%edi
call   1050 <turn_left@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1040 <go_forward@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r12d,%edx
mov    %r15d,%ecx
call   1030 <hilbert_recurse@plt>
mov    0x4(%rsp),%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <turn_left@plt>
ret

LLVM IR (-O0):
define void @hilbert_recurse(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %4
br label %58
12: ; preds = %4
%13 = load i32, i32* %7
%14 = mul nsw i32 %13, 90
%15 = call i32 @turn_left(i32 %14)
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = sub nsw i32 %17, 1
%19 = load i32, i32* %7
%20 = sub nsw i32 0, %19
%21 = load i32, i32* %8
%22 = load i8*, i8** %5
%23 = load i32, i32* %8
%24 = call i32 @go_forward(i8* %22, i32 %23)
%25 = load i32, i32* %7
%26 = sub nsw i32 0, %25
%27 = mul nsw i32 %26, 90
%28 = call i32 @turn_left(i32 %27)
%29 = load i8*, i8** %5
%30 = load i32, i32* %6
%31 = sub nsw i32 %30, 1
%32 = load i32, i32* %7
%33 = load i32, i32* %8
%34 = load i8*, i8** %5
%35 = load i32, i32* %8
%36 = call i32 @go_forward(i8* %34, i32 %35)
%37 = load i8*, i8** %5
%38 = load i32, i32* %6
%39 = sub nsw i32 %38, 1
%40 = load i32, i32* %7
%41 = load i32, i32* %8
%42 = load i32, i32* %7
%43 = sub nsw i32 0, %42
%44 = mul nsw i32 %43, 90
%45 = call i32 @turn_left(i32 %44)
%46 = load i8*, i8** %5
%47 = load i32, i32* %8
%48 = call i32 @go_forward(i8* %46, i32 %47)
%49 = load i8*, i8** %5
%50 = load i32, i32* %6
%51 = sub nsw i32 %50, 1
%52 = load i32, i32* %7
%53 = sub nsw i32 0, %52
%54 = load i32, i32* %8
%55 = load i32, i32* %7
%56 = mul nsw i32 %55, 90
%57 = call i32 @turn_left(i32 %56)
br label %58
58: ; preds = %12, %11
ret void
}

LLVM IR (-O2):
define void @hilbert_recurse(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %1, 0
br i1 %5, label %6, label %7
6: ; preds = %4, %7
ret void
7: ; preds = %4
%8 = mul nsw i32 %2, 90
%9 = tail call i32 @turn_left(i32 %8)
%10 = add nsw i32 %1, -1
%11 = sub nsw i32 0, %2
tail call void @hilbert_recurse(i8* %0, i32 %10, i32 %11, i32 %3)
%12 = tail call i32 @go_forward(i8* %0, i32 %3)
%13 = mul i32 %2, -90
%14 = tail call i32 @turn_left(i32 %13)
tail call void @hilbert_recurse(i8* %0, i32 %10, i32 %2, i32 %3)
%15 = tail call i32 @go_forward(i8* %0, i32 %3)
tail call void @hilbert_recurse(i8* %0, i32 %10, i32 %2, i32 %3)
%16 = tail call i32 @turn_left(i32 %13)
%17 = tail call i32 @go_forward(i8* %0, i32 %3)
tail call void @hilbert_recurse(i8* %0, i32 %10, i32 %11, i32 %3)
%18 = tail call i32 @turn_left(i32 %8)
br label %6
}