#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 strlen(char *);
char *str_sort(char str[]) {
  char tc;
  int i, j;
  for (i = 0; i < strlen(str); ++i) {
    for (j = i; j > 0 && str[j] < str[j - 1]; --j) {
      tc = str[j];
      str[j] = str[j - 1];
      str[j - 1] = tc;
    }
  }
  return str;
}


x86 assembly (clang, -O0):
<str_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    11e6 <str_sort+0xd6>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x19(%rbp)
jle    1179 <str_sort+0x69>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x8(%rbp),%rcx
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
setl   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1189 <str_sort+0x79>
jmp    11d3 <str_sort+0xc3>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x9(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1145 <str_sort+0x35>
jmp    11d8 <str_sort+0xc8>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1123 <str_sort+0x13>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_sort>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbp
call   1030 <strlen@plt>
test   %eax,%eax
jle    1190 <str_sort+0x80>
xor    %r12d,%r12d
mov    $0x1,%r14d
mov    %rbp,%r15
jmp    1159 <str_sort+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r12d
mov    %rbp,%rdi
call   1030 <strlen@plt>
add    $0x1,%r14d
add    $0x1,%r15
cmp    %eax,%r12d
jge    1190 <str_sort+0x80>
test   %r12d,%r12d
je     1140 <str_sort+0x30>
mov    %r12d,%eax
mov    0x0(%rbp,%rax,1),%al
mov    %r15,%rcx
mov    %r14d,%edx
nopl   0x0(%rax,%rax,1)
lea    -0x2(%rdx),%esi
movzbl 0x0(%rbp,%rsi,1),%ebx
cmp    %bl,%al
jge    1140 <str_sort+0x30>
mov    %bl,(%rcx)
mov    %al,0x0(%rbp,%rsi,1)
add    $0xffffffff,%edx
add    $0xffffffffffffffff,%rcx
cmp    $0x1,%edx
jg     1170 <str_sort+0x60>
jmp    1140 <str_sort+0x30>
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @str_sort(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
br label %6
6: ; preds = %59, %1
%7 = load i32, i32* %4
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = icmp slt i32 %7, %9
br i1 %10, label %11, label %62
11: ; preds = %6
%12 = load i32, i32* %4
store i32 %12, i32* %5
br label %13
13: ; preds = %55, %11
%14 = load i32, i32* %5
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %31
16: ; preds = %13
%17 = load i8*, i8** %2
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = load i8*, i8** %2
%24 = load i32, i32* %5
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp slt i32 %22, %29
br label %31
31: ; preds = %16, %13
%32 = phi i1 [ false, %13 ], [ %30, %16 ]
br i1 %32, label %33, label %58
33: ; preds = %31
%34 = load i8*, i8** %2
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
store i8 %38, i8* %3
%39 = load i8*, i8** %2
%40 = load i32, i32* %5
%41 = sub nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
%44 = load i8, i8* %43
%45 = load i8*, i8** %2
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
store i8 %44, i8* %48
%49 = load i8, i8* %3
%50 = load i8*, i8** %2
%51 = load i32, i32* %5
%52 = sub nsw i32 %51, 1
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %50, i64 %53
store i8 %49, i8* %54
br label %55
55: ; preds = %33
%56 = load i32, i32* %5
%57 = add nsw i32 %56, -1
store i32 %57, i32* %5
br label %13
58: ; preds = %31
br label %59
59: ; preds = %58
%60 = load i32, i32* %4
%61 = add nsw i32 %60, 1
store i32 %61, i32* %4
br label %6
62: ; preds = %6
%63 = load i8*, i8** %2
ret i8* %63
}

LLVM IR (-O2):
define i8* @str_sort(i8* returned %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %26
4: ; preds = %1, %22
%5 = phi i32 [ %23, %22 ], [ 0, %1 ]
%6 = icmp eq i32 %5, 0
br i1 %6, label %22, label %7
7: ; preds = %4
%8 = zext i32 %5 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
br label %11
11: ; preds = %7, %18
%12 = phi i32 [ %13, %18 ], [ %5, %7 ]
%13 = add nsw i32 %12, -1
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = icmp slt i8 %10, %16
br i1 %17, label %18, label %22
18: ; preds = %11
%19 = zext i32 %12 to i64
%20 = getelementptr inbounds i8, i8* %0, i64 %19
store i8 %16, i8* %20
store i8 %10, i8* %15
%21 = icmp sgt i32 %12, 1
br i1 %21, label %11, label %22
22: ; preds = %18, %11, %4
%23 = add nuw nsw i32 %5, 1
%24 = tail call i32 @strlen(i8* %0)
%25 = icmp slt i32 %23, %24
br i1 %25, label %4, label %26
26: ; preds = %22, %1
ret i8* %0
}