#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 *, unsigned long, char *);
void printHistory(char **commands, unsigned long size, unsigned long current) {
  if (!commands)
    return;
  unsigned long i = 1;
  if (current > size)
    i = current - size + 1;
  for (; i <= current; i++)
    printf("\t%lu: %s\n", i, commands[(i - 1) % size]);
}


x86 assembly (clang, -O0):
<printHistory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1134 <printHistory+0x24>
jmp    11ae <printHistory+0x9e>
movq   $0x1,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jbe    115a <printHistory+0x4a>
mov    -0x18(%rbp),%rax
sub    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115f <printHistory+0x4f>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
ja     11ae <printHistory+0x9e>
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
sub    $0x1,%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax,%rdx,8),%rdx
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115f <printHistory+0x4f>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printHistory>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1141 <printHistory+0x31>
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdx,%rax
sub    %rsi,%rax
add    $0x1,%rax
cmp    %rsi,%rdx
mov    $0x1,%ecx
cmova  %rax,%rcx
cmp    %rdx,%rcx
jbe    1150 <printHistory+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rdi,%r15
xor    %ebx,%ebx
mov    %r14,%rax
sub    %r12,%rax
cmovae %rax,%rbx
lea    0xe9a(%rip),%r13
jmp    1193 <printHistory+0x83>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rax
xor    %edx,%edx
div    %r12
mov    (%r15,%rdx,8),%rdx
mov    %r13,%rdi
mov    %rbp,%rsi
call   1030 <printf@plt>
add    $0x2,%rbx
cmp    %r14,%rbx
mov    %rbp,%rbx
ja     1141 <printHistory+0x31>
lea    0x1(%rbx),%rbp
mov    %rbx,%rax
or     %r12,%rax
shr    $0x20,%rax
jne    1170 <printHistory+0x60>
mov    %ebx,%eax
xor    %edx,%edx
div    %r12d
jmp    1178 <printHistory+0x68>

LLVM IR (-O0):
@.str = [10 x i8] c"\09%lu: %s\0A\00"
define void @printHistory(i8** %0, i64 %1, i64 %2) {
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i8** %0, i8*** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%8 = load i8**, i8*** %4
%9 = icmp ne i8** %8, null
br i1 %9, label %11, label %10
10: ; preds = %3
br label %38
11: ; preds = %3
store i64 1, i64* %7
%12 = load i64, i64* %6
%13 = load i64, i64* %5
%14 = icmp ugt i64 %12, %13
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i64, i64* %6
%17 = load i64, i64* %5
%18 = sub i64 %16, %17
%19 = add i64 %18, 1
store i64 %19, i64* %7
br label %20
20: ; preds = %15, %11
br label %21
21: ; preds = %35, %20
%22 = load i64, i64* %7
%23 = load i64, i64* %6
%24 = icmp ule i64 %22, %23
br i1 %24, label %25, label %38
25: ; preds = %21
%26 = load i64, i64* %7
%27 = load i8**, i8*** %4
%28 = load i64, i64* %7
%29 = sub i64 %28, 1
%30 = load i64, i64* %5
%31 = urem i64 %29, %30
%32 = getelementptr inbounds i8*, i8** %27, i64 %31
%33 = load i8*, i8** %32
%34 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 %26, i8* %33)
br label %35
35: ; preds = %25
%36 = load i64, i64* %7
%37 = add i64 %36, 1
store i64 %37, i64* %7
br label %21
38: ; preds = %10, %21
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"\09%lu: %s\0A\00"
define void @printHistory(i8** %0, i64 %1, i64 %2) {
%4 = icmp eq i8** %0, null
br i1 %4, label %20, label %5
5: ; preds = %3
%6 = icmp ugt i64 %2, %1
%7 = sub i64 1, %1
%8 = add i64 %7, %2
%9 = select i1 %6, i64 %8, i64 1
%10 = icmp ugt i64 %9, %2
br i1 %10, label %20, label %11
11: ; preds = %5, %11
%12 = phi i64 [ %18, %11 ], [ %9, %5 ]
%13 = add i64 %12, -1
%14 = urem i64 %13, %1
%15 = getelementptr inbounds i8*, i8** %0, i64 %14
%16 = load i8*, i8** %15
%17 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 %12, i8* %16)
%18 = add i64 %12, 1
%19 = icmp ugt i64 %18, %2
br i1 %19, label %20, label %11
20: ; preds = %11, %5, %3
ret void
}