#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*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int main(void) {
  char str[100] = {0}, tmp;
  printf("Enter a string: ");
  gets(str);
  for (size_t i = 0; i < strlen(str) - 1; i++) {
    if (str[i] > str[i + 1]) {
      tmp = str[i];
      str[i] = str[i + 1];
      str[i + 1] = tmp;
    }
  }
  printf("%s", str);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1050 <memset@plt>
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rdi
call   1060 <gets@plt>
movq   $0x0,-0x80(%rbp)
mov    -0x80(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x70(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jae    1203 <main+0xc3>
mov    -0x80(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
mov    -0x80(%rbp),%rcx
movsbl -0x6f(%rbp,%rcx,1),%ecx
cmp    %ecx,%eax
jle    11ed <main+0xad>
mov    -0x80(%rbp),%rax
mov    -0x70(%rbp,%rax,1),%al
mov    %al,-0x71(%rbp)
mov    -0x80(%rbp),%rax
mov    -0x6f(%rbp,%rax,1),%cl
mov    -0x80(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x71(%rbp),%cl
mov    -0x80(%rbp),%rax
mov    %cl,-0x6f(%rbp,%rax,1)
jmp    11f2 <main+0xb2>
mov    -0x80(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x80(%rbp)
jmp    1181 <main+0x41>
lea    -0x70(%rbp),%rsi
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
lea    0xe9a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <gets@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jne    11a0 <main+0x70>
lea    0xe85(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
mov    %rsp,%r14
jmp    11c6 <main+0x96>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <strlen@plt>
add    $0xffffffff,%eax
movslq %eax,%rcx
mov    %rbx,%rax
cmp    %rcx,%rbx
jae    1185 <main+0x55>
movzbl (%rsp,%rax,1),%ecx
movzbl 0x1(%rsp,%rax,1),%edx
lea    0x1(%rax),%rbx
cmp    %dl,%cl
jle    11b0 <main+0x80>
mov    %dl,(%rsp,%rax,1)
mov    %cl,0x1(%rsp,%rax,1)
jmp    11b0 <main+0x80>

LLVM IR (-O0):
@.str = [17 x i8] c"Enter a string: \00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i8
%4 = alloca i64
store i32 0, i32* %1
%5 = bitcast [100 x i8]* %2 to i8*
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%8 = call i32 @gets(i8* %7)
store i64 0, i64* %4
br label %9
9: ; preds = %42, %0
%10 = load i64, i64* %4
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%12 = call i32 @strlen(i8* %11)
%13 = sub nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = icmp ult i64 %10, %14
br i1 %15, label %16, label %45
16: ; preds = %9
%17 = load i64, i64* %4
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = load i64, i64* %4
%22 = add i64 %21, 1
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp sgt i32 %20, %25
br i1 %26, label %27, label %41
27: ; preds = %16
%28 = load i64, i64* %4
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %28
%30 = load i8, i8* %29
store i8 %30, i8* %3
%31 = load i64, i64* %4
%32 = add i64 %31, 1
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = load i64, i64* %4
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %35
store i8 %34, i8* %36
%37 = load i8, i8* %3
%38 = load i64, i64* %4
%39 = add i64 %38, 1
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %39
store i8 %37, i8* %40
br label %41
41: ; preds = %27, %16
br label %42
42: ; preds = %41
%43 = load i64, i64* %4
%44 = add i64 %43, 1
store i64 %44, i64* %4
br label %9
45: ; preds = %9
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %46)
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"Enter a string: \00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @gets(i8* %2)
%5 = call i32 @strlen(i8* %2)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %9
7: ; preds = %18, %0
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
ret i32 0
9: ; preds = %0, %18
%10 = phi i64 [ %13, %18 ], [ 0, %0 ]
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = add nuw i64 %10, 1
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = icmp sgt i8 %12, %15
br i1 %16, label %17, label %18
17: ; preds = %9
store i8 %15, i8* %11
store i8 %12, i8* %14
br label %18
18: ; preds = %9, %17
%19 = call i32 @strlen(i8* %2)
%20 = add nsw i32 %19, -1
%21 = sext i32 %20 to i64
%22 = icmp ult i64 %13, %21
br i1 %22, label %9, label %7
}