#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 */
typedef int int64_t;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ printf(char *);
int print_sorted(int64_t *a, size_t num_elements) {
  bool sorted = true;
  for (int i = 0; i < num_elements; ++i) {
    if (a[i] != i + 1) {
      sorted = false;
      break;
    }
  }
  if (sorted) {
    printf("\nArray successfully sorted!\n");
    return EXIT_SUCCESS;
  } else {
    printf("\nArray is not sorted!\n");
    return EXIT_FAILURE;
  }
  return EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<print_sorted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movslq -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1174 <print_sorted+0x64>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
je     1161 <print_sorted+0x51>
movl   $0x0,-0x1c(%rbp)
jmp    1174 <print_sorted+0x64>
jmp    1166 <print_sorted+0x56>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112e <print_sorted+0x1e>
cmpl   $0x0,-0x1c(%rbp)
je     119b <print_sorted+0x8b>
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11b3 <print_sorted+0xa3>
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_sorted>:
push   %rbx
mov    %rdi,%rax
xor    %ecx,%ecx
mov    0x2ebb(%rip),%rbx
lea    0xef2(%rip),%rdi
mov    0x2eb5(%rip),%r8
lea    0xece(%rip),%r9
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    %rcx,%rsi
je     1157 <print_sorted+0x47>
mov    (%rax,%rcx,4),%edx
add    $0x1,%rcx
cmp    %rdx,%rcx
je     1140 <print_sorted+0x30>
mov    %r9,%rdi
mov    %r8,%rbx
call   1030 <puts@plt>
mov    (%rbx),%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@str = [22 x i8] c"\0AArray is not sorted!\00"
@str.2 = [28 x i8] c"\0AArray successfully sorted!\00"
define i32 @print_sorted(i32* nocapture %0, i64 %1) {
br label %3
3: ; preds = %6, %2
%4 = phi i64 [ %9, %6 ], [ 0, %2 ]
%5 = icmp eq i64 %4, %1
br i1 %5, label %12, label %6
6: ; preds = %3
%7 = getelementptr inbounds i32, i32* %0, i64 %4
%8 = load i32, i32* %7
%9 = add nuw i64 %4, 1
%10 = zext i32 %8 to i64
%11 = icmp eq i64 %9, %10
br i1 %11, label %3, label %12
12: ; preds = %6, %3
%13 = phi i8* [ getelementptr inbounds ([28 x i8], [28 x i8]* @str.2, i64 0, i64 0), %3 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0), %6 ]
%14 = phi i32* [ @EXIT_SUCCESS, %3 ], [ @EXIT_FAILURE, %6 ]
%15 = tail call i32 @puts(i8* dereferenceable(1) %13)
%16 = load i32, i32* %14
ret i32 %16
}