#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 */
char cardNumber(char);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  int i, j = 0, sorted = 0, n, m;
  char deck[13], temp;
  scanf("%s", deck);
  printf("Original: %s\n", deck);
  while (!sorted) {
    j++;
    sorted = 1;
    for (i = 0; i < 13 - j; i++) {
      n = cardNumber(deck[i]) > 0 ? cardNumber(deck[i]) : deck[i] - '0';
      m = cardNumber(deck[i + 1]) > 0 ? cardNumber(deck[i + 1])
                                      : deck[i + 1] - '0';
      if (n > m) {
        temp = deck[i];
        deck[i] = deck[i + 1];
        deck[i + 1] = temp;
        sorted = 0;
      }
    }
  }
  printf("Sorted: %s\n", deck);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    -0x25(%rbp),%rsi
lea    0xea8(%rip),%rdi
call   1050 <scanf@plt>
lea    -0x25(%rbp),%rsi
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x0,-0x10(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1183 <main+0x53>
jmp    12a2 <main+0x172>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xd,%ecx
sub    -0xc(%rbp),%ecx
cmp    %ecx,%eax
jge    129d <main+0x16d>
movslq -0x8(%rbp),%rax
movsbl -0x25(%rbp,%rax,1),%edi
call   1040 <cardNumber@plt>
movsbl %al,%eax
cmp    $0x0,%eax
jle    11e0 <main+0xb0>
movslq -0x8(%rbp),%rax
movsbl -0x25(%rbp,%rax,1),%edi
call   1040 <cardNumber@plt>
movsbl %al,%eax
mov    %eax,-0x2c(%rbp)
jmp    11ef <main+0xbf>
movslq -0x8(%rbp),%rax
movsbl -0x25(%rbp,%rax,1),%eax
sub    $0x30,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x25(%rbp,%rax,1),%edi
call   1040 <cardNumber@plt>
movsbl %al,%eax
cmp    $0x0,%eax
jle    1230 <main+0x100>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x25(%rbp,%rax,1),%edi
call   1040 <cardNumber@plt>
movsbl %al,%eax
mov    %eax,-0x30(%rbp)
jmp    1243 <main+0x113>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x25(%rbp,%rax,1),%eax
sub    $0x30,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    128a <main+0x15a>
movslq -0x8(%rbp),%rax
mov    -0x25(%rbp,%rax,1),%al
mov    %al,-0x26(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x25(%rbp,%rax,1),%cl
movslq -0x8(%rbp),%rax
mov    %cl,-0x25(%rbp,%rax,1)
mov    -0x26(%rbp),%cl
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cltq
mov    %cl,-0x25(%rbp,%rax,1)
movl   $0x0,-0x10(%rbp)
jmp    128f <main+0x15f>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    119a <main+0x6a>
jmp    116d <main+0x3d>
lea    -0x25(%rbp),%rsi
lea    0xd64(%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   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xebd(%rip),%rdi
lea    0x3(%rsp),%rbx
mov    %rbx,%rsi
call   1050 <scanf@plt>
lea    0xeac(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %r14d,%r14d
jmp    1179 <main+0x49>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %r12d,%r12d
jne    1206 <main+0xd6>
cmp    $0xb,%r14
ja     1206 <main+0xd6>
mov    $0xc,%r15d
sub    %r14,%r15
add    $0x1,%r14
mov    $0x1,%r12d
xor    %ebp,%ebp
jmp    11a8 <main+0x78>
nopw   0x0(%rax,%rax,1)
mov    %rax,%rbp
cmp    %r15,%rax
jge    1170 <main+0x40>
movsbl 0x3(%rsp,%rbp,1),%edi
call   1040 <cardNumber@plt>
movsbl 0x3(%rsp,%rbp,1),%ebx
test   %al,%al
jle    11d0 <main+0xa0>
mov    %ebx,%edi
call   1040 <cardNumber@plt>
movsbl %al,%ebx
jmp    11d3 <main+0xa3>
nopw   0x0(%rax,%rax,1)
add    $0xffffffd0,%ebx
movsbl 0x4(%rsp,%rbp,1),%edi
call   1040 <cardNumber@plt>
movsbl 0x4(%rsp,%rbp,1),%edi
test   %al,%al
jle    11f0 <main+0xc0>
call   1040 <cardNumber@plt>
movsbl %al,%edi
jmp    11f3 <main+0xc3>
add    $0xffffffd0,%edi
lea    0x1(%rbp),%rax
cmp    %edi,%ebx
jle    11a0 <main+0x70>
rolw   $0x8,0x3(%rsp,%rbp,1)
xor    %r12d,%r12d
jmp    11a0 <main+0x70>
lea    0xe04(%rip),%rdi
lea    0x3(%rsp),%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [14 x i8] c"Original: %s\0A\00"
@.str.2 = [12 x i8] c"Sorted: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [13 x i8]
%8 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
%9 = getelementptr inbounds [13 x i8], [13 x i8]* %7, i64 0, i64 0
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [13 x i8], [13 x i8]* %7, i64 0, i64 0
%12 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %100, %0
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 0
%16 = xor i1 %15, true
br i1 %16, label %17, label %101
17: ; preds = %13
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
store i32 1, i32* %4
store i32 0, i32* %2
br label %20
20: ; preds = %97, %17
%21 = load i32, i32* %2
%22 = load i32, i32* %3
%23 = sub nsw i32 13, %22
%24 = icmp slt i32 %21, %23
br i1 %24, label %25, label %100
25: ; preds = %20
%26 = load i32, i32* %2
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [13 x i8], [13 x i8]* %7, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = call signext i8 @cardNumber(i8 signext %29)
%31 = sext i8 %30 to i32
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %25
%34 = load i32, i32* %2
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [13 x i8], [13 x i8]* %7, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = call signext i8 @cardNumber(i8 signext %37)
%39 = sext i8 %38 to i32
br label %47
40: ; preds = %25
%41 = load i32, i32* %2
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [13 x i8], [13 x i8]* %7, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = sub nsw i32 %45, 48
br label %47
47: ; preds = %40, %33
%48 = phi i32 [ %39, %33 ], [ %46, %40 ]
store i32 %48, i32* %5
%49 = load i32, i32* %2
%50 = add nsw i32 %49, 1
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [13 x i8], [13 x i8]* %7, i64 0, i64 %51
%53 = load i8, i8* %52
%54 = call signext i8 @cardNumber(i8 signext %53)
%55 = sext i8 %54 to i32
%56 = icmp sgt i32 %55, 0
br i1 %56, label %57, label %65
57: ; preds = %47
%58 = load i32, i32* %2
%59 = add nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [13 x i8], [13 x i8]* %7, i64 0, i64 %60
%62 = load i8, i8* %61
%63 = call signext i8 @cardNumber(i8 signext %62)
%64 = sext i8 %63 to i32
br label %73
65: ; preds = %47
%66 = load i32, i32* %2
%67 = add nsw i32 %66, 1
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [13 x i8], [13 x i8]* %7, i64 0, i64 %68
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = sub nsw i32 %71, 48
br label %73
73: ; preds = %65, %57
%74 = phi i32 [ %64, %57 ], [ %72, %65 ]
store i32 %74, i32* %6
%75 = load i32, i32* %5
%76 = load i32, i32* %6
%77 = icmp sgt i32 %75, %76
br i1 %77, label %78, label %96
78: ; preds = %73
%79 = load i32, i32* %2
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [13 x i8], [13 x i8]* %7, i64 0, i64 %80
%82 = load i8, i8* %81
store i8 %82, i8* %8
%83 = load i32, i32* %2
%84 = add nsw i32 %83, 1
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [13 x i8], [13 x i8]* %7, i64 0, i64 %85
%87 = load i8, i8* %86
%88 = load i32, i32* %2
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds [13 x i8], [13 x i8]* %7, i64 0, i64 %89
store i8 %87, i8* %90
%91 = load i8, i8* %8
%92 = load i32, i32* %2
%93 = add nsw i32 %92, 1
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds [13 x i8], [13 x i8]* %7, i64 0, i64 %94
store i8 %91, i8* %95
store i32 0, i32* %4
br label %96
96: ; preds = %78, %73
br label %97
97: ; preds = %96
%98 = load i32, i32* %2
%99 = add nsw i32 %98, 1
store i32 %99, i32* %2
br label %20
100: ; preds = %20
br label %13
101: ; preds = %13
%102 = getelementptr inbounds [13 x i8], [13 x i8]* %7, i64 0, i64 0
%103 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %102)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [14 x i8] c"Original: %s\0A\00"
@.str.2 = [12 x i8] c"Sorted: %s\0A\00"
define i32 @main() {
%1 = alloca [13 x i8]
%2 = getelementptr inbounds [13 x i8], [13 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)
%4 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %7
5: ; preds = %46
%6 = icmp eq i32 %47, 0
br i1 %6, label %7, label %49
7: ; preds = %0, %5
%8 = phi i64 [ 0, %0 ], [ %9, %5 ]
%9 = add nuw i64 %8, 1
%10 = sub nsw i64 12, %8
%11 = icmp ult i64 %8, 12
br i1 %11, label %12, label %49
12: ; preds = %7, %46
%13 = phi i64 [ %28, %46 ], [ 0, %7 ]
%14 = phi i32 [ %47, %46 ], [ 1, %7 ]
%15 = getelementptr inbounds [13 x i8], [13 x i8]* %1, i64 0, i64 %13
%16 = load i8, i8* %15
%17 = call signext i8 @cardNumber(i8 signext %16)
%18 = icmp sgt i8 %17, 0
%19 = load i8, i8* %15
br i1 %18, label %20, label %23
20: ; preds = %12
%21 = call signext i8 @cardNumber(i8 signext %19)
%22 = sext i8 %21 to i32
br label %26
23: ; preds = %12
%24 = sext i8 %19 to i32
%25 = add nsw i32 %24, -48
br label %26
26: ; preds = %23, %20
%27 = phi i32 [ %22, %20 ], [ %25, %23 ]
%28 = add nuw nsw i64 %13, 1
%29 = getelementptr inbounds [13 x i8], [13 x i8]* %1, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = call signext i8 @cardNumber(i8 signext %30)
%32 = icmp sgt i8 %31, 0
%33 = load i8, i8* %29
br i1 %32, label %34, label %37
34: ; preds = %26
%35 = call signext i8 @cardNumber(i8 signext %33)
%36 = sext i8 %35 to i32
br label %40
37: ; preds = %26
%38 = sext i8 %33 to i32
%39 = add nsw i32 %38, -48
br label %40
40: ; preds = %37, %34
%41 = phi i32 [ %36, %34 ], [ %39, %37 ]
%42 = icmp sgt i32 %27, %41
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load i8, i8* %15
%45 = load i8, i8* %29
store i8 %45, i8* %15
store i8 %44, i8* %29
br label %46
46: ; preds = %40, %43
%47 = phi i32 [ 0, %43 ], [ %14, %40 ]
%48 = icmp slt i64 %28, %10
br i1 %48, label %12, label %5
49: ; preds = %7, %5
%50 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %2)
ret i32 0
}