#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*/ circle_sort(int *, int, int /*<<< orphan*/, int,
                               int /*<<< orphan*/);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ print_vector(int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n;
  int *a;
  printf("Inform the size of the array:\n");
  scanf("%d", &n);
  a = (int *)malloc(n * sizeof(int));
  printf("Enter elements of the array one by one\n");
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  printf("Unsorted List: ");
  print_vector(a, n);
  circle_sort(a, n, 0, n - 1, 0);
  printf("Sorted List: ");
  print_vector(a, n);
  free(a);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
call   1050 <printf@plt>
lea    0xe9d(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1080 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xe7d(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e6 <main+0x86>
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe4c(%rip),%rdi
call   1080 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b1 <main+0x51>
lea    0xe5d(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1070 <print_vector@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
xor    %r8d,%r8d
mov    %r8d,%edx
call   1040 <circle_sort@plt>
lea    0xe3d(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1070 <print_vector@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xea2(%rip),%rdi
call   1040 <puts@plt>
lea    0xe75(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1090 <scanf@plt>
mov    0x4(%rsp),%edi
shl    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
lea    0xe94(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,0x4(%rsp)
jle    11ed <main+0x7d>
xor    %r12d,%r12d
lea    0xe3f(%rip),%r15
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <scanf@plt>
add    $0x1,%r12
movslq 0x4(%rsp),%rax
add    $0x4,%rbx
cmp    %rax,%r12
jl     11d0 <main+0x60>
lea    0xe0f(%rip),%rdi
call   1060 <printf@plt>
mov    0x4(%rsp),%esi
mov    %r14,%rdi
call   1080 <print_vector@plt>
mov    0x4(%rsp),%esi
lea    -0x1(%rsi),%ecx
mov    %r14,%rdi
xor    %edx,%edx
xor    %r8d,%r8d
call   1050 <circle_sort@plt>
lea    0xdf3(%rip),%rdi
call   1060 <printf@plt>
mov    0x4(%rsp),%esi
mov    %r14,%rdi
call   1080 <print_vector@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Inform the size of the array:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [40 x i8] c"Enter elements of the array one by one\0A\00"
@.str.3 = [16 x i8] c"Unsorted List: \00"
@.str.4 = [14 x i8] c"Sorted List: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %2
%8 = sext i32 %7 to i64
%9 = mul i64 %8, 4
%10 = trunc i64 %9 to i32
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i32*
store i32* %12, i32** %3
%13 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %14
14: ; preds = %24, %0
%15 = load i32, i32* %4
%16 = load i32, i32* %2
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %27
18: ; preds = %14
%19 = load i32*, i32** %3
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %22)
br label %24
24: ; preds = %18
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %14
27: ; preds = %14
%28 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%29 = load i32*, i32** %3
%30 = load i32, i32* %2
%31 = call i32 @print_vector(i32* %29, i32 %30)
%32 = load i32*, i32** %3
%33 = load i32, i32* %2
%34 = load i32, i32* %2
%35 = sub nsw i32 %34, 1
%36 = call i32 @circle_sort(i32* %32, i32 %33, i32 0, i32 %35, i32 0)
%37 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%38 = load i32*, i32** %3
%39 = load i32, i32* %2
%40 = call i32 @print_vector(i32* %38, i32 %39)
%41 = load i32*, i32** %3
%42 = call i32 @free(i32* %41)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [16 x i8] c"Unsorted List: \00"
@.str.4 = [14 x i8] c"Sorted List: \00"
@str = [30 x i8] c"Inform the size of the array:\00"
@str.5 = [39 x i8] c"Enter elements of the array one by one\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = shl i32 %5, 2
%7 = call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i32*
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.5, i64 0, i64 0))
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 0
br i1 %11, label %23, label %12
12: ; preds = %23, %0
%13 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%14 = load i32, i32* %1
%15 = call i32 @print_vector(i32* %8, i32 %14)
%16 = load i32, i32* %1
%17 = add nsw i32 %16, -1
%18 = call i32 @circle_sort(i32* %8, i32 %16, i32 0, i32 %17, i32 0)
%19 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%20 = load i32, i32* %1
%21 = call i32 @print_vector(i32* %8, i32 %20)
%22 = call i32 @free(i32* %8)
ret i32 0
23: ; preds = %0, %23
%24 = phi i64 [ %27, %23 ], [ 0, %0 ]
%25 = getelementptr inbounds i32, i32* %8, i64 %24
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %25)
%27 = add nuw nsw i64 %24, 1
%28 = load i32, i32* %1
%29 = sext i32 %28 to i64
%30 = icmp slt i64 %27, %29
br i1 %30, label %23, label %12
}