#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*/ printf(char *, ...);
float dot_product_in_c(int *n, float **p_input_a, float **p_input_b) {
  int i;
  float dot;
  float *input_a = *p_input_a;
  float *input_b = *p_input_b;
  dot = 0.0;
  printf("calculating dot product of size: %d\n", *n);
  printf("input_a: [ ");
  for (i = 0; i < *n; i++) {
    printf("%f ", *(input_a + i));
  }
  printf("].\n");
  printf("input_b: [ ");
  for (i = 0; i < *n; i++) {
    printf("%f ", *(input_a + i));
  }
  printf("].\n");
  for (i = 0; i < *n; i++) {
    dot = dot + *(input_a + i) * *(input_b + i);
  }
  return dot;
}


x86 assembly (clang, -O0):
<dot_product_in_c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%eax
jge    11a7 <dot_product_in_c+0x97>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe9f(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116b <dot_product_in_c+0x5b>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%eax
jge    1206 <dot_product_in_c+0xf6>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe40(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ca <dot_product_in_c+0xba>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%eax
jge    1264 <dot_product_in_c+0x154>
movss  -0x20(%rbp),%xmm1
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    121b <dot_product_in_c+0x10b>
movss  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dot_product_in_c>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r15
mov    (%rsi),%r13
mov    (%rdx),%r12
mov    (%rdi),%esi
lea    0xec5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xedc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,(%r15)
jle    1181 <dot_product_in_c+0x61>
xor    %ebx,%ebx
lea    0xed2(%rip),%r14
nop
movss  0x0(%r13,%rbx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x1,%rbx
movslq (%r15),%rax
cmp    %rax,%rbx
jl     1160 <dot_product_in_c+0x40>
lea    0xeb9(%rip),%rdi
call   1030 <puts@plt>
lea    0xea1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,(%r15)
jle    11d1 <dot_product_in_c+0xb1>
xor    %ebx,%ebx
lea    0xe87(%rip),%r14
nopw   0x0(%rax,%rax,1)
movss  0x0(%r13,%rbx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x1,%rbx
movslq (%r15),%rax
cmp    %rax,%rbx
jl     11b0 <dot_product_in_c+0x90>
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
mov    (%r15),%ecx
test   %ecx,%ecx
jle    11fa <dot_product_in_c+0xda>
lea    -0x1(%rcx),%rdx
mov    %ecx,%eax
and    $0x3,%eax
cmp    $0x3,%rdx
jae    1202 <dot_product_in_c+0xe2>
xorps  %xmm0,%xmm0
xor    %edx,%edx
jmp    1260 <dot_product_in_c+0x140>
xorps  %xmm0,%xmm0
jmp    1297 <dot_product_in_c+0x177>
and    $0xfffffffc,%ecx
xorps  %xmm0,%xmm0
xor    %edx,%edx
nopw   0x0(%rax,%rax,1)
movss  0x0(%r13,%rdx,4),%xmm1
movss  0x4(%r13,%rdx,4),%xmm2
mulss  (%r12,%rdx,4),%xmm1
mulss  0x4(%r12,%rdx,4),%xmm2
addss  %xmm0,%xmm1
movss  0x8(%r13,%rdx,4),%xmm3
mulss  0x8(%r12,%rdx,4),%xmm3
addss  %xmm1,%xmm2
movss  0xc(%r13,%rdx,4),%xmm0
mulss  0xc(%r12,%rdx,4),%xmm0
addss  %xmm2,%xmm3
addss  %xmm3,%xmm0
add    $0x4,%rdx
cmp    %rdx,%rcx
jne    1210 <dot_product_in_c+0xf0>
test   %rax,%rax
je     1297 <dot_product_in_c+0x177>
lea    (%r12,%rdx,4),%rcx
lea    0x0(,%rdx,4),%rdx
add    %r13,%rdx
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
movss  (%rdx,%rsi,4),%xmm1
mulss  (%rcx,%rsi,4),%xmm1
addss  %xmm1,%xmm0
add    $0x1,%rsi
cmp    %rsi,%rax
jne    1280 <dot_product_in_c+0x160>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [37 x i8] c"calculating dot product of size: %d\0A\00"
@.str.1 = [12 x i8] c"input_a: [ \00"
@.str.2 = [4 x i8] c"%f \00"
@.str.3 = [4 x i8] c"].\0A\00"
@.str.4 = [12 x i8] c"input_b: [ \00"
define float @dot_product_in_c(i32* %0, float** %1, float** %2) {
%4 = alloca i32*
%5 = alloca float**
%6 = alloca float**
%7 = alloca i32
%8 = alloca float
%9 = alloca float*
%10 = alloca float*
store i32* %0, i32** %4
store float** %1, float*** %5
store float** %2, float*** %6
%11 = load float**, float*** %5
%12 = load float*, float** %11
store float* %12, float** %9
%13 = load float**, float*** %6
%14 = load float*, float** %13
store float* %14, float** %10
store float 0.000000e+00, float* %8
%15 = load i32*, i32** %4
%16 = load i32, i32* %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %7
br label %19
19: ; preds = %32, %3
%20 = load i32, i32* %7
%21 = load i32*, i32** %4
%22 = load i32, i32* %21
%23 = icmp slt i32 %20, %22
br i1 %23, label %24, label %35
24: ; preds = %19
%25 = load float*, float** %9
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds float, float* %25, i64 %27
%29 = load float, float* %28
%30 = fpext float %29 to double
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %30)
br label %32
32: ; preds = %24
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %19
35: ; preds = %19
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %7
br label %38
38: ; preds = %51, %35
%39 = load i32, i32* %7
%40 = load i32*, i32** %4
%41 = load i32, i32* %40
%42 = icmp slt i32 %39, %41
br i1 %42, label %43, label %54
43: ; preds = %38
%44 = load float*, float** %9
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds float, float* %44, i64 %46
%48 = load float, float* %47
%49 = fpext float %48 to double
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %49)
br label %51
51: ; preds = %43
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %38
54: ; preds = %38
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %7
br label %56
56: ; preds = %74, %54
%57 = load i32, i32* %7
%58 = load i32*, i32** %4
%59 = load i32, i32* %58
%60 = icmp slt i32 %57, %59
br i1 %60, label %61, label %77
61: ; preds = %56
%62 = load float, float* %8
%63 = load float*, float** %9
%64 = load i32, i32* %7
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds float, float* %63, i64 %65
%67 = load float, float* %66
%68 = load float*, float** %10
%69 = load i32, i32* %7
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds float, float* %68, i64 %70
%72 = load float, float* %71
%73 = call float @llvm.fmuladd.f32(float %67, float %72, float %62)
store float %73, float* %8
br label %74
74: ; preds = %61
%75 = load i32, i32* %7
%76 = add nsw i32 %75, 1
store i32 %76, i32* %7
br label %56
77: ; preds = %56
%78 = load float, float* %8
ret float %78
}

LLVM IR (-O2):
@.str = [37 x i8] c"calculating dot product of size: %d\0A\00"
@.str.1 = [12 x i8] c"input_a: [ \00"
@.str.2 = [4 x i8] c"%f \00"
@.str.4 = [12 x i8] c"input_b: [ \00"
@str.5 = [3 x i8] c"].\00"
define float @dot_product_in_c(i32* nocapture %0, float** nocapture %1, float** nocapture %2) {
%4 = load float*, float** %1
%5 = load float*, float** %2
%6 = load i32, i32* %0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* %0
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %3, %11
%12 = phi i64 [ %17, %11 ], [ 0, %3 ]
%13 = getelementptr inbounds float, float* %4, i64 %12
%14 = load float, float* %13
%15 = fpext float %14 to double
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %15)
%17 = add nuw nsw i64 %12, 1
%18 = load i32, i32* %0
%19 = sext i32 %18 to i64
%20 = icmp slt i64 %17, %19
br i1 %20, label %11, label %21
21: ; preds = %11, %3
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.5, i64 0, i64 0))
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%24 = load i32, i32* %0
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %36
26: ; preds = %21, %26
%27 = phi i64 [ %32, %26 ], [ 0, %21 ]
%28 = getelementptr inbounds float, float* %4, i64 %27
%29 = load float, float* %28
%30 = fpext float %29 to double
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %30)
%32 = add nuw nsw i64 %27, 1
%33 = load i32, i32* %0
%34 = sext i32 %33 to i64
%35 = icmp slt i64 %32, %34
br i1 %35, label %26, label %36
36: ; preds = %26, %21
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.5, i64 0, i64 0))
%38 = load i32, i32* %0
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %94
40: ; preds = %36
%41 = zext i32 %38 to i64
%42 = add nsw i64 %41, -1
%43 = and i64 %41, 3
%44 = icmp ult i64 %42, 3
br i1 %44, label %77, label %45
45: ; preds = %40
%46 = and i64 %41, 4294967292
br label %47
47: ; preds = %47, %45
%48 = phi i64 [ 0, %45 ], [ %74, %47 ]
%49 = phi float [ 0.000000e+00, %45 ], [ %73, %47 ]
%50 = phi i64 [ 0, %45 ], [ %75, %47 ]
%51 = getelementptr inbounds float, float* %4, i64 %48
%52 = load float, float* %51
%53 = getelementptr inbounds float, float* %5, i64 %48
%54 = load float, float* %53
%55 = tail call float @llvm.fmuladd.f32(float %52, float %54, float %49)
%56 = or i64 %48, 1
%57 = getelementptr inbounds float, float* %4, i64 %56
%58 = load float, float* %57
%59 = getelementptr inbounds float, float* %5, i64 %56
%60 = load float, float* %59
%61 = tail call float @llvm.fmuladd.f32(float %58, float %60, float %55)
%62 = or i64 %48, 2
%63 = getelementptr inbounds float, float* %4, i64 %62
%64 = load float, float* %63
%65 = getelementptr inbounds float, float* %5, i64 %62
%66 = load float, float* %65
%67 = tail call float @llvm.fmuladd.f32(float %64, float %66, float %61)
%68 = or i64 %48, 3
%69 = getelementptr inbounds float, float* %4, i64 %68
%70 = load float, float* %69
%71 = getelementptr inbounds float, float* %5, i64 %68
%72 = load float, float* %71
%73 = tail call float @llvm.fmuladd.f32(float %70, float %72, float %67)
%74 = add nuw nsw i64 %48, 4
%75 = add i64 %50, 4
%76 = icmp eq i64 %75, %46
br i1 %76, label %77, label %47
77: ; preds = %47, %40
%78 = phi float [ undef, %40 ], [ %73, %47 ]
%79 = phi i64 [ 0, %40 ], [ %74, %47 ]
%80 = phi float [ 0.000000e+00, %40 ], [ %73, %47 ]
%81 = icmp eq i64 %43, 0
br i1 %81, label %94, label %82
82: ; preds = %77, %82
%83 = phi i64 [ %91, %82 ], [ %79, %77 ]
%84 = phi float [ %90, %82 ], [ %80, %77 ]
%85 = phi i64 [ %92, %82 ], [ 0, %77 ]
%86 = getelementptr inbounds float, float* %4, i64 %83
%87 = load float, float* %86
%88 = getelementptr inbounds float, float* %5, i64 %83
%89 = load float, float* %88
%90 = tail call float @llvm.fmuladd.f32(float %87, float %89, float %84)
%91 = add nuw nsw i64 %83, 1
%92 = add i64 %85, 1
%93 = icmp eq i64 %92, %43
br i1 %93, label %94, label %82
94: ; preds = %77, %82, %36
%95 = phi float [ 0.000000e+00, %36 ], [ %78, %77 ], [ %90, %82 ]
ret float %95
}