#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 *);
void checkSorted(int *A, int N) {
  int i;
  for (i = 0; i < N - 1; i++) {
    if (A[i] > A[i + 1])
      break;
  }
  if (i != N - 1) {
    printf("Output is not sorted");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<checkSorted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1180 <checkSorted+0x60>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jle    116d <checkSorted+0x4d>
jmp    1180 <checkSorted+0x60>
jmp    1172 <checkSorted+0x52>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <checkSorted+0x16>
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     11a7 <checkSorted+0x87>
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkSorted>:
push   %rax
add    $0xffffffff,%esi
xor    %ecx,%ecx
test   %esi,%esi
mov    $0x0,%r8d
cmovg  %esi,%r8d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    %rcx,%r8
je     115b <checkSorted+0x3b>
mov    (%rdi,%rcx,4),%eax
lea    0x1(%rcx),%rdx
cmp    0x4(%rdi,%rcx,4),%eax
mov    %rdx,%rcx
jle    1140 <checkSorted+0x20>
add    $0xffffffff,%edx
mov    %edx,%r8d
cmp    %esi,%r8d
jne    1162 <checkSorted+0x42>
pop    %rax
ret
lea    0xe97(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"Output is not sorted\00"
define void @checkSorted(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 0, i32* %5
br label %6
6: ; preds = %26, %2
%7 = load i32, i32* %5
%8 = load i32, i32* %4
%9 = sub nsw i32 %8, 1
%10 = icmp slt i32 %7, %9
br i1 %10, label %11, label %29
11: ; preds = %6
%12 = load i32*, i32** %3
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %12, i64 %14
%16 = load i32, i32* %15
%17 = load i32*, i32** %3
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %17, i64 %20
%22 = load i32, i32* %21
%23 = icmp sgt i32 %16, %22
br i1 %23, label %24, label %25
24: ; preds = %11
br label %29
25: ; preds = %11
br label %26
26: ; preds = %25
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %6
29: ; preds = %24, %6
%30 = load i32, i32* %5
%31 = load i32, i32* %4
%32 = sub nsw i32 %31, 1
%33 = icmp ne i32 %30, %32
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %29
ret void
}

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