#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);
int /*<<< orphan*/ printf(char *, int, int, int, int);
void validate_raising_sort(int *array, int length) {
  int i;
  for (i = 1; i < length; i++) {
    if (array[i - 1] > array[i]) {
      printf("failed, %d > %d in [%d,%d]", array[i - 1], array[i], i - 1, i);
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<validate_raising_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b1 <validate_raising_sort+0x91>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jle    119e <validate_raising_sort+0x7e>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x10(%rbp),%r8d
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
jmp    11a3 <validate_raising_sort+0x83>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <validate_raising_sort+0x16>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_raising_sort>:
push   %rax
cmp    $0x2,%esi
jl     1143 <validate_raising_sort+0x23>
mov    %esi,%eax
mov    (%rdi),%esi
add    $0xffffffffffffffff,%rax
xor    %ecx,%ecx
mov    0x4(%rdi,%rcx,4),%edx
cmp    %edx,%esi
jg     1145 <validate_raising_sort+0x25>
add    $0x1,%rcx
mov    %edx,%esi
cmp    %rcx,%rax
jne    1130 <validate_raising_sort+0x10>
pop    %rax
ret
lea    0x1(%rcx),%r8d
lea    0xeb0(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

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

LLVM IR (-O2):
@.str = [27 x i8] c"failed, %d > %d in [%d,%d]\00"
define void @validate_raising_sort(i32* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
br i1 %3, label %4, label %22
4: ; preds = %2
%5 = zext i32 %1 to i64
%6 = load i32, i32* %0
br label %7
7: ; preds = %4, %19
%8 = phi i32 [ %6, %4 ], [ %11, %19 ]
%9 = phi i64 [ 1, %4 ], [ %20, %19 ]
%10 = getelementptr inbounds i32, i32* %0, i64 %9
%11 = load i32, i32* %10
%12 = icmp sgt i32 %8, %11
br i1 %12, label %13, label %19
13: ; preds = %7
%14 = trunc i64 %9 to i32
%15 = trunc i64 %9 to i32
%16 = add i32 %15, -1
%17 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %11, i32 %16, i32 %14)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %7
%20 = add nuw nsw i64 %9, 1
%21 = icmp eq i64 %20, %5
br i1 %21, label %22, label %7
22: ; preds = %19, %2
ret void
}