#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_iteration_order(int, int *);
double tic();
double benchmark() {
  double elapsed;
  int8_t o;
  double t;
  int i;
  int64_t strides[] = {3, 2, 1};
  int64_t ndims = 3;
  t = tic();
  for (i = 0; i < 1000000; i++) {
    strides[0] = (int64_t)((rand_double() * 10.0) - 5.0);
    o = stdlib_ndarray_iteration_order(ndims, strides);
    if (o > 1 || o < -1) {
      printf("unexpected result\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (o > 1 || o < -1) {
    printf("unexpected result\n");
  }
  return elapsed;
}


x86 assembly (clang, -O0):
<benchmark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xec1(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xebf(%rip),%eax
mov    %eax,-0x20(%rbp)
movl   $0x3,-0x2c(%rbp)
mov    $0x0,%al
call   1050 <tic@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xf4240,-0x1c(%rbp)
jge    11f0 <benchmark+0xb0>
mov    $0x0,%al
call   1060 <rand_double@plt>
movsd  0xe6e(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe6a(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1030 <stdlib_ndarray_iteration_order@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jg     11cc <benchmark+0x8c>
cmpl   $0xffffffff,-0xc(%rbp)
jge    11dd <benchmark+0x9d>
lea    0xe49(%rip),%rdi
call   1040 <printf@plt>
jmp    11f0 <benchmark+0xb0>
jmp    11e2 <benchmark+0xa2>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1176 <benchmark+0x36>
mov    $0x0,%al
call   1050 <tic@plt>
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
cmpl   $0x1,-0xc(%rbp)
jg     1215 <benchmark+0xd5>
cmpl   $0xffffffff,-0xc(%rbp)
jge    1221 <benchmark+0xe1>
lea    0xe00(%rip),%rdi
call   1040 <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    0xecc(%rip),%eax
mov    %eax,0x10(%rsp)
mov    0xeb9(%rip),%rax
mov    %rax,0x8(%rsp)
xor    %eax,%eax
call   1050 <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   1060 <rand_double@plt>
mulsd  0xe71(%rip),%xmm0
addsd  0xe71(%rip),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,0x8(%rsp)
mov    $0x3,%edi
mov    %rbx,%rsi
call   1040 <stdlib_ndarray_iteration_order@plt>
add    $0xfffffffe,%eax
cmp    $0xfffffffd,%eax
jb     11c2 <benchmark+0x82>
add    $0xffffffff,%ebp
jne    1180 <benchmark+0x40>
xor    %eax,%eax
call   1050 <tic@plt>
jmp    11ec <benchmark+0xac>
lea    0xe53(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <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 3, i32 2, 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 [3 x i32]
%6 = alloca i32
%7 = bitcast [3 x i32]* %5 to i8*
store i32 3, i32* %6
%8 = call double (...) @tic()
store double %8, double* %3
store i32 0, i32* %4
br label %9
9: ; preds = %28, %0
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 1000000
br i1 %11, label %12, label %31
12: ; preds = %9
%13 = call double (...) @rand_double()
%14 = call double @llvm.fmuladd.f64(double %13, double 1.000000e+01, double -5.000000e+00)
%15 = fptosi double %14 to i32
%16 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 0
store i32 %15, i32* %16
%17 = load i32, i32* %6
%18 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 0
%19 = call i32 @stdlib_ndarray_iteration_order(i32 %17, i32* %18)
store i32 %19, i32* %2
%20 = load i32, i32* %2
%21 = icmp sgt i32 %20, 1
br i1 %21, label %25, label %22
22: ; preds = %12
%23 = load i32, i32* %2
%24 = icmp slt i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %22, %12
%26 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %31
27: ; preds = %22
br label %28
28: ; preds = %27
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %9
31: ; preds = %25, %9
%32 = call double (...) @tic()
%33 = load double, double* %3
%34 = fsub double %32, %33
store double %34, double* %1
%35 = load i32, i32* %2
%36 = icmp sgt i32 %35, 1
br i1 %36, label %40, label %37
37: ; preds = %31
%38 = load i32, i32* %2
%39 = icmp slt i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %37, %31
%41 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %42
42: ; preds = %40, %37
%43 = load double, double* %1
ret double %43
}

LLVM IR (-O2):
@__const.benchmark.strides = [3 x i32] [i32 3, i32 2, 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 0
br label %8
5: ; preds = %8
%6 = add nuw nsw i32 %9, 1
%7 = icmp eq i32 %6, 1000000
br i1 %7, label %16, label %8
8: ; preds = %0, %5
%9 = phi i32 [ 0, %0 ], [ %6, %5 ]
%10 = call double (...) @rand_double()
%11 = call double @llvm.fmuladd.f64(double %10, double 1.000000e+01, double -5.000000e+00)
%12 = fptosi double %11 to i32
store i32 %12, i32* %4
%13 = call i32 @stdlib_ndarray_iteration_order(i32 3, i32* %4)
%14 = add i32 %13, -2
%15 = icmp ult i32 %14, -3
br i1 %15, label %18, label %5
16: ; preds = %5
%17 = call double (...) @tic()
br label %22
18: ; preds = %8
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.1, i64 0, i64 0))
%20 = call double (...) @tic()
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.1, i64 0, i64 0))
br label %22
22: ; preds = %16, %18
%23 = phi double [ %17, %16 ], [ %20, %18 ]
%24 = fsub double %23, %3
ret double %24
}