#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 *);
int stdlib_ndarray_numel(int, int *);
double tic();
double benchmark() {
  double elapsed;
  int64_t n;
  double t;
  int i;
  int64_t shape[] = {20, 19, 18};
  int64_t ndims = 3;
  t = tic();
  for (i = 0; i < 1000000; i++) {
    shape[0] = (int64_t)((100 % (i + 1)) + 10);
    n = stdlib_ndarray_numel(ndims, shape);
    if (n < 10) {
      printf("unexpected result\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (n < 10) {
    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    11c4 <benchmark+0x94>
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    $0x64,%eax
cltd
idiv   %ecx
add    $0xa,%edx
mov    %edx,-0x28(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1030 <stdlib_ndarray_numel@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    11b1 <benchmark+0x81>
lea    0xe65(%rip),%rdi
call   1040 <printf@plt>
jmp    11c4 <benchmark+0x94>
jmp    11b6 <benchmark+0x86>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1166 <benchmark+0x36>
mov    $0x0,%al
call   1050 <tic@plt>
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    11eb <benchmark+0xbb>
lea    0xe26(%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    $0x1,%ebp
lea    0x8(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0xf4241,%ebp
je     11c9 <benchmark+0x99>
mov    $0x64,%eax
xor    %edx,%edx
div    %ebp
add    $0xa,%edx
mov    %edx,0x8(%rsp)
mov    $0x3,%edi
mov    %rbx,%rsi
call   1030 <stdlib_ndarray_numel@plt>
add    $0x1,%ebp
cmp    $0xa,%eax
jge    1170 <benchmark+0x40>
lea    0xe68(%rip),%rbx
mov    %rbx,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1050 <tic@plt>
movsd  %xmm0,0x18(%rsp)
mov    %rbx,%rdi
call   1040 <puts@plt>
movsd  0x18(%rsp),%xmm0
jmp    11d0 <benchmark+0xa0>
xor    %eax,%eax
call   1050 <tic@plt>
subsd  0x20(%rsp),%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.benchmark.shape = [3 x i32] [i32 20, i32 19, i32 18]
@.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 = load i32, i32* %4
%14 = add nsw i32 %13, 1
%15 = srem i32 100, %14
%16 = add nsw i32 %15, 10
%17 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 0
store i32 %16, i32* %17
%18 = load i32, i32* %6
%19 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 0
%20 = call i32 @stdlib_ndarray_numel(i32 %18, i32* %19)
store i32 %20, i32* %2
%21 = load i32, i32* %2
%22 = icmp slt i32 %21, 10
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 = icmp slt i32 %33, 10
br i1 %34, label %35, label %37
35: ; preds = %29
%36 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %37
37: ; preds = %35, %29
%38 = load double, double* %1
ret double %38
}

LLVM IR (-O2):
@__const.benchmark.shape = [3 x i32] [i32 20, i32 19, i32 18]
@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 %5
5: ; preds = %8, %0
%6 = phi i32 [ 0, %0 ], [ %9, %8 ]
%7 = icmp eq i32 %6, 1000000
br i1 %7, label %14, label %8
8: ; preds = %5
%9 = add nuw nsw i32 %6, 1
%10 = urem i32 100, %9
%11 = add nuw nsw i32 %10, 10
store i32 %11, i32* %4
%12 = call i32 @stdlib_ndarray_numel(i32 3, i32* %4)
%13 = icmp slt i32 %12, 10
br i1 %13, label %16, label %5
14: ; preds = %5
%15 = call double (...) @tic()
br label %20
16: ; preds = %8
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.1, i64 0, i64 0))
%18 = call double (...) @tic()
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.1, i64 0, i64 0))
br label %20
20: ; preds = %14, %16
%21 = phi double [ %18, %16 ], [ %15, %14 ]
%22 = fsub double %21, %3
ret double %22
}