#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 /*<<< orphan*/ uint8_t;

/* Variables and functions */
bool rd_sorted(const void *base, size_t nmemb, size_t size,
               int (*cmp)(const void *, const void *)) {
  if (nmemb < 2) {
    return true;
  }
  register uint8_t *a = (uint8_t *)base, *b = (uint8_t *)base + size,
                   *end = (uint8_t *)base + (size * nmemb);
  while (b != end) {
    if (cmp((void *)a, (void *)b) > 0) {
      return false;
    }
    a = b, b += size;
  }
  return true;
}


x86 assembly (clang, -O0):
<rd_sorted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x2,-0x18(%rbp)
jae    112f <rd_sorted+0x2f>
movl   $0x1,-0x4(%rbp)
jmp    11b7 <rd_sorted+0xb7>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
imul   -0x18(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x40(%rbp),%rax
je     11b0 <rd_sorted+0xb0>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   *%rax
cmp    $0x0,%eax
jle    1193 <rd_sorted+0x93>
movl   $0x0,-0x4(%rbp)
jmp    11b7 <rd_sorted+0xb7>
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x2,%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1162 <rd_sorted+0x62>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rd_sorted>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%eax
cmp    $0x2,%rsi
jb     1160 <rd_sorted+0x60>
mov    %rcx,%r15
mov    %rdx,%rbp
mov    %rdi,%r12
lea    -0x4(,%rsi,4),%rbx
ff
imul   %rdx,%rbx
lea    (%rdi,%rdx,4),%r13
shl    $0x2,%rbp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
cmp    %r14,%rbx
je     115b <rd_sorted+0x5b>
lea    (%r12,%r14,1),%rdi
lea    (%r14,%r13,1),%rsi
call   *%r15
add    %rbp,%r14
test   %eax,%eax
jle    1140 <rd_sorted+0x40>
xor    %eax,%eax
jmp    1160 <rd_sorted+0x60>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @rd_sorted(i8* %0, i64 %1, i64 %2, i32 (i8*, i8*)* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32 (i8*, i8*)*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
store i8* %0, i8** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i32 (i8*, i8*)* %3, i32 (i8*, i8*)** %9
%13 = load i64, i64* %7
%14 = icmp ult i64 %13, 2
br i1 %14, label %15, label %16
15: ; preds = %4
store i32 1, i32* %5
br label %48
16: ; preds = %4
%17 = load i8*, i8** %6
%18 = bitcast i8* %17 to i32*
store i32* %18, i32** %10
%19 = load i8*, i8** %6
%20 = bitcast i8* %19 to i32*
%21 = load i64, i64* %8
%22 = getelementptr inbounds i32, i32* %20, i64 %21
store i32* %22, i32** %11
%23 = load i8*, i8** %6
%24 = bitcast i8* %23 to i32*
%25 = load i64, i64* %8
%26 = load i64, i64* %7
%27 = mul i64 %25, %26
%28 = getelementptr inbounds i32, i32* %24, i64 %27
store i32* %28, i32** %12
br label %29
29: ; preds = %42, %16
%30 = load i32*, i32** %11
%31 = load i32*, i32** %12
%32 = icmp ne i32* %30, %31
br i1 %32, label %33, label %47
33: ; preds = %29
%34 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %9
%35 = load i32*, i32** %10
%36 = bitcast i32* %35 to i8*
%37 = load i32*, i32** %11
%38 = bitcast i32* %37 to i8*
%39 = call i32 %34(i8* %36, i8* %38)
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %33
store i32 0, i32* %5
br label %48
42: ; preds = %33
%43 = load i32*, i32** %11
store i32* %43, i32** %10
%44 = load i64, i64* %8
%45 = load i32*, i32** %11
%46 = getelementptr inbounds i32, i32* %45, i64 %44
store i32* %46, i32** %11
br label %29
47: ; preds = %29
store i32 1, i32* %5
br label %48
48: ; preds = %47, %41, %15
%49 = load i32, i32* %5
ret i32 %49
}

LLVM IR (-O2):
define i32 @rd_sorted(i8* %0, i64 %1, i64 %2, i32 (i8*, i8*)* nocapture %3) {
%5 = icmp ult i64 %1, 2
br i1 %5, label %19, label %6
6: ; preds = %4
%7 = bitcast i8* %0 to i32*
%8 = mul i64 %2, %1
%9 = getelementptr inbounds i32, i32* %7, i64 %8
br label %10
10: ; preds = %14, %6
%11 = phi i32* [ %7, %6 ], [ %12, %14 ]
%12 = getelementptr inbounds i32, i32* %11, i64 %2
%13 = icmp eq i32* %12, %9
br i1 %13, label %19, label %14
14: ; preds = %10
%15 = bitcast i32* %11 to i8*
%16 = bitcast i32* %12 to i8*
%17 = tail call i32 %3(i8* %15, i8* %16)
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %10
19: ; preds = %14, %10, %4
%20 = phi i32 [ 1, %4 ], [ 1, %10 ], [ 0, %14 ]
ret i32 %20
}