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

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
double rand_double();
int stdlib_ndarray_singleton_dimensions(int, int *);
double tic();
double benchmark() {
  double elapsed;
  int64_t n;
  double t;
  int i;
  int64_t shape[] = {5, 2, 1};
  int64_t ndims = 3;
  t = tic();
  for (i = 0; i < 1000000; i++) {
    shape[0] = (int64_t)(rand_double() * 5.0);
    n = stdlib_ndarray_singleton_dimensions(ndims, shape);
    if (n > ndims) {
      printf("unexpected result\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (n > ndims) {
    printf("unexpected result\n");
  }
  return elapsed;
}


x86 assembly (clang, -O0):
<benchmark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xeb9(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xeb7(%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    11dc <benchmark+0x9c>
mov    $0x0,%al
call   1050 <rand_double@plt>
movsd  0xe6e(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1060 <stdlib_ndarray_singleton_dimensions@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jle    11c9 <benchmark+0x89>
lea    0xe55(%rip),%rdi
call   1030 <printf@plt>
jmp    11dc <benchmark+0x9c>
jmp    11ce <benchmark+0x8e>
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)
mov    -0xc(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jle    1205 <benchmark+0xc5>
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    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    $0x3,%edi
mov    %rbx,%rsi
call   1060 <stdlib_ndarray_singleton_dimensions@plt>
cmp    $0x3,%eax
jg     11b7 <benchmark+0x77>
add    $0xffffffff,%ebp
jne    1180 <benchmark+0x40>
xor    %eax,%eax
call   1040 <tic@plt>
jmp    11e1 <benchmark+0xa1>
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.shape = [3 x i32] [i32 5, 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 = %26, %0
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 1000000
br i1 %11, label %12, label %29
12: ; preds = %9
%13 = call double (...) @rand_double()
%14 = fmul double %13, 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_singleton_dimensions(i32 %17, i32* %18)
store i32 %19, i32* %2
%20 = load i32, i32* %2
%21 = load i32, i32* %6
%22 = icmp sgt i32 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %12
%24 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %29
25: ; preds = %12
br label %26
26: ; preds = %25
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %9
29: ; preds = %23, %9
%30 = call double (...) @tic()
%31 = load double, double* %3
%32 = fsub double %30, %31
store double %32, double* %1
%33 = load i32, i32* %2
%34 = load i32, i32* %6
%35 = icmp sgt i32 %33, %34
br i1 %35, label %36, label %38
36: ; preds = %29
%37 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %38
38: ; preds = %36, %29
%39 = load double, double* %1
ret double %39
}

LLVM IR (-O2):
@__const.benchmark.shape = [3 x i32] [i32 5, 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 = fmul double %10, 5.000000e+00
%12 = fptosi double %11 to i32
store i32 %12, i32* %4
%13 = call i32 @stdlib_ndarray_singleton_dimensions(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
}