#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*/ abort();
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(size_t);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, size_t);
int /*<<< orphan*/ multiply(unsigned char, unsigned char);
unsigned char sum(int /*<<< orphan*/, unsigned char);
void inner_product_set(unsigned char *result, unsigned char *A,
                       unsigned char *x, size_t in_len, size_t out_len) {
  unsigned char *x_copy = malloc(in_len);
  if (!x_copy)
    abort();
  memcpy(x_copy, x, in_len);
  for (int i = 0; i < out_len; i++) {
    unsigned char tmp = 0;
    for (int j = 0; j < in_len; j++) {
      tmp = sum(multiply(A[in_len * i + j], x_copy[j]), tmp);
    }
    result[i] = tmp;
  }
  free(x_copy);
}


x86 assembly (clang, -O0):
<inner_product_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    119b <inner_product_set+0x3b>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <memcpy@plt>
movl   $0x0,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1240 <inner_product_set+0xe0>
movb   $0x0,-0x35(%rbp)
movl   $0x0,-0x3c(%rbp)
movslq -0x3c(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1224 <inner_product_set+0xc4>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq -0x34(%rbp),%rdx
imul   %rdx,%rcx
movslq -0x3c(%rbp),%rdx
add    %rdx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movzbl %dl,%edi
movzbl (%rax,%rcx,1),%esi
call   1050 <multiply@plt>
mov    %eax,%edi
movzbl -0x35(%rbp),%esi
call   1070 <sum@plt>
mov    %al,-0x35(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11cc <inner_product_set+0x6c>
mov    -0x35(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11b3 <inner_product_set+0x53>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inner_product_set>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%rbp
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,0x10(%rsp)
mov    %rcx,%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     121e <inner_product_set+0xbe>
mov    %rax,%r13
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <memcpy@plt>
test   %rbp,%rbp
je     1208 <inner_product_set+0xa8>
xor    %r12d,%r12d
mov    %rbp,0x8(%rsp)
jmp    11cc <inner_product_set+0x6c>
xor    %ebp,%ebp
mov    0x10(%rsp),%rax
mov    %bpl,(%rax,%r12,1)
add    $0x1,%r12
add    %r15,%rbx
mov    0x8(%rsp),%rbp
cmp    %rbp,%r12
je     1208 <inner_product_set+0xa8>
test   %r15,%r15
je     11b0 <inner_product_set+0x50>
xor    %r14d,%r14d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
movzbl (%rbx,%r14,1),%edi
movzbl 0x0(%r13,%r14,1),%esi
call   1050 <multiply@plt>
movzbl %bpl,%esi
mov    %eax,%edi
call   1070 <sum@plt>
mov    %eax,%ebp
add    $0x1,%r14
cmp    %r14,%r15
jne    11e0 <inner_product_set+0x80>
jmp    11b2 <inner_product_set+0x52>
mov    %r13,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
define void @inner_product_set(i8* %0, i8* %1, i8* %2, i64 %3, i64 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8
%14 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
store i64 %4, i64* %10
%15 = load i64, i64* %9
%16 = call i8* @malloc(i64 %15)
store i8* %16, i8** %11
%17 = load i8*, i8** %11
%18 = icmp ne i8* %17, null
br i1 %18, label %21, label %19
19: ; preds = %5
%20 = call i32 (...) @abort()
unreachable
21: ; preds = %5
%22 = load i8*, i8** %11
%23 = load i8*, i8** %8
%24 = load i64, i64* %9
%25 = call i32 @memcpy(i8* %22, i8* %23, i64 %24)
store i32 0, i32* %12
br label %26
26: ; preds = %65, %21
%27 = load i32, i32* %12
%28 = sext i32 %27 to i64
%29 = load i64, i64* %10
%30 = icmp ult i64 %28, %29
br i1 %30, label %31, label %68
31: ; preds = %26
store i8 0, i8* %13
store i32 0, i32* %14
br label %32
32: ; preds = %56, %31
%33 = load i32, i32* %14
%34 = sext i32 %33 to i64
%35 = load i64, i64* %9
%36 = icmp ult i64 %34, %35
br i1 %36, label %37, label %59
37: ; preds = %32
%38 = load i8*, i8** %7
%39 = load i64, i64* %9
%40 = load i32, i32* %12
%41 = sext i32 %40 to i64
%42 = mul i64 %39, %41
%43 = load i32, i32* %14
%44 = sext i32 %43 to i64
%45 = add i64 %42, %44
%46 = getelementptr inbounds i8, i8* %38, i64 %45
%47 = load i8, i8* %46
%48 = load i8*, i8** %11
%49 = load i32, i32* %14
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = load i8, i8* %51
%53 = call i32 @multiply(i8 zeroext %47, i8 zeroext %52)
%54 = load i8, i8* %13
%55 = call zeroext i8 @sum(i32 %53, i8 zeroext %54)
store i8 %55, i8* %13
br label %56
56: ; preds = %37
%57 = load i32, i32* %14
%58 = add nsw i32 %57, 1
store i32 %58, i32* %14
br label %32
59: ; preds = %32
%60 = load i8, i8* %13
%61 = load i8*, i8** %6
%62 = load i32, i32* %12
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
store i8 %60, i8* %64
br label %65
65: ; preds = %59
%66 = load i32, i32* %12
%67 = add nsw i32 %66, 1
store i32 %67, i32* %12
br label %26
68: ; preds = %26
%69 = load i8*, i8** %11
%70 = call i32 @free(i8* %69)
ret void
}

LLVM IR (-O2):
define void @inner_product_set(i8* nocapture writeonly %0, i8* nocapture %1, i8* %2, i64 %3, i64 %4) {
%6 = tail call i8* @malloc(i64 %3)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 (...) @abort()
unreachable
10: ; preds = %5
%11 = tail call i32 @memcpy(i8* %6, i8* %2, i64 %3)
%12 = icmp eq i64 %4, 0
br i1 %12, label %19, label %13
13: ; preds = %10
%14 = icmp eq i64 %3, 0
br label %15
15: ; preds = %13, %21
%16 = phi i64 [ 0, %13 ], [ %24, %21 ]
br i1 %14, label %21, label %17
17: ; preds = %15
%18 = mul i64 %16, %3
br label %26
19: ; preds = %21, %10
%20 = tail call i32 @free(i8* %6)
ret void
21: ; preds = %26, %15
%22 = phi i8 [ 0, %15 ], [ %35, %26 ]
%23 = getelementptr inbounds i8, i8* %0, i64 %16
store i8 %22, i8* %23
%24 = add nuw i64 %16, 1
%25 = icmp eq i64 %24, %4
br i1 %25, label %19, label %15
26: ; preds = %17, %26
%27 = phi i64 [ 0, %17 ], [ %36, %26 ]
%28 = phi i8 [ 0, %17 ], [ %35, %26 ]
%29 = add i64 %27, %18
%30 = getelementptr inbounds i8, i8* %1, i64 %29
%31 = load i8, i8* %30
%32 = getelementptr inbounds i8, i8* %6, i64 %27
%33 = load i8, i8* %32
%34 = tail call i32 @multiply(i8 zeroext %31, i8 zeroext %33)
%35 = tail call zeroext i8 @sum(i32 %34, i8 zeroext %28)
%36 = add nuw i64 %27, 1
%37 = icmp eq i64 %36, %3
br i1 %37, label %21, label %26
}