#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 /*<<< orphan*/ multiply(unsigned char, unsigned char);
unsigned char sum(int /*<<< orphan*/, unsigned char);
unsigned char inner_product(unsigned char *a, unsigned char *b, size_t len) {
  unsigned char result = 0;
  for (int i = 0; i < len; i++) {
    result = sum(multiply(a[i], b[i]), result);
  }
  return result;
}


x86 assembly (clang, -O0):
<inner_product>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
movl   $0x0,-0x20(%rbp)
movslq -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1188 <inner_product+0x68>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl %dl,%edi
movzbl (%rax,%rcx,1),%esi
call   1030 <multiply@plt>
mov    %eax,%edi
movzbl -0x19(%rbp),%esi
call   1040 <sum@plt>
mov    %al,-0x19(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    113f <inner_product+0x1f>
movzbl -0x19(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inner_product>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdx,%rdx
je     1167 <inner_product+0x47>
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%edi
movzbl (%r14,%rbx,1),%esi
call   1030 <multiply@plt>
movzbl %bpl,%esi
mov    %eax,%edi
call   1040 <sum@plt>
mov    %eax,%ebp
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1140 <inner_product+0x20>
jmp    1169 <inner_product+0x49>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i8 @inner_product(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i8 0, i8* %7
store i32 0, i32* %8
br label %9
9: ; preds = %28, %3
%10 = load i32, i32* %8
%11 = sext i32 %10 to i64
%12 = load i64, i64* %6
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %31
14: ; preds = %9
%15 = load i8*, i8** %4
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = load i8*, i8** %5
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = call i32 @multiply(i8 zeroext %19, i8 zeroext %24)
%26 = load i8, i8* %7
%27 = call zeroext i8 @sum(i32 %25, i8 zeroext %26)
store i8 %27, i8* %7
br label %28
28: ; preds = %14
%29 = load i32, i32* %8
%30 = add nsw i32 %29, 1
store i32 %30, i32* %8
br label %9
31: ; preds = %9
%32 = load i8, i8* %7
ret i8 %32
}

LLVM IR (-O2):
define zeroext i8 @inner_product(i8* nocapture %0, i8* nocapture %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %5, label %7
5: ; preds = %7, %3
%6 = phi i8 [ 0, %3 ], [ %15, %7 ]
ret i8 %6
7: ; preds = %3, %7
%8 = phi i64 [ %16, %7 ], [ 0, %3 ]
%9 = phi i8 [ %15, %7 ], [ 0, %3 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %8
%11 = load i8, i8* %10
%12 = getelementptr inbounds i8, i8* %1, i64 %8
%13 = load i8, i8* %12
%14 = tail call i32 @multiply(i8 zeroext %11, i8 zeroext %13)
%15 = tail call zeroext i8 @sum(i32 %14, i8 zeroext %9)
%16 = add nuw i64 %8, 1
%17 = icmp eq i64 %16, %2
br i1 %17, label %5, label %7
}