#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ calc_diff(int, double *, double *, double *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int read_vecs(int *, double **, double **);
void main() {
  double *x, *y, *z;
  int vecsize;
  int check = read_vecs(&vecsize, &x, &y);
  if (check == -1) {
    printf("Input format error\n");
  } else {
    int i;
    z = (double *)malloc(sizeof(double) * vecsize);
    calc_diff(vecsize, x, y, z);
    FILE *fp;
    fp = fopen("vector_out.dat", "w");
    for (i = 0; i < vecsize; i++) {
      fprintf(fp, "%f\n", z[i]);
    }
    fclose(fp);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x1c(%rbp),%rdi
lea    -0x8(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1090 <read_vecs@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    11a7 <main+0x37>
lea    0xe63(%rip),%rdi
call   1040 <printf@plt>
jmp    122c <main+0xbc>
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1070 <calc_diff@plt>
lea    0xe3f(%rip),%rdi
lea    0xe47(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1223 <main+0xb3>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe15(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ec <main+0x7c>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0x4(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1090 <read_vecs@plt>
cmp    $0xffffffff,%eax
je     1209 <main+0x99>
mov    0x4(%rsp),%edi
shl    $0x3,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    0x4(%rsp),%edi
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdx
mov    %rax,%rcx
call   1070 <calc_diff@plt>
lea    0xe40(%rip),%rdi
lea    0xe48(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r12
cmpl   $0x0,0x4(%rsp)
jle    11ff <main+0x8f>
xor    %ebx,%ebx
lea    0xe32(%rip),%r15
nop
movsd  (%r14,%rbx,8),%xmm0
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <fprintf@plt>
add    $0x1,%rbx
movslq 0x4(%rsp),%rax
cmp    %rax,%rbx
jl     11e0 <main+0x70>
mov    %r12,%rdi
call   1040 <fclose@plt>
jmp    1215 <main+0xa5>
lea    0xe05(%rip),%rdi
call   1030 <puts@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Input format error\0A\00"
@.str.1 = [15 x i8] c"vector_out.dat\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [4 x i8] c"%f\0A\00"
define void @main() {
%1 = alloca double*
%2 = alloca double*
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = call i32 @read_vecs(i32* %4, double** %1, double** %2)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %44
13: ; preds = %0
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = mul i64 8, %15
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to double*
store double* %19, double** %3
%20 = load i32, i32* %4
%21 = load double*, double** %1
%22 = load double*, double** %2
%23 = load double*, double** %3
%24 = call i32 @calc_diff(i32 %20, double* %21, double* %22, double* %23)
%25 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %25, i32** %7
store i32 0, i32* %6
br label %26
26: ; preds = %38, %13
%27 = load i32, i32* %6
%28 = load i32, i32* %4
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %41
30: ; preds = %26
%31 = load i32*, i32** %7
%32 = load double*, double** %3
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
%36 = load double, double* %35
%37 = call i32 @fprintf(i32* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double %36)
br label %38
38: ; preds = %30
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %26
41: ; preds = %26
%42 = load i32*, i32** %7
%43 = call i32 @fclose(i32* %42)
br label %44
44: ; preds = %41, %11
ret void
}

LLVM IR (-O2):
@.str.1 = [15 x i8] c"vector_out.dat\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [4 x i8] c"%f\0A\00"
@str = [19 x i8] c"Input format error\00"
define void @main() {
%1 = alloca double*
%2 = alloca double*
%3 = alloca i32
%4 = bitcast double** %1 to i8*
%5 = bitcast double** %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = call i32 @read_vecs(i32* %3, double** %1, double** %2)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %34
11: ; preds = %0
%12 = load i32, i32* %3
%13 = shl i32 %12, 3
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to double*
%16 = load i32, i32* %3
%17 = load double*, double** %1
%18 = load double*, double** %2
%19 = call i32 @calc_diff(i32 %16, double* %17, double* %18, double* %15)
%20 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* %3
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %11, %23
%24 = phi i64 [ %28, %23 ], [ 0, %11 ]
%25 = getelementptr inbounds double, double* %15, i64 %24
%26 = load double, double* %25
%27 = call i32 @fprintf(i32* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double %26)
%28 = add nuw nsw i64 %24, 1
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = icmp slt i64 %28, %30
br i1 %31, label %23, label %32
32: ; preds = %23, %11
%33 = call i32 @fclose(i32* %20)
br label %34
34: ; preds = %32, %9
ret void
}