#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 int8_t;
typedef size_t int64_t;

/* Variables and functions */
size_t llabs(size_t);
int8_t stdlib_ndarray_is_column_major(int64_t ndims, int64_t *strides) {
  int64_t s1;
  int64_t s2;
  int64_t i;
  if (ndims == 0) {
    return 0;
  }
  s1 = llabs(strides[0]);
  for (i = 1; i < ndims; i++) {
    s2 = llabs(strides[i]);
    if (s2 < s1) {
      return 0;
    }
    s1 = s2;
  }
  return 1;
}


x86 assembly (clang, -O0):
<stdlib_ndarray_is_column_major>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1137 <stdlib_ndarray_is_column_major+0x27>
movl   $0x0,-0x4(%rbp)
jmp    11ac <stdlib_ndarray_is_column_major+0x9c>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <llabs@plt>
mov    %rax,-0x20(%rbp)
movq   $0x1,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11a5 <stdlib_ndarray_is_column_major+0x95>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <llabs@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    118c <stdlib_ndarray_is_column_major+0x7c>
movl   $0x0,-0x4(%rbp)
jmp    11ac <stdlib_ndarray_is_column_major+0x9c>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    114f <stdlib_ndarray_is_column_major+0x3f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stdlib_ndarray_is_column_major>:
xor    %eax,%eax
test   %rdi,%rdi
je     1144 <stdlib_ndarray_is_column_major+0x44>
cmp    $0x1,%rdi
je     113f <stdlib_ndarray_is_column_major+0x3f>
mov    (%rsi),%rdx
mov    %rdx,%rcx
neg    %rcx
cmovs  %rdx,%rcx
mov    $0x1,%edx
nop
mov    %rcx,%r8
mov    (%rsi,%rdx,8),%r9
mov    %r9,%rcx
neg    %rcx
cmovs  %r9,%rcx
cmp    %r8,%rcx
jb     1144 <stdlib_ndarray_is_column_major+0x44>
add    $0x1,%rdx
cmp    %rdx,%rdi
jne    1120 <stdlib_ndarray_is_column_major+0x20>
mov    $0x1,%eax
ret

LLVM IR (-O0):
define i32 @stdlib_ndarray_is_column_major(i64 %0, i64* %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i64 %0, i64* %4
store i64* %1, i64** %5
%9 = load i64, i64* %4
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %3
br label %37
12: ; preds = %2
%13 = load i64*, i64** %5
%14 = getelementptr inbounds i64, i64* %13, i64 0
%15 = load i64, i64* %14
%16 = call i64 @llabs(i64 %15)
store i64 %16, i64* %6
store i64 1, i64* %8
br label %17
17: ; preds = %33, %12
%18 = load i64, i64* %8
%19 = load i64, i64* %4
%20 = icmp ult i64 %18, %19
br i1 %20, label %21, label %36
21: ; preds = %17
%22 = load i64*, i64** %5
%23 = load i64, i64* %8
%24 = getelementptr inbounds i64, i64* %22, i64 %23
%25 = load i64, i64* %24
%26 = call i64 @llabs(i64 %25)
store i64 %26, i64* %7
%27 = load i64, i64* %7
%28 = load i64, i64* %6
%29 = icmp ult i64 %27, %28
br i1 %29, label %30, label %31
30: ; preds = %21
store i32 0, i32* %3
br label %37
31: ; preds = %21
%32 = load i64, i64* %7
store i64 %32, i64* %6
br label %33
33: ; preds = %31
%34 = load i64, i64* %8
%35 = add i64 %34, 1
store i64 %35, i64* %8
br label %17
36: ; preds = %17
store i32 1, i32* %3
br label %37
37: ; preds = %36, %30, %11
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
define i32 @stdlib_ndarray_is_column_major(i64 %0, i64* nocapture %1) {
switch i64 %0, label %3 [
i64 0, label %17
i64 1, label %16
]
3: ; preds = %2
%4 = load i64, i64* %1
%5 = tail call i64 @llvm.abs.i64(i64 %4, i1 true)
br label %8
6: ; preds = %8
%7 = icmp eq i64 %15, %0
br i1 %7, label %17, label %8
8: ; preds = %3, %6
%9 = phi i64 [ %15, %6 ], [ 1, %3 ]
%10 = phi i64 [ %13, %6 ], [ %5, %3 ]
%11 = getelementptr inbounds i64, i64* %1, i64 %9
%12 = load i64, i64* %11
%13 = tail call i64 @llvm.abs.i64(i64 %12, i1 true)
%14 = icmp ult i64 %13, %10
%15 = add nuw i64 %9, 1
br i1 %14, label %17, label %6
16: ; preds = %2
br label %17
17: ; preds = %8, %6, %2, %16
%18 = phi i32 [ 0, %2 ], [ 1, %16 ], [ 0, %8 ], [ 1, %6 ]
ret i32 %18
}