#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*/ printf(char *);
void checkSort(int *data, int num) {
  int i;
  int flag = 0;
  for (i = 0; i < num - 1; i++) {
    if (data[i] > data[i + 1]) {
      flag = 1;
      break;
    }
  }
  if (flag == 0)
    printf("data is sorted\n");
  else
    printf("data is not sorted\n");
}


x86 assembly (clang, -O0):
<checkSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    117e <checkSort+0x6e>
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    116b <checkSort+0x5b>
movl   $0x1,-0x14(%rbp)
jmp    117e <checkSort+0x6e>
jmp    1170 <checkSort+0x60>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112d <checkSort+0x1d>
cmpl   $0x0,-0x14(%rbp)
jne    1199 <checkSort+0x89>
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
jmp    11a5 <checkSort+0x95>
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkSort>:
add    $0xffffffff,%esi
xor    %ecx,%ecx
test   %esi,%esi
cmovle %ecx,%esi
lea    0xef2(%rip),%r9
lea    0xed8(%rip),%r8
nopl   0x0(%rax,%rax,1)
cmp    %rcx,%rsi
je     1148 <checkSort+0x38>
mov    (%rdi,%rcx,4),%edx
lea    0x1(%rcx),%rax
cmp    0x4(%rdi,%rcx,4),%edx
mov    %rax,%rcx
jle    1130 <checkSort+0x20>
mov    %r8,%r9
mov    %r9,%rdi
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"data is sorted\0A\00"
@.str.1 = [20 x i8] c"data is not sorted\0A\00"
define void @checkSort(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %6
store i32 0, i32* %5
br label %7
7: ; preds = %27, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = sub nsw i32 %9, 1
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %30
12: ; preds = %7
%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 %26
25: ; preds = %12
store i32 1, i32* %6
br label %30
26: ; preds = %12
br label %27
27: ; preds = %26
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %7
30: ; preds = %25, %7
%31 = load i32, i32* %6
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %37
35: ; preds = %30
%36 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %35, %33
ret void
}

LLVM IR (-O2):
@str = [19 x i8] c"data is not sorted\00"
@str.2 = [15 x i8] c"data is sorted\00"
define void @checkSort(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 %16, 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, %6
%17 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.2, i64 0, i64 0), %6 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0), %9 ]
%18 = tail call i32 @puts(i8* dereferenceable(1) %17)
ret void
}