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


x86 assembly (clang, -O0):
<permute_norepeat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    1185 <permute_norepeat+0x65>
mov    -0x28(%rbp),%rcx
mov    (%rcx),%eax
add    $0x1,%eax
mov    %eax,(%rcx)
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    $0x2710,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1180 <permute_norepeat+0x60>
mov    -0x2c(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
jmp    1220 <permute_norepeat+0x100>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1220 <permute_norepeat+0x100>
mov    -0x28(%rbp),%rax
cmpl   $0xf4240,(%rax)
jle    11ad <permute_norepeat+0x8d>
jmp    1220 <permute_norepeat+0x100>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     11c4 <permute_norepeat+0xa4>
jmp    1212 <permute_norepeat+0xf2>
mov    -0x8(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
movb   $0x1,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
add    $0x1,%r8d
mov    -0x28(%rbp),%r9
call   1030 <permute_norepeat@plt>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    118c <permute_norepeat+0x6c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<permute_norepeat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%rbx
mov    %rdx,0x8(%rsp)
cmp    %r8d,%ecx
jne    117a <permute_norepeat+0x5a>
mov    (%rbx),%esi
add    $0x1,%esi
mov    %esi,(%rbx)
imul   $0x3afb7e91,%esi,%eax
add    $0x346dc0,%eax
ror    $0x4,%eax
cmp    $0x68db8,%eax
ja     1200 <permute_norepeat+0xe0>
lea    0xe9e(%rip),%rdi
mov    0x8(%rsp),%rdx
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
mov    %ecx,%r12d
test   %ecx,%ecx
jle    1200 <permute_norepeat+0xe0>
mov    %rsi,%rbp
mov    %rdi,%r13
mov    %r8d,%eax
movslq %r8d,%rdx
mov    %rdx,0x10(%rsp)
add    $0x1,%eax
mov    %eax,0x4(%rsp)
mov    %r12d,%r14d
xor    %r15d,%r15d
jmp    11b9 <permute_norepeat+0x99>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15
cmp    %r15,%r14
je     1200 <permute_norepeat+0xe0>
cmpl   $0xf4240,(%rbx)
jg     1200 <permute_norepeat+0xe0>
cmpb   $0x0,0x0(%rbp,%r15,1)
jne    11b0 <permute_norepeat+0x90>
movzbl 0x0(%r13,%r15,1),%eax
mov    0x8(%rsp),%rdx
mov    0x10(%rsp),%rsi
mov    %al,(%rdx,%rsi,1)
movb   $0x1,0x0(%rbp,%r15,1)
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %r12d,%ecx
mov    0x4(%rsp),%r8d
mov    %rbx,%r9
call   1030 <permute_norepeat@plt>
movb   $0x0,0x0(%rbp,%r15,1)
jmp    11b0 <permute_norepeat+0x90>
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_norepeat(i8* %0, i8* %1, i8* %2, i32 %3, i32 %4, i32* %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32* %5, i32** %12
%15 = load i32, i32* %10
%16 = load i32, i32* %11
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %30
18: ; preds = %6
%19 = load i32*, i32** %12
%20 = load i32, i32* %19
%21 = add nsw i32 %20, 1
store i32 %21, i32* %19
store i32 %21, i32* %13
%22 = load i32, i32* %13
%23 = srem i32 %22, 10000
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %18
%26 = load i32, i32* %13
%27 = load i8*, i8** %9
%28 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %26, i8* %27)
br label %29
29: ; preds = %25, %18
br label %76
30: ; preds = %6
store i32 0, i32* %14
br label %31
31: ; preds = %73, %30
%32 = load i32, i32* %14
%33 = load i32, i32* %10
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %76
35: ; preds = %31
%36 = load i32*, i32** %12
%37 = load i32, i32* %36
%38 = icmp sgt i32 %37, 1000000
br i1 %38, label %39, label %40
39: ; preds = %35
br label %76
40: ; preds = %35
%41 = load i8*, i8** %8
%42 = load i32, i32* %14
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8, i8* %44
%46 = icmp ne i8 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %40
br label %73
48: ; preds = %40
%49 = load i8*, i8** %7
%50 = load i32, i32* %14
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i8, i8* %52
%54 = load i8*, i8** %9
%55 = load i32, i32* %11
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
store i8 %53, i8* %57
%58 = load i8*, i8** %8
%59 = load i32, i32* %14
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
store i8 1, i8* %61
%62 = load i8*, i8** %7
%63 = load i8*, i8** %8
%64 = load i8*, i8** %9
%65 = load i32, i32* %10
%66 = load i32, i32* %11
%67 = add nsw i32 %66, 1
%68 = load i32*, i32** %12
%69 = load i8*, i8** %8
%70 = load i32, i32* %14
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %69, i64 %71
store i8 0, i8* %72
br label %73
73: ; preds = %48, %47
%74 = load i32, i32* %14
%75 = add nsw i32 %74, 1
store i32 %75, i32* %14
br label %31
76: ; preds = %29, %39, %31
ret void
}

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