#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 *);
void permute_repeat(const char digits[], char buf[], int len, int cur,
                    int *printcount) {
  if (len == cur) {
    printf("%9d %s\n", ++(*printcount), buf);
    return;
  }
  int i = 0;
  for (; i < len; ++i) {
    if (*printcount > 1000000) {
      return;
    }
    buf[cur] = digits[i];
    permute_repeat(digits, buf, len, cur + 1, printcount);
  }
}


x86 assembly (clang, -O0):
<permute_repeat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    1166 <permute_repeat+0x46>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
add    $0x1,%esi
mov    %esi,(%rax)
mov    -0x10(%rbp),%rdx
lea    0xea4(%rip),%rdi
call   1040 <printf@plt>
jmp    11cc <permute_repeat+0xac>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11cc <permute_repeat+0xac>
mov    -0x20(%rbp),%rax
cmpl   $0xf4240,(%rax)
jle    118e <permute_repeat+0x6e>
jmp    11cc <permute_repeat+0xac>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
mov    -0x20(%rbp),%r8
call   1030 <permute_repeat@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116d <permute_repeat+0x4d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<permute_repeat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%rbx
mov    %rsi,%r14
cmp    %ecx,%edx
jne    115c <permute_repeat+0x3c>
mov    (%rbx),%esi
add    $0x1,%esi
mov    %esi,(%rbx)
lea    0xeba(%rip),%rdi
mov    %r14,%rdx
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
mov    %edx,%r15d
test   %edx,%edx
jle    11b6 <permute_repeat+0x96>
mov    %ecx,%r12d
mov    %rdi,%rbp
movslq %ecx,%rax
mov    %rax,0x10(%rsp)
add    $0x1,%r12d
mov    %r15d,%eax
mov    %rax,0x8(%rsp)
xor    %r13d,%r13d
cmpl   $0xf4240,(%rbx)
jg     11b6 <permute_repeat+0x96>
movzbl 0x0(%rbp,%r13,1),%eax
mov    0x10(%rsp),%rcx
mov    %al,(%r14,%rcx,1)
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
mov    %r12d,%ecx
mov    %rbx,%r8
call   1030 <permute_repeat@plt>
add    $0x1,%r13
cmp    %r13,0x8(%rsp)
jne    1180 <permute_repeat+0x60>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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