#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 /*<<< orphan*/ int64_t;
typedef int /*<<< orphan*/ int32_t;
typedef int int16_t;

/* Variables and functions */
int /*<<< orphan*/ accumTimesVec32(int const, int /*<<< orphan*/ const,
                                   int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ accumVec16(int const, int const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ zeroVec32(int const, int /*<<< orphan*/ *);
int /*<<< orphan*/ zeroVec64(int const, int /*<<< orphan*/ *);
void transducePackedMulti(const int16_t ns, const int16_t q0,
                          const int16_t dims, const int16_t *restrict tmat,
                          const int16_t *restrict tcounts,
                          const int16_t *restrict fcounts,
                          const int16_t *restrict cstream,
                          int32_t *restrict fstream, int64_t *restrict out) {
  zeroVec64(dims, out);
  int32_t wacc[dims];
  zeroVec32(dims, wacc);
  int16_t st = q0;
  const int16_t *citer = cstream;
  const int32_t *fiter = fstream;
  while (1) {
    const int16_t c = *citer;
    if (c == -2) {
      return;
    }
    if (c == -1) {
      accumVec16(dims, fcounts + (st * dims), wacc);
      accumTimesVec32(dims, *fiter, wacc, out);
      zeroVec32(dims, wacc);
      st = q0;
      ++fiter;
      ++citer;
    } else {
      int i = (c * ns) + st;
      st = tmat[i];
      accumVec16(dims, tcounts + (i * dims), wacc);
      ++citer;
    }
  }
}


x86 assembly (clang, -O0):
<transducePackedMulti>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0xc(%rbp),%edi
mov    0x20(%rbp),%rsi
call   1060 <zeroVec64@plt>
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x60(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <zeroVec32@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    11bf <transducePackedMulti+0x7f>
mov    -0x48(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
cmpl   $0xfffffffe,-0x54(%rbp)
jne    11de <transducePackedMulti+0x9e>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret
cmpl   $0xffffffff,-0x54(%rbp)
jne    124d <transducePackedMulti+0x10d>
mov    -0x60(%rbp),%rdx
mov    -0xc(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x3c(%rbp),%eax
imul   -0xc(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
call   1050 <accumVec16@plt>
mov    -0x60(%rbp),%rdx
mov    -0xc(%rbp),%edi
mov    -0x50(%rbp),%rax
mov    (%rax),%esi
mov    0x20(%rbp),%rcx
call   1030 <accumTimesVec32@plt>
mov    -0x60(%rbp),%rsi
mov    -0xc(%rbp),%edi
call   1040 <zeroVec32@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x50(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x48(%rbp)
jmp    1294 <transducePackedMulti+0x154>
mov    -0x60(%rbp),%rdx
mov    -0x54(%rbp),%eax
imul   -0x4(%rbp),%eax
add    -0x3c(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x58(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x3c(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x58(%rbp),%eax
imul   -0xc(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
call   1050 <accumVec16@plt>
mov    -0x48(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x48(%rbp)
jmp    11ba <transducePackedMulti+0x7a>

x86 assembly (clang, -O2):
<transducePackedMulti>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,-0x48(%rbp)
mov    %r8,-0x40(%rbp)
mov    %rcx,-0x38(%rbp)
mov    %edx,%ebx
mov    %esi,%r13d
mov    %edi,-0x2c(%rbp)
mov    0x20(%rbp),%rsi
mov    0x18(%rbp),%r12
mov    0x10(%rbp),%r14
mov    %edx,%edi
call   1060 <zeroVec64@plt>
mov    %ebx,%eax
mov    %rsp,%r15
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %ebx,%edi
mov    %r15,%rsi
call   1040 <zeroVec32@plt>
mov    %r13d,-0x30(%rbp)
jmp    11e1 <transducePackedMulti+0xa1>
nop
imul   %ebx,%r13d
movslq %r13d,%rax
mov    -0x48(%rbp),%rcx
lea    (%rcx,%rax,4),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
call   1050 <accumVec16@plt>
mov    (%r12),%esi
mov    %ebx,%edi
mov    %r15,%rdx
mov    0x20(%rbp),%rcx
call   1030 <accumTimesVec32@plt>
mov    %ebx,%edi
mov    %r15,%rsi
call   1040 <zeroVec32@plt>
add    $0x4,%r12
add    $0x4,%r14
mov    -0x30(%rbp),%r13d
mov    (%r14),%eax
cmp    $0xffffffff,%eax
je     11a0 <transducePackedMulti+0x60>
cmp    $0xfffffffe,%eax
je     121c <transducePackedMulti+0xdc>
imul   -0x2c(%rbp),%eax
add    %r13d,%eax
cltq
mov    -0x38(%rbp),%rcx
mov    (%rcx,%rax,4),%r13d
imul   %ebx,%eax
cltq
mov    -0x40(%rbp),%rcx
lea    (%rcx,%rax,4),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
call   1050 <accumVec16@plt>
add    $0x4,%r14
jmp    11e1 <transducePackedMulti+0xa1>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @transducePackedMulti(i32 %0, i32 %1, i32 %2, i32* noalias %3, i32* noalias %4, i32* noalias %5, i32* noalias %6, i32* noalias %7, i32* noalias %8) {
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32*
%17 = alloca i32*
%18 = alloca i32*
%19 = alloca i8*
%20 = alloca i64
%21 = alloca i32
%22 = alloca i32*
%23 = alloca i32*
%24 = alloca i32
%25 = alloca i32
store i32 %0, i32* %10
store i32 %1, i32* %11
store i32 %2, i32* %12
store i32* %3, i32** %13
store i32* %4, i32** %14
store i32* %5, i32** %15
store i32* %6, i32** %16
store i32* %7, i32** %17
store i32* %8, i32** %18
%26 = load i32, i32* %12
%27 = load i32*, i32** %18
%28 = call i32 @zeroVec64(i32 %26, i32* %27)
%29 = load i32, i32* %12
%30 = zext i32 %29 to i64
%31 = call i8* @llvm.stacksave()
store i8* %31, i8** %19
%32 = alloca i32, i64 %30
store i64 %30, i64* %20
%33 = load i32, i32* %12
%34 = call i32 @zeroVec32(i32 %33, i32* %32)
%35 = load i32, i32* %11
store i32 %35, i32* %21
%36 = load i32*, i32** %16
store i32* %36, i32** %22
%37 = load i32*, i32** %17
store i32* %37, i32** %23
br label %38
38: ; preds = %91, %9
br label %39
39: ; preds = %38
%40 = load i32*, i32** %22
%41 = load i32, i32* %40
store i32 %41, i32* %24
%42 = load i32, i32* %24
%43 = icmp eq i32 %42, -2
br i1 %43, label %44, label %46
44: ; preds = %39
%45 = load i8*, i8** %19
ret void
46: ; preds = %39
%47 = load i32, i32* %24
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %70
49: ; preds = %46
%50 = load i32, i32* %12
%51 = load i32*, i32** %15
%52 = load i32, i32* %21
%53 = load i32, i32* %12
%54 = mul nsw i32 %52, %53
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %51, i64 %55
%57 = call i32 @accumVec16(i32 %50, i32* %56, i32* %32)
%58 = load i32, i32* %12
%59 = load i32*, i32** %23
%60 = load i32, i32* %59
%61 = load i32*, i32** %18
%62 = call i32 @accumTimesVec32(i32 %58, i32 %60, i32* %32, i32* %61)
%63 = load i32, i32* %12
%64 = call i32 @zeroVec32(i32 %63, i32* %32)
%65 = load i32, i32* %11
store i32 %65, i32* %21
%66 = load i32*, i32** %23
%67 = getelementptr inbounds i32, i32* %66, i32 1
store i32* %67, i32** %23
%68 = load i32*, i32** %22
%69 = getelementptr inbounds i32, i32* %68, i32 1
store i32* %69, i32** %22
br label %91
70: ; preds = %46
%71 = load i32, i32* %24
%72 = load i32, i32* %10
%73 = mul nsw i32 %71, %72
%74 = load i32, i32* %21
%75 = add nsw i32 %73, %74
store i32 %75, i32* %25
%76 = load i32*, i32** %13
%77 = load i32, i32* %25
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i32, i32* %76, i64 %78
%80 = load i32, i32* %79
store i32 %80, i32* %21
%81 = load i32, i32* %12
%82 = load i32*, i32** %14
%83 = load i32, i32* %25
%84 = load i32, i32* %12
%85 = mul nsw i32 %83, %84
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i32, i32* %82, i64 %86
%88 = call i32 @accumVec16(i32 %81, i32* %87, i32* %32)
%89 = load i32*, i32** %22
%90 = getelementptr inbounds i32, i32* %89, i32 1
store i32* %90, i32** %22
br label %91
91: ; preds = %70, %49
br label %38
}

LLVM IR (-O2):
define void @transducePackedMulti(i32 %0, i32 %1, i32 %2, i32* noalias nocapture %3, i32* noalias %4, i32* noalias %5, i32* noalias nocapture %6, i32* noalias nocapture %7, i32* noalias %8) {
%10 = tail call i32 @zeroVec64(i32 %2, i32* %8)
%11 = zext i32 %2 to i64
%12 = alloca i32, i64 %11
%13 = call i32 @zeroVec32(i32 %2, i32* %12)
br label %14
14: ; preds = %38, %9
%15 = phi i32* [ %7, %9 ], [ %39, %38 ]
%16 = phi i32* [ %6, %9 ], [ %41, %38 ]
%17 = phi i32 [ %1, %9 ], [ %40, %38 ]
%18 = load i32, i32* %16
switch i32 %18, label %28 [
i32 -2, label %42
i32 -1, label %19
]
19: ; preds = %14
%20 = mul nsw i32 %17, %2
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %5, i64 %21
%23 = call i32 @accumVec16(i32 %2, i32* %22, i32* %12)
%24 = load i32, i32* %15
%25 = call i32 @accumTimesVec32(i32 %2, i32 %24, i32* %12, i32* %8)
%26 = call i32 @zeroVec32(i32 %2, i32* %12)
%27 = getelementptr inbounds i32, i32* %15, i64 1
br label %38
28: ; preds = %14
%29 = mul nsw i32 %18, %0
%30 = add nsw i32 %29, %17
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %3, i64 %31
%33 = load i32, i32* %32
%34 = mul nsw i32 %30, %2
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %4, i64 %35
%37 = call i32 @accumVec16(i32 %2, i32* %36, i32* %12)
br label %38
38: ; preds = %19, %28
%39 = phi i32* [ %27, %19 ], [ %15, %28 ]
%40 = phi i32 [ %1, %19 ], [ %33, %28 ]
%41 = getelementptr inbounds i32, i32* %16, i64 1
br label %14
42: ; preds = %14
ret void
}