#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_buffer_length_compatible_shape(int, int, int *);
double tic();
double benchmark() {
  double elapsed;
  int8_t b;
  double t;
  int i;
  int64_t ndims = 3;
  int64_t shape[] = {10, 10, 10};
  t = tic();
  for (i = 0; i < 1000000; i++) {
    shape[0] = (int64_t)(rand_double() * 10.0);
    b = stdlib_ndarray_is_buffer_length_compatible_shape(1500, ndims, shape);
    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    11e9 <benchmark+0xa9>
mov    $0x0,%al
call   1050 <rand_double@plt>
movsd  0xe6e(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%esi
lea    -0x2c(%rbp),%rdx
mov    $0x5dc,%edi
call   1060 <stdlib_ndarray_is_buffer_length_compatible_shape@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11d6 <benchmark+0x96>
cmpl   $0x1,-0xc(%rbp)
je     11d6 <benchmark+0x96>
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
jmp    11e9 <benchmark+0xa9>
jmp    11db <benchmark+0x9b>
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     121a <benchmark+0xda>
cmpl   $0x1,-0xc(%rbp)
je     121a <benchmark+0xda>
lea    0xdff(%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>
mulsd  0xe71(%rip),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,0x8(%rsp)
mov    $0x5dc,%edi
mov    $0x3,%esi
mov    %rbx,%rdx
call   1060 <stdlib_ndarray_is_buffer_length_compatible_shape@plt>
cmp    $0x2,%eax
jae    11bc <benchmark+0x7c>
add    $0xffffffff,%ebp
jne    1180 <benchmark+0x40>
xor    %eax,%eax
call   1040 <tic@plt>
jmp    11e6 <benchmark+0xa6>
lea    0xe51(%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.shape = [3 x i32] [i32 10, i32 10, i32 10]
@.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 = %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 = fmul double %13, 1.000000e+01
%15 = fptosi double %14 to i32
%16 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 0
store i32 %15, i32* %16
%17 = load i32, i32* %5
%18 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 0
%19 = call i32 @stdlib_ndarray_is_buffer_length_compatible_shape(i32 1500, i32 %17, i32* %18)
store i32 %19, i32* %2
%20 = load i32, i32* %2
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %12
%23 = load i32, i32* %2
%24 = icmp ne i32 %23, 1
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %31
27: ; preds = %22, %12
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 ne i32 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %31
%38 = load i32, i32* %2
%39 = icmp ne i32 %38, 1
br i1 %39, label %40, label %42
40: ; preds = %37
%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, %31
%43 = load double, double* %1
ret double %43
}

LLVM IR (-O2):
@__const.benchmark.shape = [3 x i32] [i32 10, i32 10, i32 10]
@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 %10
5: ; preds = %10
%6 = add nuw nsw i32 %11, 1
%7 = icmp eq i32 %6, 1000000
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = call double (...) @tic()
br label %21
10: ; preds = %0, %5
%11 = phi i32 [ 0, %0 ], [ %6, %5 ]
%12 = call double (...) @rand_double()
%13 = fmul double %12, 1.000000e+01
%14 = fptosi double %13 to i32
store i32 %14, i32* %4
%15 = call i32 @stdlib_ndarray_is_buffer_length_compatible_shape(i32 1500, i32 3, i32* %4)
%16 = icmp ult i32 %15, 2
br i1 %16, label %5, label %17
17: ; preds = %10
%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 = %8, %17
%22 = phi double [ %9, %8 ], [ %19, %17 ]
%23 = fsub double %22, %3
ret double %23
}