#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_strides2order(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_strides2order(ndims, strides);
    if (o > 3) {
      printf("unexpected result\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (o > 3) {
    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   1040 <tic@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xf4240,-0x1c(%rbp)
jge    11e6 <benchmark+0xa6>
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   1050 <stdlib_ndarray_strides2order@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x3,-0xc(%rbp)
jle    11d3 <benchmark+0x93>
lea    0xe53(%rip),%rdi
call   1030 <printf@plt>
jmp    11e6 <benchmark+0xa6>
jmp    11d8 <benchmark+0x98>
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   $0x3,-0xc(%rbp)
jle    120d <benchmark+0xcd>
lea    0xe14(%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    0xecc(%rip),%eax
mov    %eax,0x10(%rsp)
mov    0xeb9(%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   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   1050 <stdlib_ndarray_strides2order@plt>
cmp    $0x3,%eax
jg     11bf <benchmark+0x7f>
add    $0xffffffff,%ebp
jne    1180 <benchmark+0x40>
xor    %eax,%eax
call   1040 <tic@plt>
jmp    11e9 <benchmark+0xa9>
lea    0xe56(%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 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 = %25, %0
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 1000000
br i1 %11, label %12, label %28
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_strides2order(i32 %17, i32* %18)
store i32 %19, i32* %2
%20 = load i32, i32* %2
%21 = icmp sgt i32 %20, 3
br i1 %21, label %22, label %24
22: ; preds = %12
%23 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %28
24: ; preds = %12
br label %25
25: ; preds = %24
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %9
28: ; preds = %22, %9
%29 = call double (...) @tic()
%30 = load double, double* %3
%31 = fsub double %29, %30
store double %31, double* %1
%32 = load i32, i32* %2
%33 = icmp sgt i32 %32, 3
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %36
36: ; preds = %34, %28
%37 = load double, double* %1
ret double %37
}

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 %15, 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_strides2order(i32 3, i32* %4)
%14 = icmp sgt i32 %13, 3
br i1 %14, label %17, label %5
15: ; preds = %5
%16 = call double (...) @tic()
br label %21
17: ; preds = %8
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.1, i64 0, i64 0))
%19 = call double (...) @tic()
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.1, i64 0, i64 0))
br label %21
21: ; preds = %15, %17
%22 = phi double [ %19, %17 ], [ %16, %15 ]
%23 = fsub double %22, %3
ret double %23
}