#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 *, int, char *);
int print_history(char **history, int commands_run) {
  int hist_num = 10 + 1, last_index = (commands_run - 1) % 10, i;
  for (i = last_index + 1; i < 10; i++) {
    if (--hist_num <= commands_run)
      printf("%d %s\n", hist_num, history[i % 10]);
  }
  for (i = 0; i <= last_index; i++) {
    if (--hist_num <= commands_run)
      printf("%d %s\n", hist_num, history[i % 10]);
  }
  return commands_run;
}


x86 assembly (clang, -O0):
<print_history>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0xb,-0x10(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0xa,-0x18(%rbp)
jge    119c <print_history+0x8c>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
cmp    -0xc(%rbp),%eax
jg     1189 <print_history+0x79>
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%rax
movslq %edx,%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe7c(%rip),%rdi
call   1030 <printf@plt>
jmp    118e <print_history+0x7e>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1140 <print_history+0x30>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1201 <print_history+0xf1>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
cmp    -0xc(%rbp),%eax
jg     11ee <print_history+0xde>
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x28(%rbp),%rax
movslq %edx,%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe17(%rip),%rdi
call   1030 <printf@plt>
jmp    11f3 <print_history+0xe3>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a3 <print_history+0x93>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_history>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
lea    -0x1(%r14),%eax
movslq %eax,%r13
imul   $0x66666667,%r13,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r13d
mov    $0xb,%ebp
cmp    $0x8,%r13d
jg     11b5 <print_history+0xa5>
lea    0x1(%r13),%ebx
mov    $0xb,%ebp
lea    0xea1(%rip),%r12
jmp    1178 <print_history+0x68>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    $0xa,%ebx
je     11b0 <print_history+0xa0>
add    $0xffffffff,%ebp
cmp    %r14d,%ebp
jg     1170 <print_history+0x60>
movslq %ebx,%rax
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
cltq
mov    (%r15,%rax,8),%rdx
mov    %r12,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
jmp    1170 <print_history+0x60>
test   %r13d,%r13d
js     120f <print_history+0xff>
add    $0x1,%r13d
add    $0xffffffff,%ebp
xor    %ebx,%ebx
movabs $0xcccccccccccccccd,%r12
cc cc cc
jmp    11e1 <print_history+0xd1>
nopw   0x0(%rax,%rax,1)
add    $0x8,%r15
add    $0x1,%rbx
add    $0xffffffff,%ebp
add    $0xffffffff,%r13d
je     120f <print_history+0xff>
mov    %rbx,%rax
mul    %r12
cmp    %r14d,%ebp
jg     11d0 <print_history+0xc0>
shr    $0x2,%rdx
and    $0xfffffffffffffffe,%rdx
lea    (%rdx,%rdx,4),%rax
neg    %rax
mov    (%r15,%rax,8),%rdx
lea    0xdfa(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
jmp    11d0 <print_history+0xc0>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%d %s\0A\00"
define i32 @print_history(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8** %0, i8*** %3
store i32 %1, i32* %4
store i32 11, i32* %5
%8 = load i32, i32* %4
%9 = sub nsw i32 %8, 1
%10 = srem i32 %9, 10
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = add nsw i32 %11, 1
store i32 %12, i32* %7
br label %13
13: ; preds = %31, %2
%14 = load i32, i32* %7
%15 = icmp slt i32 %14, 10
br i1 %15, label %16, label %34
16: ; preds = %13
%17 = load i32, i32* %5
%18 = add nsw i32 %17, -1
store i32 %18, i32* %5
%19 = load i32, i32* %4
%20 = icmp sle i32 %18, %19
br i1 %20, label %21, label %30
21: ; preds = %16
%22 = load i32, i32* %5
%23 = load i8**, i8*** %3
%24 = load i32, i32* %7
%25 = srem i32 %24, 10
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %23, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %22, i8* %28)
br label %30
30: ; preds = %21, %16
br label %31
31: ; preds = %30
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %13
34: ; preds = %13
store i32 0, i32* %7
br label %35
35: ; preds = %54, %34
%36 = load i32, i32* %7
%37 = load i32, i32* %6
%38 = icmp sle i32 %36, %37
br i1 %38, label %39, label %57
39: ; preds = %35
%40 = load i32, i32* %5
%41 = add nsw i32 %40, -1
store i32 %41, i32* %5
%42 = load i32, i32* %4
%43 = icmp sle i32 %41, %42
br i1 %43, label %44, label %53
44: ; preds = %39
%45 = load i32, i32* %5
%46 = load i8**, i8*** %3
%47 = load i32, i32* %7
%48 = srem i32 %47, 10
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %46, i64 %49
%51 = load i8*, i8** %50
%52 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %45, i8* %51)
br label %53
53: ; preds = %44, %39
br label %54
54: ; preds = %53
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
store i32 %56, i32* %7
br label %35
57: ; preds = %35
%58 = load i32, i32* %4
ret i32 %58
}

LLVM IR (-O2):
@.str = [7 x i8] c"%d %s\0A\00"
define i32 @print_history(i8** nocapture %0, i32 returned %1) {
%3 = add nsw i32 %1, -1
%4 = srem i32 %3, 10
%5 = icmp slt i32 %4, 9
br i1 %5, label %10, label %8
6: ; preds = %22
%7 = icmp slt i32 %4, 0
br i1 %7, label %38, label %8
8: ; preds = %2, %6
%9 = phi i32 [ %14, %6 ], [ 11, %2 ]
br label %24
10: ; preds = %2, %22
%11 = phi i32 [ %13, %22 ], [ %4, %2 ]
%12 = phi i32 [ %14, %22 ], [ 11, %2 ]
%13 = add nsw i32 %11, 1
%14 = add nsw i32 %12, -1
%15 = icmp sgt i32 %14, %1
br i1 %15, label %22, label %16
16: ; preds = %10
%17 = srem i32 %13, 10
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %0, i64 %18
%20 = load i8*, i8** %19
%21 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %14, i8* %20)
br label %22
22: ; preds = %10, %16
%23 = icmp eq i32 %13, 9
br i1 %23, label %6, label %10
24: ; preds = %8, %35
%25 = phi i32 [ %36, %35 ], [ 0, %8 ]
%26 = phi i32 [ %27, %35 ], [ %9, %8 ]
%27 = add nsw i32 %26, -1
%28 = icmp sgt i32 %27, %1
br i1 %28, label %35, label %29
29: ; preds = %24
%30 = urem i32 %25, 10
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %0, i64 %31
%33 = load i8*, i8** %32
%34 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %27, i8* %33)
br label %35
35: ; preds = %24, %29
%36 = add nuw nsw i32 %25, 1
%37 = icmp eq i32 %25, %4
br i1 %37, label %38, label %24
38: ; preds = %35, %6
ret i32 %1
}