#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 */
scalar_t__ ceil(int);
int /*<<< orphan*/ forwd(int);
int /*<<< orphan*/ turnleft(int);
int /*<<< orphan*/ turnright(int);
void koch(int len, int level) {
  int newlen;
  if (0 == level) {
    forwd(len);
    return;
  } else {
    newlen = (int)ceil(len / 3.0);
    koch(newlen, level - 1);
    turnleft(60);
    koch(newlen, level - 1);
    turnright(120);
    koch(newlen, level - 1);
    turnleft(60);
    koch(newlen, level - 1);
  }
}


x86 assembly (clang, -O0):
<koch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%eax
jne    1176 <koch+0x26>
mov    -0x4(%rbp),%edi
call   1070 <forwd@plt>
jmp    11e9 <koch+0x99>
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  0xe7d(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <ceil@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
call   1050 <koch@plt>
mov    $0x3c,%edi
call   1040 <turnleft@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
call   1050 <koch@plt>
mov    $0x78,%edi
call   1060 <turnright@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
call   1050 <koch@plt>
mov    $0x3c,%edi
call   1040 <turnleft@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
call   1050 <koch@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<koch>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
test   %esi,%esi
je     11b9 <koch+0x69>
mov    %esi,%ebp
add    $0xffffffff,%ebp
xchg   %ax,%ax
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
divsd  0xe91(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <ceil@plt>
mov    %rax,%rbx
mov    %ebx,%edi
mov    %ebp,%esi
call   1050 <koch@plt>
mov    $0x3c,%edi
call   1040 <turnleft@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   1050 <koch@plt>
mov    $0x78,%edi
call   1060 <turnright@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   1050 <koch@plt>
mov    $0x3c,%edi
call   1040 <turnleft@plt>
add    $0xffffffff,%ebp
jb     1160 <koch+0x10>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1070 <forwd@plt>

LLVM IR (-O0):
define void @koch(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 eq i32 0, %6
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* %3
%10 = call i32 @forwd(i32 %9)
br label %33
11: ; preds = %2
%12 = load i32, i32* %3
%13 = sitofp i32 %12 to double
%14 = fdiv double %13, 3.000000e+00
%15 = fptosi double %14 to i32
%16 = call i64 @ceil(i32 %15)
%17 = trunc i64 %16 to i32
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = load i32, i32* %4
%20 = sub nsw i32 %19, 1
%21 = call i32 @turnleft(i32 60)
%22 = load i32, i32* %5
%23 = load i32, i32* %4
%24 = sub nsw i32 %23, 1
%25 = call i32 @turnright(i32 120)
%26 = load i32, i32* %5
%27 = load i32, i32* %4
%28 = sub nsw i32 %27, 1
%29 = call i32 @turnleft(i32 60)
%30 = load i32, i32* %5
%31 = load i32, i32* %4
%32 = sub nsw i32 %31, 1
br label %33
33: ; preds = %8, %11
ret void
}

LLVM IR (-O2):
define void @koch(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %6, label %9
4: ; preds = %9
%5 = trunc i64 %15 to i32
br label %6
6: ; preds = %4, %2
%7 = phi i32 [ %0, %2 ], [ %5, %4 ]
%8 = tail call i32 @forwd(i32 %7)
ret void
9: ; preds = %2, %9
%10 = phi i32 [ %17, %9 ], [ %1, %2 ]
%11 = phi i32 [ %16, %9 ], [ %0, %2 ]
%12 = sitofp i32 %11 to double
%13 = fdiv double %12, 3.000000e+00
%14 = fptosi double %13 to i32
%15 = tail call i64 @ceil(i32 %14)
%16 = trunc i64 %15 to i32
%17 = add nsw i32 %10, -1
tail call void @koch(i32 %16, i32 %17)
%18 = tail call i32 @turnleft(i32 60)
tail call void @koch(i32 %16, i32 %17)
%19 = tail call i32 @turnright(i32 120)
tail call void @koch(i32 %16, i32 %17)
%20 = tail call i32 @turnleft(i32 60)
%21 = icmp eq i32 %17, 0
br i1 %21, label %4, label %9
}