#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 scalar_t__ int8_t;
typedef int int64_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
scalar_t__ stdlib_ndarray_broadcast_shapes(int, int **, int *, int *);
double tic();
double benchmark() {
  double elapsed;
  int8_t status;
  double t;
  int i;
  int64_t sh1[] = {8, 1, 6, 1};
  int64_t sh2[] = {7, 1, 5};
  int64_t ndims[] = {4, 3};
  int64_t *shapes[] = {sh1, sh2};
  int64_t out[] = {0, 0, 0, 0};
  t = tic();
  for (i = 0; i < 1000000; i++) {
    status = stdlib_ndarray_broadcast_shapes(2, shapes, ndims, out);
    if (status != 0) {
      printf("unexpected result\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (out[0] != 8) {
    printf("unexpected result\n");
  }
  if (out[1] != 7) {
    printf("unexpected result\n");
  }
  if (out[2] != 6) {
    printf("unexpected result\n");
  }
  if (out[3] != 5) {
    printf("unexpected result\n");
  }
  return elapsed;
}


x86 assembly (clang, -O0):
<benchmark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0xeb1(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeae(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xeab(%rip),%rax
mov    %rax,-0x3c(%rbp)
mov    0xea9(%rip),%eax
mov    %eax,-0x34(%rbp)
mov    0xea3(%rip),%rax
mov    %rax,-0x44(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    -0x3c(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    $0x0,%al
call   1040 <tic@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xf4240,-0x1c(%rbp)
jge    1206 <benchmark+0xc6>
lea    -0x60(%rbp),%rsi
lea    -0x44(%rbp),%rdx
lea    -0x70(%rbp),%rcx
mov    $0x2,%edi
call   1060 <stdlib_ndarray_broadcast_shapes@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11f3 <benchmark+0xb3>
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
jmp    1206 <benchmark+0xc6>
jmp    11f8 <benchmark+0xb8>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b0 <benchmark+0x70>
mov    $0x0,%al
call   1040 <tic@plt>
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
cmpl   $0x8,-0x70(%rbp)
je     122d <benchmark+0xed>
lea    0xdfc(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x7,-0x6c(%rbp)
je     1243 <benchmark+0x103>
lea    0xde6(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x6,-0x68(%rbp)
je     1259 <benchmark+0x119>
lea    0xdd0(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x5,-0x64(%rbp)
je     126f <benchmark+0x12f>
lea    0xdba(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmark>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
movaps 0xebf(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
mov    0xecc(%rip),%eax
mov    %eax,0x38(%rsp)
mov    0xeb9(%rip),%rax
mov    %rax,0x30(%rsp)
movabs $0x300000004,%rax
mov    %rax,0x28(%rsp)
lea    0x50(%rsp),%rax
mov    %rax,0x40(%rsp)
lea    0x30(%rsp),%rax
mov    %rax,0x48(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
xor    %eax,%eax
call   1040 <tic@plt>
movsd  %xmm0,0x20(%rsp)
mov    $0xf4240,%ebp
lea    0x40(%rsp),%r14
lea    0x28(%rsp),%r15
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x2,%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1050 <stdlib_ndarray_broadcast_shapes@plt>
test   %rax,%rax
jne    11cf <benchmark+0x9f>
add    $0xffffffff,%ebp
jne    11b0 <benchmark+0x80>
jmp    11db <benchmark+0xab>
lea    0xe46(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <tic@plt>
movsd  %xmm0,0x18(%rsp)
cmpl   $0x8,(%rsp)
jne    1226 <benchmark+0xf6>
cmpl   $0x7,0x4(%rsp)
jne    1239 <benchmark+0x109>
cmpl   $0x6,0x8(%rsp)
jne    124c <benchmark+0x11c>
cmpl   $0x5,0xc(%rsp)
je     120f <benchmark+0xdf>
lea    0xe12(%rip),%rdi
call   1030 <puts@plt>
movsd  0x18(%rsp),%xmm0
subsd  0x20(%rsp),%xmm0
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdef(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x7,0x4(%rsp)
je     11f5 <benchmark+0xc5>
lea    0xddc(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x6,0x8(%rsp)
je     11fc <benchmark+0xcc>
lea    0xdc9(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x5,0xc(%rsp)
jne    1203 <benchmark+0xd3>
jmp    120f <benchmark+0xdf>

LLVM IR (-O0):
@__const.benchmark.sh1 = [4 x i32] [i32 8, i32 1, i32 6, i32 1]
@__const.benchmark.sh2 = [3 x i32] [i32 7, i32 1, i32 5]
@__const.benchmark.ndims = [2 x i32] [i32 4, i32 3]
@.str = [19 x i8] c"unexpected result\0A\00"
define double @benchmark() {
%1 = alloca double
%2 = alloca i64
%3 = alloca double
%4 = alloca i32
%5 = alloca [4 x i32]
%6 = alloca [3 x i32]
%7 = alloca [2 x i32]
%8 = alloca [2 x i32*]
%9 = alloca [4 x i32]
%10 = bitcast [4 x i32]* %5 to i8*
%11 = bitcast [3 x i32]* %6 to i8*
%12 = bitcast [2 x i32]* %7 to i8*
%13 = getelementptr inbounds [2 x i32*], [2 x i32*]* %8, i64 0, i64 0
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
store i32* %14, i32** %13
%15 = getelementptr inbounds i32*, i32** %13, i64 1
%16 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 0
store i32* %16, i32** %15
%17 = bitcast [4 x i32]* %9 to i8*
%18 = call double (...) @tic()
store double %18, double* %3
store i32 0, i32* %4
br label %19
19: ; preds = %32, %0
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 1000000
br i1 %21, label %22, label %35
22: ; preds = %19
%23 = getelementptr inbounds [2 x i32*], [2 x i32*]* %8, i64 0, i64 0
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%25 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
%26 = call i64 @stdlib_ndarray_broadcast_shapes(i32 2, i32** %23, i32* %24, i32* %25)
store i64 %26, i64* %2
%27 = load i64, i64* %2
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %22
%30 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %35
31: ; preds = %22
br label %32
32: ; preds = %31
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %19
35: ; preds = %29, %19
%36 = call double (...) @tic()
%37 = load double, double* %3
%38 = fsub double %36, %37
store double %38, double* %1
%39 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
%40 = load i32, i32* %39
%41 = icmp ne i32 %40, 8
br i1 %41, label %42, label %44
42: ; preds = %35
%43 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %44
44: ; preds = %42, %35
%45 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 1
%46 = load i32, i32* %45
%47 = icmp ne i32 %46, 7
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %50
50: ; preds = %48, %44
%51 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 2
%52 = load i32, i32* %51
%53 = icmp ne i32 %52, 6
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %56
56: ; preds = %54, %50
%57 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 3
%58 = load i32, i32* %57
%59 = icmp ne i32 %58, 5
br i1 %59, label %60, label %62
60: ; preds = %56
%61 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %62
62: ; preds = %60, %56
%63 = load double, double* %1
ret double %63
}

LLVM IR (-O2):
@__const.benchmark.sh1 = [4 x i32] [i32 8, i32 1, i32 6, i32 1]
@__const.benchmark.sh2 = [3 x i32] [i32 7, i32 1, i32 5]
@str.4 = [18 x i8] c"unexpected result\00"
define double @benchmark() {
%1 = alloca [4 x i32]
%2 = alloca [3 x i32]
%3 = alloca i64
%4 = alloca [2 x i32*]
%5 = alloca [4 x i32]
%6 = bitcast [4 x i32]* %1 to i8*
%7 = bitcast [3 x i32]* %2 to i8*
%8 = bitcast i64* %3 to i8*
store i64 12884901892, i64* %3
%9 = bitcast [2 x i32*]* %4 to i8*
%10 = getelementptr inbounds [2 x i32*], [2 x i32*]* %4, i64 0, i64 0
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 0
store i32* %11, i32** %10
%12 = getelementptr inbounds [2 x i32*], [2 x i32*]* %4, i64 0, i64 1
%13 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
store i32* %13, i32** %12
%14 = bitcast [4 x i32]* %5 to i8*
%15 = call double (...) @tic()
%16 = bitcast i64* %3 to i32*
%17 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
br label %21
18: ; preds = %21
%19 = add nuw nsw i32 %22, 1
%20 = icmp eq i32 %19, 1000000
br i1 %20, label %27, label %21
21: ; preds = %0, %18
%22 = phi i32 [ 0, %0 ], [ %19, %18 ]
%23 = call i64 @stdlib_ndarray_broadcast_shapes(i32 2, i32** %10, i32* %16, i32* %17)
%24 = icmp eq i64 %23, 0
br i1 %24, label %18, label %25
25: ; preds = %21
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.4, i64 0, i64 0))
br label %27
27: ; preds = %18, %25
%28 = call double (...) @tic()
%29 = load i32, i32* %17
%30 = icmp eq i32 %29, 8
br i1 %30, label %33, label %31
31: ; preds = %27
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.4, i64 0, i64 0))
br label %33
33: ; preds = %31, %27
%34 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 1
%35 = load i32, i32* %34
%36 = icmp eq i32 %35, 7
br i1 %36, label %39, label %37
37: ; preds = %33
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.4, i64 0, i64 0))
br label %39
39: ; preds = %37, %33
%40 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 2
%41 = load i32, i32* %40
%42 = icmp eq i32 %41, 6
br i1 %42, label %45, label %43
43: ; preds = %39
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.4, i64 0, i64 0))
br label %45
45: ; preds = %43, %39
%46 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 3
%47 = load i32, i32* %46
%48 = icmp eq i32 %47, 5
br i1 %48, label %51, label %49
49: ; preds = %45
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.4, i64 0, i64 0))
br label %51
51: ; preds = %49, %45
%52 = fsub double %28, %15
ret double %52
}