#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__ Cardvalue(char);
int /*<<< orphan*/ Isitcard(char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
int main() {
  char a;
  char cards[100];
  int i, j;
  scanf("%[^\n]s", cards);
  for (i = 0; i < strlen(cards); i++) {
    if (!Isitcard(cards[i])) {
      printf("Not valid card\n");
      break;
    }
    for (j = i + 1; j < strlen(cards); j++) {
      if (Cardvalue(cards[i]) > Cardvalue(cards[j])) {
        a = cards[i];
        cards[i] = cards[j];
        cards[j] = a;
      }
    }
  }
  printf("%s \n", cards);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rsi
lea    0xe93(%rip),%rdi
call   1060 <scanf@plt>
movl   $0x0,-0x74(%rbp)
mov    -0x74(%rbp),%eax
mov    %eax,-0x7c(%rbp)
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x7c(%rbp),%eax
cmp    %ecx,%eax
jge    1266 <main+0x116>
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%edi
call   1070 <Isitcard@plt>
cmp    $0x0,%eax
jne    11bf <main+0x6f>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1266 <main+0x116>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
mov    -0x78(%rbp),%eax
mov    %eax,-0x80(%rbp)
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x80(%rbp),%eax
cmp    %ecx,%eax
jge    1253 <main+0x103>
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%edi
call   1030 <Cardvalue@plt>
mov    %rax,-0x88(%rbp)
movslq -0x78(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%edi
call   1030 <Cardvalue@plt>
mov    %rax,%rcx
mov    -0x88(%rbp),%rax
cmp    %rcx,%rax
jle    1240 <main+0xf0>
movslq -0x74(%rbp),%rax
mov    -0x70(%rbp,%rax,1),%al
mov    %al,-0x5(%rbp)
movslq -0x78(%rbp),%rax
mov    -0x70(%rbp,%rax,1),%cl
movslq -0x74(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x5(%rbp),%cl
movslq -0x78(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
jmp    1245 <main+0xf5>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    11c8 <main+0x78>
jmp    1258 <main+0x108>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1179 <main+0x29>
lea    -0x70(%rbp),%rsi
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xe8b(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1070 <scanf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    1229 <main+0xc9>
mov    $0x1,%r15d
xor    %r12d,%r12d
mov    %rsp,%r14
jmp    11b3 <main+0x53>
xchg   %ax,%ax
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
add    $0x1,%r15
cmp    %rax,%r12
jge    1229 <main+0xc9>
mov    %r12,%r13
movsbl (%rsp,%r12,1),%edi
call   1080 <Isitcard@plt>
test   %eax,%eax
je     121d <main+0xbd>
lea    0x1(%r13),%r12
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%r12
jge    11a0 <main+0x40>
mov    %r15,%rbp
jmp    11f0 <main+0x90>
nopl   0x0(%rax)
add    $0x1,%rbp
mov    %r14,%rdi
call   1050 <strlen@plt>
cmp    %ebp,%eax
jle    11a0 <main+0x40>
movsbl (%rsp,%r13,1),%edi
call   1030 <Cardvalue@plt>
mov    %rax,%rbx
movsbl (%rsp,%rbp,1),%edi
call   1030 <Cardvalue@plt>
cmp    %rax,%rbx
jle    11e0 <main+0x80>
movzbl (%rsp,%r13,1),%eax
movzbl (%rsp,%rbp,1),%ecx
mov    %cl,(%rsp,%r13,1)
mov    %al,(%rsp,%rbp,1)
jmp    11e0 <main+0x80>
lea    0xde8(%rip),%rdi
call   1040 <puts@plt>
lea    0xdd7(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c"%[^\0A]s\00"
@.str.2 = [5 x i8] c"%s \0A\00"
@str = [15 x i8] c"Not valid card\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = call i32 @strlen(i8* %2)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %11, label %41
6: ; preds = %36, %20
%7 = call i32 @strlen(i8* %2)
%8 = sext i32 %7 to i64
%9 = icmp slt i64 %21, %8
%10 = add nuw nsw i64 %13, 1
br i1 %9, label %11, label %41
11: ; preds = %0, %6
%12 = phi i64 [ %21, %6 ], [ 0, %0 ]
%13 = phi i64 [ %10, %6 ], [ 1, %0 ]
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %12
%15 = load i8, i8* %14
%16 = call i32 @Isitcard(i8 signext %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %41
20: ; preds = %11
%21 = add nuw nsw i64 %12, 1
%22 = call i32 @strlen(i8* %2)
%23 = sext i32 %22 to i64
%24 = icmp slt i64 %21, %23
br i1 %24, label %25, label %6
25: ; preds = %20, %36
%26 = phi i64 [ %37, %36 ], [ %13, %20 ]
%27 = load i8, i8* %14
%28 = call i64 @Cardvalue(i8 signext %27)
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %26
%30 = load i8, i8* %29
%31 = call i64 @Cardvalue(i8 signext %30)
%32 = icmp sgt i64 %28, %31
br i1 %32, label %33, label %36
33: ; preds = %25
%34 = load i8, i8* %14
%35 = load i8, i8* %29
store i8 %35, i8* %14
store i8 %34, i8* %29
br label %36
36: ; preds = %25, %33
%37 = add nuw nsw i64 %26, 1
%38 = call i32 @strlen(i8* %2)
%39 = trunc i64 %37 to i32
%40 = icmp sgt i32 %38, %39
br i1 %40, label %25, label %6
41: ; preds = %6, %0, %18
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %2)
ret i32 0
}