#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*/ threadscan_fatal(char *, int, int, size_t, size_t);
void assert_monotonicity(size_t *a, int n) {
  size_t last = 0;
  int i;
  for (i = 0; i < n; ++i) {
    if (a[i] <= last) {
      threadscan_fatal("The list is not monotonic at position %d "
                       "out of %d (%llu, last: %llu)\n",
                       i, n, a[i], last);
    }
    last = a[i];
  }
}


x86 assembly (clang, -O0):
<assert_monotonicity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1190 <assert_monotonicity+0x80>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
cmp    -0x18(%rbp),%rax
ja     1172 <assert_monotonicity+0x62>
mov    -0x1c(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x18(%rbp),%r8
lea    0xe93(%rip),%rdi
call   1030 <threadscan_fatal@plt>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112e <assert_monotonicity+0x1e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<assert_monotonicity>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1158 <assert_monotonicity+0x48>
mov    %rdi,%r14
mov    %esi,%r15d
xor    %ebx,%ebx
lea    0xed5(%rip),%r12
xor    %r8d,%r8d
jmp    113c <assert_monotonicity+0x2c>
add    $0x1,%rbx
mov    %rcx,%r8
cmp    %rbx,%r15
je     1158 <assert_monotonicity+0x48>
mov    (%r14,%rbx,8),%rcx
cmp    %r8,%rcx
ja     1130 <assert_monotonicity+0x20>
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
call   1030 <threadscan_fatal@plt>
mov    (%r14,%rbx,8),%rcx
jmp    1130 <assert_monotonicity+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [71 x i8] c"The list is not monotonic at position %d out of %d (%llu, last: %llu)\0A\00"
define void @assert_monotonicity(i64* %0, i32 %1) {
%3 = alloca i64*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
store i64* %0, i64** %3
store i32 %1, i32* %4
store i64 0, i64* %5
store i32 0, i32* %6
br label %7
7: ; preds = %35, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %38
11: ; preds = %7
%12 = load i64*, i64** %3
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i64, i64* %12, i64 %14
%16 = load i64, i64* %15
%17 = load i64, i64* %5
%18 = icmp ule i64 %16, %17
br i1 %18, label %19, label %29
19: ; preds = %11
%20 = load i32, i32* %6
%21 = load i32, i32* %4
%22 = load i64*, i64** %3
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i64, i64* %22, i64 %24
%26 = load i64, i64* %25
%27 = load i64, i64* %5
%28 = call i32 @threadscan_fatal(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %21, i64 %26, i64 %27)
br label %29
29: ; preds = %19, %11
%30 = load i64*, i64** %3
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i64, i64* %30, i64 %32
%34 = load i64, i64* %33
store i64 %34, i64* %5
br label %35
35: ; preds = %29
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %7
38: ; preds = %7
ret void
}

LLVM IR (-O2):
@.str = [71 x i8] c"The list is not monotonic at position %d out of %d (%llu, last: %llu)\0A\00"
define void @assert_monotonicity(i64* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %20
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %16
%7 = phi i64 [ 0, %4 ], [ %18, %16 ]
%8 = phi i64 [ 0, %4 ], [ %17, %16 ]
%9 = getelementptr inbounds i64, i64* %0, i64 %7
%10 = load i64, i64* %9
%11 = icmp ugt i64 %10, %8
br i1 %11, label %16, label %12
12: ; preds = %6
%13 = trunc i64 %7 to i32
%14 = tail call i32 @threadscan_fatal(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %1, i64 %10, i64 %8)
%15 = load i64, i64* %9
br label %16
16: ; preds = %12, %6
%17 = phi i64 [ %15, %12 ], [ %10, %6 ]
%18 = add nuw nsw i64 %7, 1
%19 = icmp eq i64 %18, %5
br i1 %19, label %20, label %6
20: ; preds = %16, %2
ret void
}