#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void sort_test(int *array, size_t length) {
  int i;
  for (i = 0; i < length - 1; i++)
    if (array[i] > array[i + 1]) {
      printf("error : array not sorted!!!\n");
      printf("indice %d valore %d \n", i, array[i]);
      exit(0);
    }
  printf("\ntest ok!!\n\n");
}


x86 assembly (clang, -O0):
<sort_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    11b1 <sort_test+0x91>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
mov    -0x14(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jle    119e <sort_test+0x7e>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <exit@plt>
jmp    11a3 <sort_test+0x83>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1137 <sort_test+0x17>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sort_test>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x1,%eax
sub    %rsi,%rax
mov    $0xffffffffffffffff,%rcx
nopw   0x0(%rax,%rax,1)
lea    (%rax,%rcx,1),%rdx
cmp    $0xffffffffffffffff,%rdx
je     1197 <sort_test+0x67>
mov    0x4(%r14,%rcx,4),%edx
lea    0x1(%rcx),%rbx
cmp    0x8(%r14,%rcx,4),%edx
mov    %rbx,%rcx
jle    1150 <sort_test+0x20>
mov    %ebx,%r15d
lea    0xeab(%rip),%rdi
call   1030 <puts@plt>
mov    (%r14,%r15,4),%edx
lea    0xe79(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
lea    0xe78(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"error : array not sorted!!!\0A\00"
@.str.1 = [22 x i8] c"indice %d valore %d \0A\00"
@.str.2 = [13 x i8] c"\0Atest ok!!\0A\0A\00"
define void @sort_test(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32
store i32* %0, i32** %3
store i64 %1, i64* %4
store i32 0, i32* %5
br label %6
6: ; preds = %36, %2
%7 = load i32, i32* %5
%8 = sext i32 %7 to i64
%9 = load i64, i64* %4
%10 = sub i64 %9, 1
%11 = icmp ult i64 %8, %10
br i1 %11, label %12, label %39
12: ; preds = %6
%13 = load i32*, i32** %3
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
%17 = load i32, i32* %16
%18 = load i32*, i32** %3
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %18, i64 %21
%23 = load i32, i32* %22
%24 = icmp sgt i32 %17, %23
br i1 %24, label %25, label %35
25: ; preds = %12
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%27 = load i32, i32* %5
%28 = load i32*, i32** %3
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %32)
%34 = call i32 @exit(i32 0)
unreachable
35: ; preds = %12
br label %36
36: ; preds = %35
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %6
39: ; preds = %6
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [22 x i8] c"indice %d valore %d \0A\00"
@str = [12 x i8] c"\0Atest ok!!\0A\00"
@str.3 = [28 x i8] c"error : array not sorted!!!\00"
define void @sort_test(i32* nocapture %0, i64 %1) {
%3 = add i64 %1, -1
br label %4
4: ; preds = %7, %2
%5 = phi i64 [ %10, %7 ], [ 0, %2 ]
%6 = icmp eq i64 %5, %3
br i1 %6, label %22, label %7
7: ; preds = %4
%8 = getelementptr inbounds i32, i32* %0, i64 %5
%9 = load i32, i32* %8
%10 = add nuw i64 %5, 1
%11 = getelementptr inbounds i32, i32* %0, i64 %10
%12 = load i32, i32* %11
%13 = icmp sgt i32 %9, %12
br i1 %13, label %14, label %4
14: ; preds = %7
%15 = trunc i64 %5 to i32
%16 = and i64 %5, 4294967295
%17 = getelementptr inbounds i32, i32* %0, i64 %16
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.3, i64 0, i64 0))
%19 = load i32, i32* %17
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %19)
%21 = tail call i32 @exit(i32 0)
unreachable
22: ; preds = %4
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
ret void
}