#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 int32_t;
typedef int int16_t;

/* Variables and functions */
unsigned int clamp_s16(int);
void MultSubBlocks(int16_t *dst, const int16_t *src1, const int16_t *src2,
                   unsigned int shift) {
  unsigned int i;
  for (i = 0; i < 64; ++i) {
    int32_t v = src1[i] * src2[i];
    dst[i] = clamp_s16(v) << shift;
  }
}


x86 assembly (clang, -O0):
<MultSubBlocks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x40,-0x20(%rbp)
jae    1177 <MultSubBlocks+0x67>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,4),%eax
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%edx
imul   (%rcx,%rdx,4),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <clamp_s16@plt>
mov    %eax,%edx
mov    -0x1c(%rbp),%ecx
shl    %cl,%edx
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112e <MultSubBlocks+0x1e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MultSubBlocks>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    (%r15,%rbp,4),%edi
imul   (%r12,%rbp,4),%edi
call   1030 <clamp_s16@plt>
mov    %r14d,%ecx
shl    %cl,%eax
mov    %eax,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    $0x40,%rbp
jne    1130 <MultSubBlocks+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @MultSubBlocks(i32* nocapture writeonly %0, i32* nocapture %1, i32* nocapture %2, i32 %3) {
br label %5
5: ; preds = %4, %5
%6 = phi i64 [ 0, %4 ], [ %15, %5 ]
%7 = getelementptr inbounds i32, i32* %1, i64 %6
%8 = load i32, i32* %7
%9 = getelementptr inbounds i32, i32* %2, i64 %6
%10 = load i32, i32* %9
%11 = mul nsw i32 %10, %8
%12 = tail call i32 @clamp_s16(i32 %11)
%13 = shl i32 %12, %3
%14 = getelementptr inbounds i32, i32* %0, i64 %6
store i32 %13, i32* %14
%15 = add nuw nsw i64 %6, 1
%16 = icmp eq i64 %15, 64
br i1 %16, label %17, label %5
17: ; preds = %5
ret void
}