#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 */
int add8(int, int /*<<< orphan*/);
int compress_element(double);
float expand_element(int);
int /*<<< orphan*/ init_compand();
int /*<<< orphan*/ mul8(unsigned char, unsigned char);
float dot8(unsigned char *x, unsigned char *y, int n) {
  int i, sum;
  init_compand();
  sum = compress_element(0.0);
  for (i = 0; i < n; i++) {
    sum = add8(sum, mul8(x[i], y[i]));
  }
  return expand_element(sum);
}


x86 assembly (clang, -O0):
<dot8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    $0x0,%al
call   1030 <init_compand@plt>
xorps  %xmm0,%xmm0
call   1060 <compress_element@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c8 <dot8+0x78>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl %dl,%edi
movzbl (%rax,%rcx,1),%esi
call   1040 <mul8@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%esi
call   1070 <add8@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    117c <dot8+0x2c>
mov    -0x1c(%rbp),%edi
call   1050 <expand_element@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dot8>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%r12
xor    %eax,%eax
call   1030 <init_compand@plt>
xorps  %xmm0,%xmm0
call   1060 <compress_element@plt>
mov    %eax,%ebp
test   %r15d,%r15d
jle    11a3 <dot8+0x53>
mov    %r15d,%r15d
xor    %ebx,%ebx
nopl   0x0(%rax)
movzbl (%r12,%rbx,1),%edi
movzbl (%r14,%rbx,1),%esi
call   1040 <mul8@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1070 <add8@plt>
mov    %eax,%ebp
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1180 <dot8+0x30>
mov    %ebp,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <expand_element@plt>

LLVM IR (-O0):
define float @dot8(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = call i32 (...) @init_compand()
%10 = call i32 @compress_element(double 0.000000e+00)
store i32 %10, i32* %8
store i32 0, i32* %7
br label %11
11: ; preds = %29, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %32
15: ; preds = %11
%16 = load i32, i32* %8
%17 = load i8*, i8** %4
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = load i8*, i8** %5
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = call i32 @mul8(i8 zeroext %21, i8 zeroext %26)
%28 = call i32 @add8(i32 %16, i32 %27)
store i32 %28, i32* %8
br label %29
29: ; preds = %15
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %11
32: ; preds = %11
%33 = load i32, i32* %8
%34 = call float @expand_element(i32 %33)
ret float %34
}

LLVM IR (-O2):
define float @dot8(i8* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32 (...) @init_compand()
%5 = tail call i32 @compress_element(double 0.000000e+00)
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %20
7: ; preds = %3
%8 = zext i32 %2 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %18, %9 ]
%11 = phi i32 [ %5, %7 ], [ %17, %9 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %10
%13 = load i8, i8* %12
%14 = getelementptr inbounds i8, i8* %1, i64 %10
%15 = load i8, i8* %14
%16 = tail call i32 @mul8(i8 zeroext %13, i8 zeroext %15)
%17 = tail call i32 @add8(i32 %11, i32 %16)
%18 = add nuw nsw i64 %10, 1
%19 = icmp eq i64 %18, %8
br i1 %19, label %20, label %9
20: ; preds = %9, %3
%21 = phi i32 [ %5, %3 ], [ %17, %9 ]
%22 = tail call float @expand_element(i32 %21)
ret float %22
}