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

/* Variables and functions */
int64_t stdlib_ndarray_min_view_buffer_index(int64_t ndims, int64_t *shape,
                                             int64_t *strides, int64_t offset) {
  int64_t idx;
  int64_t i;
  idx = offset;
  for (i = 0; i < ndims; i++) {
    if (strides[i] < 0) {
      idx += strides[i] * (shape[i] - 1);
    }
  }
  return idx;
}


x86 assembly (clang, -O0):
<stdlib_ndarray_min_view_buffer_index>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    1183 <stdlib_ndarray_min_view_buffer_index+0x83>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jae    116d <stdlib_ndarray_min_view_buffer_index+0x6d>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x10(%rbp),%rcx
mov    -0x30(%rbp),%rdx
mov    (%rcx,%rdx,8),%rcx
sub    $0x1,%rcx
imul   %rcx,%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1172 <stdlib_ndarray_min_view_buffer_index+0x72>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1124 <stdlib_ndarray_min_view_buffer_index+0x24>
mov    -0x28(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<stdlib_ndarray_min_view_buffer_index>:
mov    %rcx,%rax
ret

LLVM IR (-O0):
define i64 @stdlib_ndarray_min_view_buffer_index(i64 %0, i64* %1, i64* %2, i64 %3) {
%5 = alloca i64
%6 = alloca i64*
%7 = alloca i64*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i64 %0, i64* %5
store i64* %1, i64** %6
store i64* %2, i64** %7
store i64 %3, i64* %8
%11 = load i64, i64* %8
store i64 %11, i64* %9
store i64 0, i64* %10
br label %12
12: ; preds = %36, %4
%13 = load i64, i64* %10
%14 = load i64, i64* %5
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %39
16: ; preds = %12
%17 = load i64*, i64** %7
%18 = load i64, i64* %10
%19 = getelementptr inbounds i64, i64* %17, i64 %18
%20 = load i64, i64* %19
%21 = icmp ult i64 %20, 0
br i1 %21, label %22, label %35
22: ; preds = %16
%23 = load i64*, i64** %7
%24 = load i64, i64* %10
%25 = getelementptr inbounds i64, i64* %23, i64 %24
%26 = load i64, i64* %25
%27 = load i64*, i64** %6
%28 = load i64, i64* %10
%29 = getelementptr inbounds i64, i64* %27, i64 %28
%30 = load i64, i64* %29
%31 = sub i64 %30, 1
%32 = mul i64 %26, %31
%33 = load i64, i64* %9
%34 = add i64 %33, %32
store i64 %34, i64* %9
br label %35
35: ; preds = %22, %16
br label %36
36: ; preds = %35
%37 = load i64, i64* %10
%38 = add i64 %37, 1
store i64 %38, i64* %10
br label %12
39: ; preds = %12
%40 = load i64, i64* %9
ret i64 %40
}

LLVM IR (-O2):
define i64 @stdlib_ndarray_min_view_buffer_index(i64 %0, i64* nocapture readnone %1, i64* nocapture readnone %2, i64 returned %3) {
ret i64 %3
}