#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 atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ next_permutation(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc != 2) {
    fprintf(stderr, "usage: %s <N>\n", argv[0]);
    return 1;
  }
  int N = atoi(argv[1]);
  if (N <= 0)
    return 1;
  char sequence[10 + 1] = "0123456789";
  do {
    N--;
    if (N <= 0) {
      printf("%s\n", sequence);
      return 0;
    }
  } while (next_permutation(sequence));
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1188 <main+0x48>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe89(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    121b <main+0xdb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     11ae <main+0x6e>
movl   $0x1,-0x4(%rbp)
jmp    121b <main+0xdb>
mov    0xe5a(%rip),%rax
mov    %rax,-0x1f(%rbp)
mov    0xe57(%rip),%ax
mov    %ax,-0x17(%rbp)
mov    0xe4f(%rip),%al
mov    %al,-0x15(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     11fc <main+0xbc>
lea    -0x1f(%rbp),%rsi
lea    0xe2f(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    121b <main+0xdb>
jmp    1201 <main+0xc1>
lea    -0x1f(%rbp),%rdi
call   1030 <next_permutation@plt>
cmp    $0x0,%rax
jne    11cd <main+0x8d>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    1197 <main+0x57>
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
test   %eax,%eax
jle    11af <main+0x6f>
mov    %eax,%ebx
movabs $0x3736353433323130,%rax
35 36 37
mov    %rax,0x8(%rsp)
movl   $0x393837,0xf(%rsp)
add    $0x1,%ebx
lea    0x8(%rsp),%r14
nopw   0x0(%rax,%rax,1)
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
jle    11bc <main+0x7c>
mov    %r14,%rdi
call   1030 <next_permutation@plt>
test   %rax,%rax
jne    1180 <main+0x40>
jmp    11af <main+0x6f>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe56(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe57(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <printf@plt>
xor    %eax,%eax
jmp    11b4 <main+0x74>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"usage: %s <N>\0A\00"
@__const.main.sequence = [11 x i8] c"0123456789\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [11 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 1, i32* %3
br label %40
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp sle i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %16
store i32 1, i32* %3
br label %40
24: ; preds = %16
%25 = bitcast [11 x i8]* %7 to i8*
br label %26
26: ; preds = %35, %24
%27 = load i32, i32* %6
%28 = add nsw i32 %27, -1
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp sle i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = getelementptr inbounds [11 x i8], [11 x i8]* %7, i64 0, i64 0
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %32)
store i32 0, i32* %3
br label %40
34: ; preds = %26
br label %35
35: ; preds = %34
%36 = getelementptr inbounds [11 x i8], [11 x i8]* %7, i64 0, i64 0
%37 = call i64 @next_permutation(i8* %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %26, label %39
39: ; preds = %35
store i32 1, i32* %3
br label %40
40: ; preds = %39, %31, %23, %10
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"usage: %s <N>\0A\00"
@__const.main.sequence = [11 x i8] c"0123456789\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [11 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %27
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = icmp slt i32 %12, 1
br i1 %13, label %27, label %14
14: ; preds = %9
%15 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
br label %16
16: ; preds = %21, %14
%17 = phi i32 [ %12, %14 ], [ %22, %21 ]
%18 = icmp slt i32 %17, 2
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %25
21: ; preds = %16
%22 = add nsw i32 %17, -1
%23 = call i64 @next_permutation(i8* %15)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %16
25: ; preds = %21, %19
%26 = phi i32 [ 0, %19 ], [ 1, %21 ]
br label %27
27: ; preds = %25, %9, %5
%28 = phi i32 [ 1, %5 ], [ %26, %25 ], [ 1, %9 ]
ret i32 %28
}