#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*/ printArr(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ quicksort(char *, char *, char *);
int strlen(char *);
int main() {
  char data[] = "4321";
  printf("Before sorting:\n");
  printArr(data, strlen(data));
  quicksort(data, data, data + strlen(data) - 1);
  printf("After sorting:\n");
  printArr(data, strlen(data));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeab(%rip),%eax
mov    %eax,-0x9(%rbp)
mov    0xea6(%rip),%al
mov    %al,-0x5(%rbp)
lea    0xe9d(%rip),%rdi
call   1050 <printf@plt>
lea    -0x9(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x9(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
call   1060 <printArr@plt>
lea    -0x9(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x9(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x9(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x9(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
cltq
add    %rax,%rdx
add    $0xffffffffffffffff,%rdx
call   1040 <quicksort@plt>
lea    0xe4b(%rip),%rdi
call   1050 <printf@plt>
lea    -0x9(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    -0x9(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%esi
call   1060 <printArr@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movb   $0x0,0xc(%rsp)
movl   $0x31323334,0x8(%rsp)
31
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <printArr@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rdx
add    $0x7,%rdx
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1050 <quicksort@plt>
lea    0xe7c(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <printArr@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.data = [5 x i8] c"4321\00"
@.str = [17 x i8] c"Before sorting:\0A\00"
@.str.1 = [16 x i8] c"After sorting:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x i8]
store i32 0, i32* %1
%3 = bitcast [5 x i8]* %2 to i8*
%4 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%7 = call i32 @strlen(i8* %6)
%8 = call i32 @printArr(i8* %5, i32 %7)
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%10 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%11 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
%16 = getelementptr inbounds i8, i8* %15, i64 -1
%17 = call i32 @quicksort(i8* %9, i8* %10, i8* %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%19 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%20 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
%22 = call i32 @printArr(i8* %19, i32 %21)
ret i32 0
}

LLVM IR (-O2):
@__const.main.data = [5 x i8] c"4321\00"
@str = [16 x i8] c"Before sorting:\00"
@str.2 = [15 x i8] c"After sorting:\00"
define i32 @main() {
%1 = alloca [5 x i8]
%2 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%4 = call i32 @strlen(i8* %2)
%5 = call i32 @printArr(i8* %2, i32 %4)
%6 = call i32 @strlen(i8* %2)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 %7
%9 = getelementptr inbounds i8, i8* %8, i64 -1
%10 = call i32 @quicksort(i8* %2, i8* %2, i8* %9)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.2, i64 0, i64 0))
%12 = call i32 @strlen(i8* %2)
%13 = call i32 @printArr(i8* %2, i32 %12)
ret i32 0
}