#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*/ printf(char const *, ...);
void turtle_print_n_times(const char *action, long n) {
  if (n == 0)
    return;
  if (n > 1)
    printf("for i = 0, %ld, 1 do\n", n - 1);
  printf(action);
  if (n > 1)
    printf("end\n");
}


x86 assembly (clang, -O0):
<turtle_print_n_times>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1130 <turtle_print_n_times+0x20>
jmp    1175 <turtle_print_n_times+0x65>
cmpq   $0x1,-0x10(%rbp)
jle    1151 <turtle_print_n_times+0x41>
mov    -0x10(%rbp),%rsi
sub    $0x1,%rsi
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x1,-0x10(%rbp)
jle    1175 <turtle_print_n_times+0x65>
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<turtle_print_n_times>:
push   %rbx
test   %rsi,%rsi
je     1158 <turtle_print_n_times+0x38>
mov    %rdi,%rbx
cmp    $0x2,%rsi
jl     115a <turtle_print_n_times+0x3a>
add    $0xffffffffffffffff,%rsi
lea    0xec6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec4(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>
pop    %rbx
ret
mov    %rbx,%rdi
xor    %eax,%eax
pop    %rbx
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"for i = 0, %ld, 1 do\0A\00"
@.str.1 = [5 x i8] c"end\0A\00"
define void @turtle_print_n_times(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%5 = load i64, i64* %4
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %2
br label %22
8: ; preds = %2
%9 = load i64, i64* %4
%10 = icmp sgt i64 %9, 1
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = load i64, i64* %4
%13 = sub nsw i64 %12, 1
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i64 %13)
br label %15
15: ; preds = %11, %8
%16 = load i8*, i8** %3
%17 = call i32 (i8*, ...) @printf(i8* %16)
%18 = load i64, i64* %4
%19 = icmp sgt i64 %18, 1
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %7, %20, %15
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"for i = 0, %ld, 1 do\0A\00"
@str = [4 x i8] c"end\00"
define void @turtle_print_n_times(i8* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %13, label %4
4: ; preds = %2
%5 = icmp sgt i64 %1, 1
br i1 %5, label %6, label %11
6: ; preds = %4
%7 = add nsw i64 %1, -1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i64 %7)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %0)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
br label %13
11: ; preds = %4
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %0)
br label %13
13: ; preds = %11, %2, %6
ret void
}