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

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
double rand_double();
int stdlib_ndarray_is_row_major(int, int *);
double tic();
double benchmark() {
  double elapsed;
  int8_t b;
  double t;
  int i;
  int64_t ndims = 3;
  int64_t strides[] = {100, 10, 1};
  t = tic();
  for (i = 0; i < 1000000; i++) {
    strides[2] *= (rand_double() < 0.5) ? -1 : 1;
    b = stdlib_ndarray_is_row_major(ndims, strides);
    if (b != 0 && b != 1) {
      printf("unexpected result\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (b != 0 && b != 1) {
    printf("unexpected result\n");
  }
  return elapsed;
}


x86 assembly (clang, -O0):
<benchmark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x3,-0x20(%rbp)
mov    0xeb2(%rip),%rax
mov    %rax,-0x2c(%rbp)
mov    0xeb0(%rip),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1040 <tic@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xf4240,-0x1c(%rbp)
jge    11f4 <benchmark+0xb4>
mov    $0x0,%al
call   1050 <rand_double@plt>
movaps %xmm0,%xmm1
movsd  0xe6b(%rip),%xmm0
mov    $0x1,%eax
mov    $0xffffffff,%ecx
ucomisd %xmm1,%xmm0
cmova  %ecx,%eax
imul   -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x2c(%rbp),%rsi
call   1060 <stdlib_ndarray_is_row_major@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11e1 <benchmark+0xa1>
cmpl   $0x1,-0xc(%rbp)
je     11e1 <benchmark+0xa1>
lea    0xe3d(%rip),%rdi
call   1030 <printf@plt>
jmp    11f4 <benchmark+0xb4>
jmp    11e6 <benchmark+0xa6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1176 <benchmark+0x36>
mov    $0x0,%al
call   1040 <tic@plt>
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1225 <benchmark+0xe5>
cmpl   $0x1,-0xc(%rbp)
je     1225 <benchmark+0xe5>
lea    0xdf4(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmark>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    0xec4(%rip),%eax
mov    %eax,0x10(%rsp)
mov    0xeb1(%rip),%rax
mov    %rax,0x8(%rsp)
xor    %eax,%eax
call   1040 <tic@plt>
movsd  %xmm0,0x20(%rsp)
mov    $0xf4240,%ebp
lea    0x8(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1050 <rand_double@plt>
mov    0x10(%rsp),%eax
mov    %eax,%ecx
neg    %ecx
movsd  0xe69(%rip),%xmm1
ucomisd %xmm0,%xmm1
cmovbe %eax,%ecx
mov    %ecx,0x10(%rsp)
mov    $0x3,%edi
mov    %rbx,%rsi
call   1060 <stdlib_ndarray_is_row_major@plt>
cmp    $0x2,%eax
jae    11c2 <benchmark+0x82>
add    $0xffffffff,%ebp
jne    1180 <benchmark+0x40>
xor    %eax,%eax
call   1040 <tic@plt>
jmp    11ec <benchmark+0xac>
lea    0xe4b(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <tic@plt>
movsd  %xmm0,0x18(%rsp)
mov    %rbx,%rdi
call   1030 <puts@plt>
movsd  0x18(%rsp),%xmm0
subsd  0x20(%rsp),%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.benchmark.strides = [3 x i32] [i32 100, i32 10, i32 1]
@.str = [19 x i8] c"unexpected result\0A\00"
define double @benchmark() {
%1 = alloca double
%2 = alloca i32
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
%6 = alloca [3 x i32]
store i32 3, i32* %5
%7 = bitcast [3 x i32]* %6 to i8*
%8 = call double (...) @tic()
store double %8, double* %3
store i32 0, i32* %4
br label %9
9: ; preds = %31, %0
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 1000000
br i1 %11, label %12, label %34
12: ; preds = %9
%13 = call double (...) @rand_double()
%14 = fcmp olt double %13, 5.000000e-01
%15 = zext i1 %14 to i64
%16 = select i1 %14, i32 -1, i32 1
%17 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 2
%18 = load i32, i32* %17
%19 = mul nsw i32 %18, %16
store i32 %19, i32* %17
%20 = load i32, i32* %5
%21 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 0
%22 = call i32 @stdlib_ndarray_is_row_major(i32 %20, i32* %21)
store i32 %22, i32* %2
%23 = load i32, i32* %2
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %12
%26 = load i32, i32* %2
%27 = icmp ne i32 %26, 1
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %34
30: ; preds = %25, %12
br label %31
31: ; preds = %30
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %9
34: ; preds = %28, %9
%35 = call double (...) @tic()
%36 = load double, double* %3
%37 = fsub double %35, %36
store double %37, double* %1
%38 = load i32, i32* %2
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %34
%41 = load i32, i32* %2
%42 = icmp ne i32 %41, 1
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %45
45: ; preds = %43, %40, %34
%46 = load double, double* %1
ret double %46
}

LLVM IR (-O2):
@__const.benchmark.strides = [3 x i32] [i32 100, i32 10, i32 1]
@str.1 = [18 x i8] c"unexpected result\00"
define double @benchmark() {
%1 = alloca [3 x i32]
%2 = bitcast [3 x i32]* %1 to i8*
%3 = tail call double (...) @tic()
%4 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 2
%5 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
br label %11
6: ; preds = %11
%7 = add nuw nsw i32 %12, 1
%8 = icmp eq i32 %7, 1000000
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = call double (...) @tic()
br label %24
11: ; preds = %0, %6
%12 = phi i32 [ 0, %0 ], [ %7, %6 ]
%13 = call double (...) @rand_double()
%14 = fcmp olt double %13, 5.000000e-01
%15 = load i32, i32* %4
%16 = sub nsw i32 0, %15
%17 = select i1 %14, i32 %16, i32 %15
store i32 %17, i32* %4
%18 = call i32 @stdlib_ndarray_is_row_major(i32 3, i32* %5)
%19 = icmp ult i32 %18, 2
br i1 %19, label %6, label %20
20: ; preds = %11
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.1, i64 0, i64 0))
%22 = call double (...) @tic()
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.1, i64 0, i64 0))
br label %24
24: ; preds = %9, %20
%25 = phi double [ %10, %9 ], [ %22, %20 ]
%26 = fsub double %25, %3
ret double %26
}