#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 DBL_MIN;
int calculate_output(double aux_real[1000], double aux_img[1000],
                     double matrice_real[1000][1000],
                     double matrice_img[1000][1000], double snapshot_real[1000],
                     double snapshot_img[1000]) {
  int i, j, t;
  double val, t_val;
#pragma scop
  t = 0;
  t_val = DBL_MIN;
  for (i = 0; i < 1000; i++) {
    aux_img[i] = 0;
    aux_real[i] = 0;
    for (j = 0; j < 1000; j++) {
      aux_real[i] += snapshot_real[j] * matrice_real[i][j] -
                     snapshot_img[j] * matrice_img[i][j];
      aux_img[i] += snapshot_img[j] * matrice_real[i][j] +
                    snapshot_real[j] * matrice_img[i][j];
    }
    val = aux_real[i] * aux_real[i] + aux_img[i] * aux_img[i];
    t = (val >= t_val) ? (t_val = val, i) : t;
  }
#pragma endscop
  return t;
}


x86 assembly (clang, -O0):
<calculate_output>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    0x2eb6(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x3e8,-0x34(%rbp)
jge    12f4 <calculate_output+0x1f4>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x0,-0x38(%rbp)
cmpl   $0x3e8,-0x38(%rbp)
jge    1274 <calculate_output+0x174>
mov    -0x28(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
imul   $0x1f40,%rcx,%rcx
add    %rcx,%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x30(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
imul   $0x1f40,%rcx,%rcx
add    %rcx,%rax
movslq -0x38(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
imul   $0x1f40,%rcx,%rcx
add    %rcx,%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x28(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
imul   $0x1f40,%rcx,%rcx
add    %rcx,%rax
movslq -0x38(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    116e <calculate_output+0x6e>
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
ucomisd -0x50(%rbp),%xmm0
jb     12da <calculate_output+0x1da>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x54(%rbp)
jmp    12e0 <calculate_output+0x1e0>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    113a <calculate_output+0x3a>
mov    -0x3c(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate_output>:
mov    0x2ed9(%rip),%rax
movsd  (%rax),%xmm0
xor    %r10d,%r10d
xor    %eax,%eax
movq   $0x0,(%rsi,%r10,8)
movq   $0x0,(%rdi,%r10,8)
xorpd  %xmm1,%xmm1
xor    %r11d,%r11d
nopw   0x0(%rax,%rax,1)
movsd  (%rcx,%r11,8),%xmm2
mulsd  (%r9,%r11,8),%xmm2
movsd  (%r8,%r11,8),%xmm3
mulsd  (%rdx,%r11,8),%xmm3
subsd  %xmm2,%xmm3
addsd  %xmm1,%xmm3
movsd  %xmm3,(%rdi,%r10,8)
movsd  (%r9,%r11,8),%xmm2
movsd  (%r8,%r11,8),%xmm1
mulsd  (%rcx,%r11,8),%xmm1
mulsd  (%rdx,%r11,8),%xmm2
addsd  %xmm1,%xmm2
addsd  (%rsi,%r10,8),%xmm2
movsd  %xmm2,(%rsi,%r10,8)
add    $0x1,%r11
movsd  (%rdi,%r10,8),%xmm1
cmp    $0x3e8,%r11
jne    1130 <calculate_output+0x30>
mulsd  %xmm2,%xmm2
mulsd  %xmm1,%xmm1
addsd  %xmm2,%xmm1
ucomisd %xmm0,%xmm1
movapd %xmm0,%xmm2
cmpnlesd %xmm1,%xmm2
movapd %xmm2,%xmm3
andnpd %xmm1,%xmm3
andpd  %xmm0,%xmm2
orpd   %xmm3,%xmm2
cmovae %r10d,%eax
add    $0x1,%r10
add    $0x1f40,%rcx
add    $0x1f40,%rdx
movapd %xmm2,%xmm0
cmp    $0x3e8,%r10
jne    1110 <calculate_output+0x10>
ret

LLVM IR (-O0):
@DBL_MIN = global double 0.000000e+00
define i32 @calculate_output(double* %0, double* %1, [1000 x double]* %2, [1000 x double]* %3, double* %4, double* %5) {
%7 = alloca double*
%8 = alloca double*
%9 = alloca [1000 x double]*
%10 = alloca [1000 x double]*
%11 = alloca double*
%12 = alloca double*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca double
%17 = alloca double
store double* %0, double** %7
store double* %1, double** %8
store [1000 x double]* %2, [1000 x double]** %9
store [1000 x double]* %3, [1000 x double]** %10
store double* %4, double** %11
store double* %5, double** %12
store i32 0, i32* %15
%18 = load double, double* @DBL_MIN
store double %18, double* %17
store i32 0, i32* %13
br label %19
19: ; preds = %140, %6
%20 = load i32, i32* %13
%21 = icmp slt i32 %20, 1000
br i1 %21, label %22, label %143
22: ; preds = %19
%23 = load double*, double** %8
%24 = load i32, i32* %13
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
store double 0.000000e+00, double* %26
%27 = load double*, double** %7
%28 = load i32, i32* %13
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
store double 0.000000e+00, double* %30
store i32 0, i32* %14
br label %31
31: ; preds = %104, %22
%32 = load i32, i32* %14
%33 = icmp slt i32 %32, 1000
br i1 %33, label %34, label %107
34: ; preds = %31
%35 = load double*, double** %11
%36 = load i32, i32* %14
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
%39 = load double, double* %38
%40 = load [1000 x double]*, [1000 x double]** %9
%41 = load i32, i32* %13
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [1000 x double], [1000 x double]* %40, i64 %42
%44 = load i32, i32* %14
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [1000 x double], [1000 x double]* %43, i64 0, i64 %45
%47 = load double, double* %46
%48 = load double*, double** %12
%49 = load i32, i32* %14
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %48, i64 %50
%52 = load double, double* %51
%53 = load [1000 x double]*, [1000 x double]** %10
%54 = load i32, i32* %13
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [1000 x double], [1000 x double]* %53, i64 %55
%57 = load i32, i32* %14
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [1000 x double], [1000 x double]* %56, i64 0, i64 %58
%60 = load double, double* %59
%61 = fmul double %52, %60
%62 = fneg double %61
%63 = call double @llvm.fmuladd.f64(double %39, double %47, double %62)
%64 = load double*, double** %7
%65 = load i32, i32* %13
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds double, double* %64, i64 %66
%68 = load double, double* %67
%69 = fadd double %68, %63
store double %69, double* %67
%70 = load double*, double** %12
%71 = load i32, i32* %14
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds double, double* %70, i64 %72
%74 = load double, double* %73
%75 = load [1000 x double]*, [1000 x double]** %9
%76 = load i32, i32* %13
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [1000 x double], [1000 x double]* %75, i64 %77
%79 = load i32, i32* %14
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [1000 x double], [1000 x double]* %78, i64 0, i64 %80
%82 = load double, double* %81
%83 = load double*, double** %11
%84 = load i32, i32* %14
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds double, double* %83, i64 %85
%87 = load double, double* %86
%88 = load [1000 x double]*, [1000 x double]** %10
%89 = load i32, i32* %13
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds [1000 x double], [1000 x double]* %88, i64 %90
%92 = load i32, i32* %14
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [1000 x double], [1000 x double]* %91, i64 0, i64 %93
%95 = load double, double* %94
%96 = fmul double %87, %95
%97 = call double @llvm.fmuladd.f64(double %74, double %82, double %96)
%98 = load double*, double** %8
%99 = load i32, i32* %13
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds double, double* %98, i64 %100
%102 = load double, double* %101
%103 = fadd double %102, %97
store double %103, double* %101
br label %104
104: ; preds = %34
%105 = load i32, i32* %14
%106 = add nsw i32 %105, 1
store i32 %106, i32* %14
br label %31
107: ; preds = %31
%108 = load double*, double** %7
%109 = load i32, i32* %13
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds double, double* %108, i64 %110
%112 = load double, double* %111
%113 = load double*, double** %7
%114 = load i32, i32* %13
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds double, double* %113, i64 %115
%117 = load double, double* %116
%118 = load double*, double** %8
%119 = load i32, i32* %13
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds double, double* %118, i64 %120
%122 = load double, double* %121
%123 = load double*, double** %8
%124 = load i32, i32* %13
%125 = sext i32 %124 to i64
%126 = getelementptr inbounds double, double* %123, i64 %125
%127 = load double, double* %126
%128 = fmul double %122, %127
%129 = call double @llvm.fmuladd.f64(double %112, double %117, double %128)
store double %129, double* %16
%130 = load double, double* %16
%131 = load double, double* %17
%132 = fcmp oge double %130, %131
br i1 %132, label %133, label %136
133: ; preds = %107
%134 = load double, double* %16
store double %134, double* %17
%135 = load i32, i32* %13
br label %138
136: ; preds = %107
%137 = load i32, i32* %15
br label %138
138: ; preds = %136, %133
%139 = phi i32 [ %135, %133 ], [ %137, %136 ]
store i32 %139, i32* %15
br label %140
140: ; preds = %138
%141 = load i32, i32* %13
%142 = add nsw i32 %141, 1
store i32 %142, i32* %13
br label %19
143: ; preds = %19
%144 = load i32, i32* %15
ret i32 %144
}

LLVM IR (-O2):
@DBL_MIN = global double 0.000000e+00
define i32 @calculate_output(double* nocapture %0, double* nocapture %1, [1000 x double]* nocapture %2, [1000 x double]* nocapture %3, double* nocapture %4, double* nocapture %5) {
%7 = load double, double* @DBL_MIN
br label %8
8: ; preds = %6, %40
%9 = phi i64 [ 0, %6 ], [ %47, %40 ]
%10 = phi double [ %7, %6 ], [ %44, %40 ]
%11 = phi i32 [ 0, %6 ], [ %46, %40 ]
%12 = getelementptr inbounds double, double* %1, i64 %9
store double 0.000000e+00, double* %12
%13 = getelementptr inbounds double, double* %0, i64 %9
store double 0.000000e+00, double* %13
br label %14
14: ; preds = %14, %8
%15 = phi double [ 0.000000e+00, %8 ], [ %39, %14 ]
%16 = phi i64 [ 0, %8 ], [ %37, %14 ]
%17 = getelementptr inbounds double, double* %4, i64 %16
%18 = load double, double* %17
%19 = getelementptr inbounds [1000 x double], [1000 x double]* %2, i64 %9, i64 %16
%20 = load double, double* %19
%21 = getelementptr inbounds double, double* %5, i64 %16
%22 = load double, double* %21
%23 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 %9, i64 %16
%24 = load double, double* %23
%25 = fneg double %22
%26 = fmul double %24, %25
%27 = tail call double @llvm.fmuladd.f64(double %18, double %20, double %26)
%28 = fadd double %15, %27
store double %28, double* %13
%29 = load double, double* %21
%30 = load double, double* %19
%31 = load double, double* %17
%32 = load double, double* %23
%33 = fmul double %31, %32
%34 = tail call double @llvm.fmuladd.f64(double %29, double %30, double %33)
%35 = load double, double* %12
%36 = fadd double %35, %34
store double %36, double* %12
%37 = add nuw nsw i64 %16, 1
%38 = icmp eq i64 %37, 1000
%39 = load double, double* %13
br i1 %38, label %40, label %14
40: ; preds = %14
%41 = fmul double %36, %36
%42 = tail call double @llvm.fmuladd.f64(double %39, double %39, double %41)
%43 = fcmp ult double %42, %10
%44 = select i1 %43, double %10, double %42
%45 = trunc i64 %9 to i32
%46 = select i1 %43, i32 %11, i32 %45
%47 = add nuw nsw i64 %9, 1
%48 = icmp eq i64 %47, 1000
br i1 %48, label %49, label %8
49: ; preds = %40
ret i32 %46
}