#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 */
scalar_t__ card(char);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  int i = 0, j, sorted = 0;
  char swap;
  char str[14];
  scanf("%s", str);
  while (!sorted) {
    i++;
    sorted = 1;
    for (j = 0; j < 13 - i; j++) {
      if (card(str[j]) > card(str[j + 1])) {
        swap = str[j];
        str[j] = str[j + 1];
        str[j + 1] = swap;
        sorted = 0;
      }
    }
  }
  printf("The sorted deck is: %s", str);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
lea    -0x1f(%rbp),%rsi
lea    0xebc(%rip),%rdi
call   1050 <scanf@plt>
cmpl   $0x0,-0x10(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1173 <main+0x43>
jmp    121e <main+0xee>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xd,%ecx
sub    -0x8(%rbp),%ecx
cmp    %ecx,%eax
jge    1219 <main+0xe9>
movslq -0xc(%rbp),%rax
movsbl -0x1f(%rbp,%rax,1),%edi
call   1040 <card@plt>
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x1f(%rbp,%rax,1),%edi
call   1040 <card@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jle    1206 <main+0xd6>
movslq -0xc(%rbp),%rax
mov    -0x1f(%rbp,%rax,1),%al
mov    %al,-0x11(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x1f(%rbp,%rax,1),%cl
movslq -0xc(%rbp),%rax
mov    %cl,-0x1f(%rbp,%rax,1)
mov    -0x11(%rbp),%cl
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
mov    %cl,-0x1f(%rbp,%rax,1)
movl   $0x0,-0x10(%rbp)
jmp    120b <main+0xdb>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118a <main+0x5a>
jmp    115d <main+0x2d>
lea    -0x1f(%rbp),%rsi
lea    0xdd7(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xecf(%rip),%rdi
lea    0xa(%rsp),%rsi
call   1050 <scanf@plt>
xor    %r14d,%r14d
jmp    1165 <main+0x35>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %r12d,%r12d
jne    11c3 <main+0x93>
cmp    $0xb,%r14
ja     11c3 <main+0x93>
mov    $0xc,%r15d
sub    %r14,%r15
add    $0x1,%r14
mov    $0x1,%r12d
xor    %ebp,%ebp
jmp    1198 <main+0x68>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rbp
cmp    %r15,%rbx
jge    1160 <main+0x30>
movsbl 0xa(%rsp,%rbp,1),%edi
call   1040 <card@plt>
mov    %rax,%r13
lea    0x1(%rbp),%rbx
movsbl 0xb(%rsp,%rbp,1),%edi
call   1040 <card@plt>
cmp    %rax,%r13
jle    1190 <main+0x60>
rolw   $0x8,0xa(%rsp,%rbp,1)
xor    %r12d,%r12d
jmp    1190 <main+0x60>
lea    0xe36(%rip),%rdi
lea    0xa(%rsp),%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [23 x i8] c"The sorted deck is: %s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca [14 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %4
%7 = getelementptr inbounds [14 x i8], [14 x i8]* %6, i64 0, i64 0
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %9
9: ; preds = %56, %0
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %57
13: ; preds = %9
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
store i32 %15, i32* %2
store i32 1, i32* %4
store i32 0, i32* %3
br label %16
16: ; preds = %53, %13
%17 = load i32, i32* %3
%18 = load i32, i32* %2
%19 = sub nsw i32 13, %18
%20 = icmp slt i32 %17, %19
br i1 %20, label %21, label %56
21: ; preds = %16
%22 = load i32, i32* %3
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [14 x i8], [14 x i8]* %6, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = call i64 @card(i8 signext %25)
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [14 x i8], [14 x i8]* %6, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = call i64 @card(i8 signext %31)
%33 = icmp sgt i64 %26, %32
br i1 %33, label %34, label %52
34: ; preds = %21
%35 = load i32, i32* %3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [14 x i8], [14 x i8]* %6, i64 0, i64 %36
%38 = load i8, i8* %37
store i8 %38, i8* %5
%39 = load i32, i32* %3
%40 = add nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [14 x i8], [14 x i8]* %6, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = load i32, i32* %3
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [14 x i8], [14 x i8]* %6, i64 0, i64 %45
store i8 %43, i8* %46
%47 = load i8, i8* %5
%48 = load i32, i32* %3
%49 = add nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [14 x i8], [14 x i8]* %6, i64 0, i64 %50
store i8 %47, i8* %51
store i32 0, i32* %4
br label %52
52: ; preds = %34, %21
br label %53
53: ; preds = %52
%54 = load i32, i32* %3
%55 = add nsw i32 %54, 1
store i32 %55, i32* %3
br label %16
56: ; preds = %16
br label %9
57: ; preds = %9
%58 = getelementptr inbounds [14 x i8], [14 x i8]* %6, i64 0, i64 0
%59 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %58)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [23 x i8] c"The sorted deck is: %s\00"
define i32 @main() {
%1 = alloca [14 x i8]
%2 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 0
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %6
4: ; preds = %25
%5 = icmp eq i32 %26, 0
br i1 %5, label %6, label %28
6: ; preds = %0, %4
%7 = phi i64 [ 0, %0 ], [ %8, %4 ]
%8 = add nuw i64 %7, 1
%9 = sub nsw i64 12, %7
%10 = icmp ult i64 %7, 12
br i1 %10, label %11, label %28
11: ; preds = %6, %25
%12 = phi i64 [ %17, %25 ], [ 0, %6 ]
%13 = phi i32 [ %26, %25 ], [ 1, %6 ]
%14 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 %12
%15 = load i8, i8* %14
%16 = call i64 @card(i8 signext %15)
%17 = add nuw nsw i64 %12, 1
%18 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = call i64 @card(i8 signext %19)
%21 = icmp sgt i64 %16, %20
br i1 %21, label %22, label %25
22: ; preds = %11
%23 = load i8, i8* %14
%24 = load i8, i8* %18
store i8 %24, i8* %14
store i8 %23, i8* %18
br label %25
25: ; preds = %11, %22
%26 = phi i32 [ 0, %22 ], [ %13, %11 ]
%27 = icmp slt i64 %17, %9
br i1 %27, label %11, label %4
28: ; preds = %6, %4
%29 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %2)
ret i32 0
}