#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 printarray(int *array) {
  int i;
  int sorted = 1;
  int prev = -1;
  for (i = 0; i < (10); ++i) {
    printf("%d, ", array[i]);
    if (array[i] < prev) {
      sorted = 0;
    }
    prev = array[i];
  }
  if (sorted) {
    printf("\nok\n");
    return;
  } else {
    printf("\nNOT sorted\n");
    return;
  }
  return;
}


x86 assembly (clang, -O0):
<printarray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    118b <printarray+0x7b>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x14(%rbp),%eax
jge    116f <printarray+0x5f>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1131 <printarray+0x21>
cmpl   $0x0,-0x10(%rbp)
je     11a8 <printarray+0x98>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b6 <printarray+0xa6>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printarray>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    %rdi,%rbx
mov    (%rdi),%esi
lea    0xeca(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%ebp
mov    0x4(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rbx),%r15d
mov    0x8(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rbx),%esi
movss  0x8(%rbx),%xmm0
movaps %xmm0,0x60(%rsp)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%esi
movss  0xc(%rbx),%xmm0
movaps %xmm0,0x50(%rsp)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x14(%rbx),%esi
movss  0x10(%rbx),%xmm0
movaps %xmm0,0x40(%rsp)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rbx),%esi
movss  0x14(%rbx),%xmm0
movaps %xmm0,0x30(%rsp)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x1c(%rbx),%esi
movss  0x18(%rbx),%xmm0
movaps %xmm0,0x20(%rsp)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x20(%rbx),%esi
movss  0x1c(%rbx),%xmm0
movaps %xmm0,0x10(%rsp)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x24(%rbx),%esi
movss  0x20(%rbx),%xmm0
movaps %xmm0,(%rsp)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0xffffffff,%ebp
lea    0xe07(%rip),%rdi
lea    0xdf4(%rip),%rax
cmovl  %rax,%rdi
cmp    %ebp,%r15d
movdqa 0x10(%rsp),%xmm7
movdqa %xmm7,%xmm0
movdqa 0x20(%rsp),%xmm4
punpckldq %xmm4,%xmm0
movd   0x24(%rbx),%xmm1
movdqa (%rsp),%xmm6
punpckldq %xmm6,%xmm1
punpcklqdq %xmm0,%xmm1
movdqa 0x50(%rsp),%xmm3
movdqa %xmm3,%xmm0
movdqa 0x60(%rsp),%xmm2
punpckldq %xmm2,%xmm0
movdqa 0x30(%rsp),%xmm5
punpckldq %xmm5,%xmm4
movdqa %xmm4,%xmm8
movdqa 0x40(%rsp),%xmm4
punpckldq %xmm4,%xmm5
punpcklqdq %xmm0,%xmm5
punpckldq %xmm7,%xmm6
punpcklqdq %xmm8,%xmm6
pcmpgtd %xmm1,%xmm6
movd   %r15d,%xmm0
movdqa %xmm2,%xmm1
punpckldq %xmm0,%xmm1
movdqa %xmm4,%xmm0
punpckldq %xmm3,%xmm0
punpcklqdq %xmm1,%xmm0
pcmpgtd %xmm5,%xmm0
movdqa %xmm0,%xmm1
pcmpeqd %xmm0,%xmm0
pxor   %xmm0,%xmm1
pxor   %xmm0,%xmm6
packssdw %xmm1,%xmm6
psllw  $0xf,%xmm6
packsswb %xmm6,%xmm6
cmovl  %rax,%rdi
pmovmskb %xmm6,%ecx
cmp    $0xff,%cl
cmovne %rax,%rdi
add    $0x78,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

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

LLVM IR (-O2):
@.str = [5 x i8] c"%d, \00"
@str = [12 x i8] c"\0ANOT sorted\00"
@str.3 = [4 x i8] c"\0Aok\00"
define void @printarray(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = load i32, i32* %0
%5 = icmp sgt i32 %4, -2
%6 = getelementptr inbounds i32, i32* %0, i64 1
%7 = load i32, i32* %6
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %6
%10 = icmp sge i32 %9, %4
%11 = and i1 %10, %5
%12 = getelementptr inbounds i32, i32* %0, i64 2
%13 = load i32, i32* %12
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %12
%16 = getelementptr inbounds i32, i32* %0, i64 3
%17 = load i32, i32* %16
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %16
%20 = getelementptr inbounds i32, i32* %0, i64 4
%21 = load i32, i32* %20
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %20
%24 = getelementptr inbounds i32, i32* %0, i64 5
%25 = load i32, i32* %24
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %24
%28 = getelementptr inbounds i32, i32* %0, i64 6
%29 = load i32, i32* %28
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %28
%32 = getelementptr inbounds i32, i32* %0, i64 7
%33 = load i32, i32* %32
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %32
%36 = getelementptr inbounds i32, i32* %0, i64 8
%37 = load i32, i32* %36
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %37)
%39 = load i32, i32* %36
%40 = getelementptr inbounds i32, i32* %0, i64 9
%41 = load i32, i32* %40
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %40
%44 = insertelement <8 x i32> poison, i32 %43, i64 0
%45 = insertelement <8 x i32> %44, i32 %39, i64 1
%46 = insertelement <8 x i32> %45, i32 %35, i64 2
%47 = insertelement <8 x i32> %46, i32 %31, i64 3
%48 = insertelement <8 x i32> %47, i32 %27, i64 4
%49 = insertelement <8 x i32> %48, i32 %23, i64 5
%50 = insertelement <8 x i32> %49, i32 %19, i64 6
%51 = insertelement <8 x i32> %50, i32 %15, i64 7
%52 = insertelement <8 x i32> poison, i32 %39, i64 0
%53 = insertelement <8 x i32> %52, i32 %35, i64 1
%54 = insertelement <8 x i32> %53, i32 %31, i64 2
%55 = insertelement <8 x i32> %54, i32 %27, i64 3
%56 = insertelement <8 x i32> %55, i32 %23, i64 4
%57 = insertelement <8 x i32> %56, i32 %19, i64 5
%58 = insertelement <8 x i32> %57, i32 %15, i64 6
%59 = insertelement <8 x i32> %58, i32 %9, i64 7
%60 = icmp sge <8 x i32> %51, %59
%61 = freeze <8 x i1> %60
%62 = bitcast <8 x i1> %61 to i8
%63 = icmp eq i8 %62, -1
%64 = select i1 %63, i1 %11, i1 false
%65 = select i1 %64, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0)
%66 = tail call i32 @puts(i8* dereferenceable(1) %65)
ret void
}