#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 main(int argc, char *argv[]) {
  int n1[] = {1, 2, 3};
  int p1[] = {1, 3, 2};
  int n2[] = {3, 2, 1};
  int p2[] = {1, 2, 3};
  int n3[] = {1, 5, 5};
  int p3[] = {5, 1, 5};
  nextPermutation(n1, 3);
  for (int i = 0; i < 3; ++i) {
    if (!(p1[i] == n1[i])) {
      printf("assert fail: %s\n", "n1");
      return -1;
    };
  }
  nextPermutation(n2, 3);
  for (int i = 0; i < 3; ++i) {
    if (!(p2[i] == n2[i])) {
      printf("assert fail: %s\n", "n2");
      return -1;
    };
  }
  nextPermutation(n3, 3);
  for (int i = 0; i < 3; ++i) {
    if (!(p3[i] == n3[i])) {
      printf("assert fail: %s\n", "n3");
      return -1;
    };
  }
  printf("everything is fine!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xec3(%rip),%rax
mov    %rax,-0x1c(%rbp)
mov    0xec1(%rip),%eax
mov    %eax,-0x14(%rbp)
mov    0xebb(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xeb9(%rip),%eax
mov    %eax,-0x20(%rbp)
mov    0xeb3(%rip),%rax
mov    %rax,-0x34(%rbp)
mov    0xeb1(%rip),%eax
mov    %eax,-0x2c(%rbp)
mov    0xeab(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xea9(%rip),%eax
mov    %eax,-0x38(%rbp)
mov    0xea3(%rip),%rax
mov    %rax,-0x4c(%rbp)
mov    0xea1(%rip),%eax
mov    %eax,-0x44(%rbp)
mov    0xe9b(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0xe99(%rip),%eax
mov    %eax,-0x50(%rbp)
lea    -0x1c(%rbp),%rdi
mov    $0x3,%esi
call   1040 <nextPermutation@plt>
movl   $0x0,-0x5c(%rbp)
cmpl   $0x3,-0x5c(%rbp)
jge    1217 <main+0xf7>
movslq -0x5c(%rbp),%rax
mov    -0x28(%rbp,%rax,4),%eax
movslq -0x5c(%rbp),%rcx
cmp    -0x1c(%rbp,%rcx,4),%eax
je     1204 <main+0xe4>
lea    0xe5e(%rip),%rdi
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12fe <main+0x1de>
jmp    1209 <main+0xe9>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    11c3 <main+0xa3>
lea    -0x34(%rbp),%rdi
mov    $0x3,%esi
call   1040 <nextPermutation@plt>
movl   $0x0,-0x60(%rbp)
cmpl   $0x3,-0x60(%rbp)
jge    1280 <main+0x160>
movslq -0x60(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
movslq -0x60(%rbp),%rcx
cmp    -0x34(%rbp,%rcx,4),%eax
je     126d <main+0x14d>
lea    0xdf5(%rip),%rdi
lea    0xe02(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12fe <main+0x1de>
jmp    1272 <main+0x152>
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    122c <main+0x10c>
lea    -0x4c(%rbp),%rdi
mov    $0x3,%esi
call   1040 <nextPermutation@plt>
movl   $0x0,-0x64(%rbp)
cmpl   $0x3,-0x64(%rbp)
jge    12e9 <main+0x1c9>
movslq -0x64(%rbp),%rax
mov    -0x58(%rbp,%rax,4),%eax
movslq -0x64(%rbp),%rcx
cmp    -0x4c(%rbp,%rcx,4),%eax
je     12d6 <main+0x1b6>
lea    0xd8c(%rip),%rdi
lea    0xd9c(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12fe <main+0x1de>
jmp    12db <main+0x1bb>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1295 <main+0x175>
lea    0xd72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x38,%rsp
mov    0xece(%rip),%eax
mov    %eax,0x30(%rsp)
mov    0xebb(%rip),%rax
mov    %rax,0x28(%rsp)
mov    0xec4(%rip),%eax
mov    %eax,0x20(%rsp)
mov    0xeb1(%rip),%rax
mov    %rax,0x18(%rsp)
mov    0xeba(%rip),%eax
mov    %eax,0x10(%rsp)
mov    0xea7(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0x28(%rsp),%rdi
mov    $0x3,%esi
call   1050 <nextPermutation@plt>
cmpl   $0x1,0x28(%rsp)
jne    11f5 <main+0xc5>
cmpl   $0x3,0x2c(%rsp)
jne    11f5 <main+0xc5>
cmpl   $0x2,0x30(%rsp)
jne    11f5 <main+0xc5>
lea    0x18(%rsp),%rdi
mov    $0x3,%esi
call   1050 <nextPermutation@plt>
cmpl   $0x1,0x18(%rsp)
jne    1205 <main+0xd5>
cmpl   $0x2,0x1c(%rsp)
jne    1205 <main+0xd5>
cmpl   $0x3,0x20(%rsp)
jne    1205 <main+0xd5>
lea    0x8(%rsp),%rdi
mov    $0x3,%esi
call   1050 <nextPermutation@plt>
cmpl   $0x5,0x8(%rsp)
jne    1215 <main+0xe5>
cmpl   $0x1,0xc(%rsp)
jne    1215 <main+0xe5>
cmpl   $0x5,0x10(%rsp)
jne    1215 <main+0xe5>
lea    0xe55(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x38,%rsp
ret
lea    0xe28(%rip),%rdi
lea    0xe32(%rip),%rsi
jmp    1223 <main+0xf3>
lea    0xe18(%rip),%rdi
lea    0xe25(%rip),%rsi
jmp    1223 <main+0xf3>
lea    0xe08(%rip),%rdi
lea    0xe18(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x38,%rsp
ret

LLVM IR (-O0):
@__const.main.n1 = [3 x i32] [i32 1, i32 2, i32 3]
@__const.main.p1 = [3 x i32] [i32 1, i32 3, i32 2]
@__const.main.n2 = [3 x i32] [i32 3, i32 2, i32 1]
@__const.main.p2 = [3 x i32] [i32 1, i32 2, i32 3]
@__const.main.n3 = [3 x i32] [i32 1, i32 5, i32 5]
@__const.main.p3 = [3 x i32] [i32 5, i32 1, i32 5]
@.str = [17 x i8] c"assert fail: %s\0A\00"
@.str.1 = [3 x i8] c"n1\00"
@.str.2 = [3 x i8] c"n2\00"
@.str.3 = [3 x i8] c"n3\00"
@.str.4 = [21 x i8] c"everything is fine!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [3 x i32]
%7 = alloca [3 x i32]
%8 = alloca [3 x i32]
%9 = alloca [3 x i32]
%10 = alloca [3 x i32]
%11 = alloca [3 x i32]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = bitcast [3 x i32]* %6 to i8*
%16 = bitcast [3 x i32]* %7 to i8*
%17 = bitcast [3 x i32]* %8 to i8*
%18 = bitcast [3 x i32]* %9 to i8*
%19 = bitcast [3 x i32]* %10 to i8*
%20 = bitcast [3 x i32]* %11 to i8*
%21 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 0
%22 = call i32 @nextPermutation(i32* %21, i32 3)
store i32 0, i32* %12
br label %23
23: ; preds = %39, %2
%24 = load i32, i32* %12
%25 = icmp slt i32 %24, 3
br i1 %25, label %26, label %42
26: ; preds = %23
%27 = load i32, i32* %12
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = load i32, i32* %12
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = icmp eq i32 %30, %34
br i1 %35, label %38, label %36
36: ; preds = %26
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %88
38: ; preds = %26
br label %39
39: ; preds = %38
%40 = load i32, i32* %12
%41 = add nsw i32 %40, 1
store i32 %41, i32* %12
br label %23
42: ; preds = %23
%43 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 0
%44 = call i32 @nextPermutation(i32* %43, i32 3)
store i32 0, i32* %13
br label %45
45: ; preds = %61, %42
%46 = load i32, i32* %13
%47 = icmp slt i32 %46, 3
br i1 %47, label %48, label %64
48: ; preds = %45
%49 = load i32, i32* %13
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 %50
%52 = load i32, i32* %51
%53 = load i32, i32* %13
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 %54
%56 = load i32, i32* %55
%57 = icmp eq i32 %52, %56
br i1 %57, label %60, label %58
58: ; preds = %48
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %88
60: ; preds = %48
br label %61
61: ; preds = %60
%62 = load i32, i32* %13
%63 = add nsw i32 %62, 1
store i32 %63, i32* %13
br label %45
64: ; preds = %45
%65 = getelementptr inbounds [3 x i32], [3 x i32]* %10, i64 0, i64 0
%66 = call i32 @nextPermutation(i32* %65, i32 3)
store i32 0, i32* %14
br label %67
67: ; preds = %83, %64
%68 = load i32, i32* %14
%69 = icmp slt i32 %68, 3
br i1 %69, label %70, label %86
70: ; preds = %67
%71 = load i32, i32* %14
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [3 x i32], [3 x i32]* %11, i64 0, i64 %72
%74 = load i32, i32* %73
%75 = load i32, i32* %14
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [3 x i32], [3 x i32]* %10, i64 0, i64 %76
%78 = load i32, i32* %77
%79 = icmp eq i32 %74, %78
br i1 %79, label %82, label %80
80: ; preds = %70
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %88
82: ; preds = %70
br label %83
83: ; preds = %82
%84 = load i32, i32* %14
%85 = add nsw i32 %84, 1
store i32 %85, i32* %14
br label %67
86: ; preds = %67
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %88
88: ; preds = %86, %80, %58, %36
%89 = load i32, i32* %3
ret i32 %89
}

LLVM IR (-O2):
@__const.main.n1 = [3 x i32] [i32 1, i32 2, i32 3]
@__const.main.n2 = [3 x i32] [i32 3, i32 2, i32 1]
@__const.main.n3 = [3 x i32] [i32 1, i32 5, i32 5]
@.str = [17 x i8] c"assert fail: %s\0A\00"
@.str.1 = [3 x i8] c"n1\00"
@.str.2 = [3 x i8] c"n2\00"
@.str.3 = [3 x i8] c"n3\00"
@str = [20 x i8] c"everything is fine!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [3 x i32]
%4 = alloca [3 x i32]
%5 = alloca [3 x i32]
%6 = bitcast [3 x i32]* %3 to i8*
%7 = bitcast [3 x i32]* %4 to i8*
%8 = bitcast [3 x i32]* %5 to i8*
%9 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 0
%10 = call i32 @nextPermutation(i32* %9, i32 3)
%11 = load i32, i32* %9
%12 = icmp eq i32 %11, 1
%13 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 1
%14 = load i32, i32* %13
%15 = icmp eq i32 %14, 3
%16 = select i1 %12, i1 %15, i1 false
%17 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 2
%18 = load i32, i32* %17
%19 = icmp eq i32 %18, 2
%20 = select i1 %16, i1 %19, i1 false
br i1 %20, label %21, label %34
21: ; preds = %2
%22 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 0
%23 = call i32 @nextPermutation(i32* %22, i32 3)
%24 = load i32, i32* %22
%25 = icmp eq i32 %24, 1
%26 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 1
%27 = load i32, i32* %26
%28 = icmp eq i32 %27, 2
%29 = select i1 %25, i1 %28, i1 false
%30 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 2
%31 = load i32, i32* %30
%32 = icmp eq i32 %31, 3
%33 = select i1 %29, i1 %32, i1 false
br i1 %33, label %36, label %49
34: ; preds = %2
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %55
36: ; preds = %21
%37 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 0
%38 = call i32 @nextPermutation(i32* %37, i32 3)
%39 = load i32, i32* %37
%40 = icmp eq i32 %39, 5
%41 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 1
%42 = load i32, i32* %41
%43 = icmp eq i32 %42, 1
%44 = select i1 %40, i1 %43, i1 false
%45 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 2
%46 = load i32, i32* %45
%47 = icmp eq i32 %46, 5
%48 = select i1 %44, i1 %47, i1 false
br i1 %48, label %51, label %53
49: ; preds = %21
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %55
51: ; preds = %36
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %55
53: ; preds = %36
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %55
55: ; preds = %53, %49, %34, %51
%56 = phi i32 [ 0, %51 ], [ -1, %34 ], [ -1, %49 ], [ -1, %53 ]
ret i32 %56
}