#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 */

/* Variables and functions */
double tensor_dot(double *, double const *, unsigned int);
int /*<<< orphan*/ tensor_mxm(double *, unsigned int const, double const *,
                              unsigned int, double const *, int);
int /*<<< orphan*/ tensor_mxv(double *, unsigned int, double *, double const *,
                              unsigned int);
double tensor_ig3(double g[3], const double *wtr, unsigned int nr,
                  const double *wts, unsigned int ns, const double *wtt,
                  unsigned int nt, const double *u, double *work) {
  const unsigned int nrs = nr * ns;
  double *a = work, *b = work + 2 * nrs, *c = b + 2 * nr;
  tensor_mxm(a, nrs, u, nt, wtt, 2);
  tensor_mxm(b, nr, a, ns, wts, 2);
  tensor_mxv(c, nr, a + nrs, wts, ns);
  g[0] = tensor_dot(b, wtr + nr, nr);
  g[1] = tensor_dot(b + nr, wtr, nr);
  g[2] = tensor_dot(c, wtr, nr);
  return tensor_dot(b, wtr, nr);
}


x86 assembly (clang, -O0):
<tensor_ig3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x20(%rbp),%rax
mov    -0x34(%rbp),%ecx
shl    $0x1,%ecx
mov    %ecx,%ecx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x1,%ecx
mov    %ecx,%ecx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    0x18(%rbp),%rdx
mov    0x10(%rbp),%ecx
mov    -0x30(%rbp),%r8
mov    $0x2,%r9d
call   1050 <tensor_mxm@plt>
mov    -0x48(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x40(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%r8
mov    $0x2,%r9d
call   1050 <tensor_mxm@plt>
mov    -0x50(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x40(%rbp),%rdx
mov    -0x34(%rbp),%eax
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
call   1040 <tensor_mxv@plt>
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%eax
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
call   1030 <tensor_dot@plt>
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x48(%rbp),%rdi
mov    -0x14(%rbp),%eax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <tensor_dot@plt>
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <tensor_dot@plt>
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <tensor_dot@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tensor_ig3>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%ebx
mov    %rcx,%r14
mov    %edx,%r12d
mov    %rsi,0x8(%rsp)
mov    %rdi,0x10(%rsp)
mov    0x58(%rsp),%rdx
mov    0x50(%rsp),%ecx
mov    0x60(%rsp),%r15
mov    %r8d,%r13d
imul   %r12d,%r13d
lea    0x0(%r13,%r13,1),%eax
lea    (%r15,%rax,8),%rbp
lea    (%r12,%r12,1),%eax
lea    0x0(,%rax,8),%rax
add    %rbp,%rax
mov    %rax,(%rsp)
mov    %r15,%rdi
mov    %r13d,%esi
mov    %r9,%r8
mov    $0x2,%r9d
call   1050 <tensor_mxm@plt>
mov    %rbp,%rdi
mov    %r12d,%esi
mov    %r15,%rdx
mov    %ebx,%ecx
mov    %r14,%r8
mov    $0x2,%r9d
call   1050 <tensor_mxm@plt>
lea    (%r15,%r13,8),%rdx
mov    (%rsp),%r13
mov    %r13,%rdi
mov    %r12d,%esi
mov    %r14,%rcx
mov    %ebx,%r8d
call   1040 <tensor_mxv@plt>
mov    %r12d,%r15d
mov    0x8(%rsp),%rbx
lea    (%rbx,%r15,8),%rsi
mov    %rbp,%rdi
mov    %r12d,%edx
call   1030 <tensor_dot@plt>
mov    0x10(%rsp),%r14
movsd  %xmm0,(%r14)
lea    0x0(,%r15,8),%rdi
add    %rbp,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1030 <tensor_dot@plt>
movsd  %xmm0,0x8(%r14)
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1030 <tensor_dot@plt>
movsd  %xmm0,0x10(%r14)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <tensor_dot@plt>

LLVM IR (-O0):
define double @tensor_ig3(double* %0, double* %1, i32 %2, double* %3, i32 %4, double* %5, i32 %6, double* %7, double* %8) {
%10 = alloca double*
%11 = alloca double*
%12 = alloca i32
%13 = alloca double*
%14 = alloca i32
%15 = alloca double*
%16 = alloca i32
%17 = alloca double*
%18 = alloca double*
%19 = alloca i32
%20 = alloca double*
%21 = alloca double*
%22 = alloca double*
store double* %0, double** %10
store double* %1, double** %11
store i32 %2, i32* %12
store double* %3, double** %13
store i32 %4, i32* %14
store double* %5, double** %15
store i32 %6, i32* %16
store double* %7, double** %17
store double* %8, double** %18
%23 = load i32, i32* %12
%24 = load i32, i32* %14
%25 = mul i32 %23, %24
store i32 %25, i32* %19
%26 = load double*, double** %18
store double* %26, double** %20
%27 = load double*, double** %18
%28 = load i32, i32* %19
%29 = mul i32 2, %28
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds double, double* %27, i64 %30
store double* %31, double** %21
%32 = load double*, double** %21
%33 = load i32, i32* %12
%34 = mul i32 2, %33
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds double, double* %32, i64 %35
store double* %36, double** %22
%37 = load double*, double** %20
%38 = load i32, i32* %19
%39 = load double*, double** %17
%40 = load i32, i32* %16
%41 = load double*, double** %15
%42 = call i32 @tensor_mxm(double* %37, i32 %38, double* %39, i32 %40, double* %41, i32 2)
%43 = load double*, double** %21
%44 = load i32, i32* %12
%45 = load double*, double** %20
%46 = load i32, i32* %14
%47 = load double*, double** %13
%48 = call i32 @tensor_mxm(double* %43, i32 %44, double* %45, i32 %46, double* %47, i32 2)
%49 = load double*, double** %22
%50 = load i32, i32* %12
%51 = load double*, double** %20
%52 = load i32, i32* %19
%53 = zext i32 %52 to i64
%54 = getelementptr inbounds double, double* %51, i64 %53
%55 = load double*, double** %13
%56 = load i32, i32* %14
%57 = call i32 @tensor_mxv(double* %49, i32 %50, double* %54, double* %55, i32 %56)
%58 = load double*, double** %21
%59 = load double*, double** %11
%60 = load i32, i32* %12
%61 = zext i32 %60 to i64
%62 = getelementptr inbounds double, double* %59, i64 %61
%63 = load i32, i32* %12
%64 = call double @tensor_dot(double* %58, double* %62, i32 %63)
%65 = load double*, double** %10
%66 = getelementptr inbounds double, double* %65, i64 0
store double %64, double* %66
%67 = load double*, double** %21
%68 = load i32, i32* %12
%69 = zext i32 %68 to i64
%70 = getelementptr inbounds double, double* %67, i64 %69
%71 = load double*, double** %11
%72 = load i32, i32* %12
%73 = call double @tensor_dot(double* %70, double* %71, i32 %72)
%74 = load double*, double** %10
%75 = getelementptr inbounds double, double* %74, i64 1
store double %73, double* %75
%76 = load double*, double** %22
%77 = load double*, double** %11
%78 = load i32, i32* %12
%79 = call double @tensor_dot(double* %76, double* %77, i32 %78)
%80 = load double*, double** %10
%81 = getelementptr inbounds double, double* %80, i64 2
store double %79, double* %81
%82 = load double*, double** %21
%83 = load double*, double** %11
%84 = load i32, i32* %12
%85 = call double @tensor_dot(double* %82, double* %83, i32 %84)
ret double %85
}

LLVM IR (-O2):
define double @tensor_ig3(double* nocapture writeonly %0, double* %1, i32 %2, double* %3, i32 %4, double* %5, i32 %6, double* %7, double* %8) {
%10 = mul i32 %4, %2
%11 = shl i32 %10, 1
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds double, double* %8, i64 %12
%14 = shl i32 %2, 1
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds double, double* %13, i64 %15
%17 = tail call i32 @tensor_mxm(double* %8, i32 %10, double* %7, i32 %6, double* %5, i32 2)
%18 = tail call i32 @tensor_mxm(double* %13, i32 %2, double* %8, i32 %4, double* %3, i32 2)
%19 = zext i32 %10 to i64
%20 = getelementptr inbounds double, double* %8, i64 %19
%21 = tail call i32 @tensor_mxv(double* %16, i32 %2, double* %20, double* %3, i32 %4)
%22 = zext i32 %2 to i64
%23 = getelementptr inbounds double, double* %1, i64 %22
%24 = tail call double @tensor_dot(double* %13, double* %23, i32 %2)
store double %24, double* %0
%25 = getelementptr inbounds double, double* %13, i64 %22
%26 = tail call double @tensor_dot(double* %25, double* %1, i32 %2)
%27 = getelementptr inbounds double, double* %0, i64 1
store double %26, double* %27
%28 = tail call double @tensor_dot(double* %16, double* %1, i32 %2)
%29 = getelementptr inbounds double, double* %0, i64 2
store double %28, double* %29
%30 = tail call double @tensor_dot(double* %13, double* %1, i32 %2)
ret double %30
}