#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*/ nextPermutation(int *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char *argv[]) {
  int x[50] = {1, 5, 8, 4, 7, 6, 5, 3, 1};
  int n;
  scanf("%d", &n);
  int i;
  for (i = 0; i < n; i++)
    scanf("%d", &x[i]);
  nextPermutation(x, n);
  for (i = 0; i < n; i++)
    printf("%d ", x[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0xe0(%rbp),%rdi
lea    0xe99(%rip),%rsi
mov    $0xc8,%edx
call   1040 <memcpy@plt>
lea    0xf50(%rip),%rdi
lea    -0xe4(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x0,-0xe8(%rbp)
mov    -0xe8(%rbp),%eax
cmp    -0xe4(%rbp),%eax
jge    11d5 <main+0x95>
movslq -0xe8(%rbp),%rax
lea    -0xe0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xf0c(%rip),%rdi
call   1050 <scanf@plt>
mov    -0xe8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xe8(%rbp)
jmp    118e <main+0x4e>
lea    -0xe0(%rbp),%rdi
mov    -0xe4(%rbp),%esi
call   1060 <nextPermutation@plt>
movl   $0x0,-0xe8(%rbp)
mov    -0xe8(%rbp),%eax
cmp    -0xe4(%rbp),%eax
jge    1231 <main+0xf1>
movslq -0xe8(%rbp),%rax
mov    -0xe0(%rbp,%rax,4),%esi
lea    0xeb3(%rip),%rdi
call   1030 <printf@plt>
mov    -0xe8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xe8(%rbp)
jmp    11f1 <main+0xb1>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xe0,%rsp
lea    0xead(%rip),%rsi
lea    0x10(%rsp),%r15
mov    $0xc8,%edx
mov    %r15,%rdi
call   1040 <memcpy@plt>
lea    0xf5c(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%esi
test   %esi,%esi
jle    11ad <main+0x6d>
xor    %ebx,%ebx
lea    0xf41(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rsi
add    $0x4,%r15
cmp    %rsi,%rbx
jl     1190 <main+0x50>
lea    0x10(%rsp),%rdi
call   1060 <nextPermutation@plt>
cmpl   $0x0,0xc(%rsp)
jle    11ea <main+0xaa>
xor    %ebx,%ebx
lea    0xf04(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp,%rbx,4),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     11d0 <main+0x90>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@__const.main.x = <{ [9 x i32], [41 x i32] }> <{ [9 x i32] [i32 1, i32 5, i32 8, i32 4, i32 7, i32 6, i32 5, i32 3, i32 1], [41 x i32] zeroinitializer }>
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [50 x i32]
%4 = alloca i32
%5 = bitcast [50 x i32]* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %2, %10
%11 = phi i64 [ %14, %10 ], [ 0, %2 ]
%12 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 %11
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %12)
%14 = add nuw nsw i64 %11, 1
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = icmp slt i64 %14, %16
br i1 %17, label %10, label %18
18: ; preds = %10, %2
%19 = phi i32 [ %8, %2 ], [ %15, %10 ]
%20 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 0
%21 = call i32 @nextPermutation(i32* %20, i32 %19)
%22 = load i32, i32* %4
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %33
24: ; preds = %18, %24
%25 = phi i64 [ %29, %24 ], [ 0, %18 ]
%26 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = add nuw nsw i64 %25, 1
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = icmp slt i64 %29, %31
br i1 %32, label %24, label %33
33: ; preds = %24, %18
ret i32 0
}