#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 LargestMobile(char *, int *);
int /*<<< orphan*/ MoveLargestMobile(char *, int *, int);
int /*<<< orphan*/ ReverseLarger(char *, int *, int);
int /*<<< orphan*/ Sort(char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int strlen(char *);
int main(int argc, char **argv) {
  int *direct = 0;
  int lm = 0;
  if (argc != 2) {
    fprintf(stderr, "Error: Expected a single argument to permute.");
    return -1;
  }
  direct = (int *)malloc(4 * strlen(argv[1]));
  for (int i = 0; i < strlen(argv[1]); ++i)
    direct[i] = -1;
  Sort(argv[1]);
  printf("%s\n", argv[1]);
  while ((lm = LargestMobile(argv[1], direct)) >= 0) {
    ReverseLarger(argv[1], direct, lm);
    MoveLargestMobile(argv[1], direct, lm);
    printf("%s\n", argv[1]);
  }
  free(direct);
  direct = 0;
  fflush(stdout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11f0 <main+0x50>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe21(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f4 <main+0x154>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <strlen@plt>
mov    %eax,%edi
shl    $0x2,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    124f <main+0xaf>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1212 <main+0x72>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <Sort@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdc3(%rip),%rdi
call   1080 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <LargestMobile@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jl     12ce <main+0x12e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1070 <ReverseLarger@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <MoveLargestMobile@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd6a(%rip),%rdi
call   1080 <printf@plt>
jmp    1270 <main+0xd0>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
mov    0x2cf2(%rip),%rax
mov    (%rax),%edi
call   10c0 <fflush@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    1284 <main+0xe4>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1060 <strlen@plt>
lea    0x0(,%rax,4),%edi
call   10b0 <malloc@plt>
mov    %rax,%r14
mov    0x8(%rbx),%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    11fc <main+0x5c>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movl   $0xffffffff,(%r14,%rbp,4)
ff
add    $0x1,%rbp
mov    0x8(%rbx),%rdi
call   1060 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     11e0 <main+0x40>
mov    0x8(%rbx),%rdi
call   1050 <Sort@plt>
mov    0x8(%rbx),%rsi
lea    0xe1e(%rip),%rdi
call   1080 <printf@plt>
mov    0x8(%rbx),%rdi
mov    %r14,%rsi
call   10a0 <LargestMobile@plt>
test   %eax,%eax
js     126a <main+0xca>
mov    %eax,%ebp
lea    0xe00(%rip),%r15
xchg   %ax,%ax
mov    0x8(%rbx),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1070 <ReverseLarger@plt>
mov    0x8(%rbx),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <MoveLargestMobile@plt>
mov    0x8(%rbx),%rsi
mov    %r15,%rdi
call   1080 <printf@plt>
mov    0x8(%rbx),%rdi
mov    %r14,%rsi
call   10a0 <LargestMobile@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1230 <main+0x90>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
call   10c0 <fflush@plt>
xor    %eax,%eax
jmp    129e <main+0xfe>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
lea    0xd6c(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [46 x i8] c"Error: Expected a single argument to permute.\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i32 0, i32* %7
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %75
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @strlen(i8* %17)
%19 = mul nsw i32 4, %18
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i32*
store i32* %21, i32** %6
store i32 0, i32* %8
br label %22
22: ; preds = %34, %14
%23 = load i32, i32* %8
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @strlen(i8* %26)
%28 = icmp slt i32 %23, %27
br i1 %28, label %29, label %37
29: ; preds = %22
%30 = load i32*, i32** %6
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
store i32 -1, i32* %33
br label %34
34: ; preds = %29
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 1
store i32 %36, i32* %8
br label %22
37: ; preds = %22
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @Sort(i8* %40)
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %53, %37
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = load i32*, i32** %6
%51 = call i32 @LargestMobile(i8* %49, i32* %50)
store i32 %51, i32* %7
%52 = icmp sge i32 %51, 0
br i1 %52, label %53, label %70
53: ; preds = %46
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 1
%56 = load i8*, i8** %55
%57 = load i32*, i32** %6
%58 = load i32, i32* %7
%59 = call i32 @ReverseLarger(i8* %56, i32* %57, i32 %58)
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 1
%62 = load i8*, i8** %61
%63 = load i32*, i32** %6
%64 = load i32, i32* %7
%65 = call i32 @MoveLargestMobile(i8* %62, i32* %63, i32 %64)
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 1
%68 = load i8*, i8** %67
%69 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %68)
br label %46
70: ; preds = %46
%71 = load i32*, i32** %6
%72 = call i32 @free(i32* %71)
store i32* null, i32** %6
%73 = load i32, i32* @stdout
%74 = call i32 @fflush(i32 %73)
store i32 0, i32* %3
br label %75
75: ; preds = %70, %11
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [46 x i8] c"Error: Expected a single argument to permute.\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %48
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @strlen(i8* %9)
%11 = shl nsw i32 %10, 2
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i32*
%14 = load i8*, i8** %8
%15 = tail call i32 @strlen(i8* %14)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %25, label %17
17: ; preds = %25, %7
%18 = load i8*, i8** %8
%19 = tail call i32 @Sort(i8* %18)
%20 = load i8*, i8** %8
%21 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = load i8*, i8** %8
%23 = tail call i32 @LargestMobile(i8* %22, i32* %13)
%24 = icmp sgt i32 %23, -1
br i1 %24, label %33, label %44
25: ; preds = %7, %25
%26 = phi i64 [ %28, %25 ], [ 0, %7 ]
%27 = getelementptr inbounds i32, i32* %13, i64 %26
store i32 -1, i32* %27
%28 = add nuw nsw i64 %26, 1
%29 = load i8*, i8** %8
%30 = tail call i32 @strlen(i8* %29)
%31 = sext i32 %30 to i64
%32 = icmp slt i64 %28, %31
br i1 %32, label %25, label %17
33: ; preds = %17, %33
%34 = phi i32 [ %42, %33 ], [ %23, %17 ]
%35 = load i8*, i8** %8
%36 = tail call i32 @ReverseLarger(i8* %35, i32* %13, i32 %34)
%37 = load i8*, i8** %8
%38 = tail call i32 @MoveLargestMobile(i8* %37, i32* %13, i32 %34)
%39 = load i8*, i8** %8
%40 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %39)
%41 = load i8*, i8** %8
%42 = tail call i32 @LargestMobile(i8* %41, i32* %13)
%43 = icmp sgt i32 %42, -1
br i1 %43, label %33, label %44
44: ; preds = %33, %17
%45 = tail call i32 @free(i32* %13)
%46 = load i32, i32* @stdout
%47 = tail call i32 @fflush(i32 %46)
br label %48
48: ; preds = %44, %4
%49 = phi i32 [ -1, %4 ], [ 0, %44 ]
ret i32 %49
}