#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 */
double escalar(float *, float *, int);
int /*<<< orphan*/ free(float *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main(void) {
  int tam;
  float *vet1, *vet2;
  printf("Informe o tamanho dos vetores: ");
  scanf("%d", &tam);
  vet1 = (float *)malloc(tam * sizeof(float));
  vet2 = (float *)malloc(tam * sizeof(float));
  printf("Informe os valores do vetor 1:\n");
  for (int i = 0; i < tam; i++) {
    scanf("%f", &vet1[i]);
  }
  printf("Informe os valores do vetor 2:\n");
  for (int i = 0; i < tam; i++) {
    scanf("%f", &vet2[i]);
  }
  printf("O produto escalar é %.2f\n", escalar(vet1, vet2, tam));
  free(vet1);
  free(vet2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeac(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11f1 <main+0xa1>
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ba <main+0x6a>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    123d <main+0xed>
mov    -0x18(%rbp),%rsi
movslq -0x20(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1206 <main+0xb6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1050 <escalar@plt>
lea    0xe12(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe8c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe9e(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0xc(%rsp),%edi
shl    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    0xc(%rsp),%edi
shl    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
lea    0xe8e(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    11ef <main+0x8f>
lea    0xe5d(%rip),%r12
mov    %r14,%r13
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
add    $0x4,%r13
cmp    %rax,%rbx
jl     11d0 <main+0x70>
lea    0xe6a(%rip),%rdi
call   1040 <puts@plt>
mov    0xc(%rsp),%edx
test   %edx,%edx
jle    122f <main+0xcf>
lea    0xe19(%rip),%r12
mov    %r15,%r13
xor    %ebx,%ebx
nop
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rdx
add    $0x4,%r13
cmp    %rdx,%rbx
jl     1210 <main+0xb0>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <escalar@plt>
lea    0xde5(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Informe o tamanho dos vetores: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [32 x i8] c"Informe os valores do vetor 1:\0A\00"
@.str.3 = [3 x i8] c"%f\00"
@.str.4 = [32 x i8] c"Informe os valores do vetor 2:\0A\00"
@.str.5 = [27 x i8] c"O produto escalar \C3\A9 %.2f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float*
%4 = alloca float*
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 4
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to float*
store float* %14, float** %3
%15 = load i32, i32* %2
%16 = sext i32 %15 to i64
%17 = mul i64 %16, 4
%18 = trunc i64 %17 to i32
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to float*
store float* %20, float** %4
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %5
br label %22
22: ; preds = %32, %0
%23 = load i32, i32* %5
%24 = load i32, i32* %2
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %35
26: ; preds = %22
%27 = load float*, float** %3
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds float, float* %27, i64 %29
%31 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %30)
br label %32
32: ; preds = %26
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %22
35: ; preds = %22
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %6
br label %37
37: ; preds = %47, %35
%38 = load i32, i32* %6
%39 = load i32, i32* %2
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %50
41: ; preds = %37
%42 = load float*, float** %4
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds float, float* %42, i64 %44
%46 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %45)
br label %47
47: ; preds = %41
%48 = load i32, i32* %6
%49 = add nsw i32 %48, 1
store i32 %49, i32* %6
br label %37
50: ; preds = %37
%51 = load float*, float** %3
%52 = load float*, float** %4
%53 = load i32, i32* %2
%54 = call double @escalar(float* %51, float* %52, i32 %53)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), double %54)
%56 = load float*, float** %3
%57 = call i32 @free(float* %56)
%58 = load float*, float** %4
%59 = call i32 @free(float* %58)
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"Informe o tamanho dos vetores: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [3 x i8] c"%f\00"
@.str.5 = [27 x i8] c"O produto escalar \C3\A9 %.2f\0A\00"
@str = [31 x i8] c"Informe os valores do vetor 1:\00"
@str.6 = [31 x i8] c"Informe os valores do vetor 2:\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%4 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = shl i32 %5, 2
%7 = call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to float*
%9 = load i32, i32* %1
%10 = shl i32 %9, 2
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to float*
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%14 = load i32, i32* %1
%15 = icmp sgt i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %20, %0
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.6, i64 0, i64 0))
%18 = load i32, i32* %1
%19 = icmp sgt i32 %18, 0
br i1 %19, label %34, label %28
20: ; preds = %0, %20
%21 = phi i64 [ %24, %20 ], [ 0, %0 ]
%22 = getelementptr inbounds float, float* %8, i64 %21
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %22)
%24 = add nuw nsw i64 %21, 1
%25 = load i32, i32* %1
%26 = sext i32 %25 to i64
%27 = icmp slt i64 %24, %26
br i1 %27, label %20, label %16
28: ; preds = %34, %16
%29 = phi i32 [ %18, %16 ], [ %39, %34 ]
%30 = call double @escalar(float* %8, float* %12, i32 %29)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), double %30)
%32 = call i32 @free(float* %8)
%33 = call i32 @free(float* %12)
ret i32 0
34: ; preds = %16, %34
%35 = phi i64 [ %38, %34 ], [ 0, %16 ]
%36 = getelementptr inbounds float, float* %12, i64 %35
%37 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %36)
%38 = add nuw nsw i64 %35, 1
%39 = load i32, i32* %1
%40 = sext i32 %39 to i64
%41 = icmp slt i64 %38, %40
br i1 %41, label %34, label %28
}