#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*/ fn1(double *, double *, int);
double fn3(int x) {
  double b[1024], c[1024], s = 0;
  int i;
  fn1(b, c, x);
#pragma omp target map(to : b, c) map(tofrom : s)
#pragma omp parallel for reduction(+ : s)
  for (i = 0; i < x; i++)
    tgt(), s += b[i] * c[i];
  return s;
}


x86 assembly (clang, -O0):
<fn3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4020,%rsp
mov    %edi,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x4018(%rbp)
ff
lea    -0x2010(%rbp),%rdi
lea    -0x4010(%rbp),%rsi
mov    -0x4(%rbp),%edx
call   1030 <fn1@plt>
movl   $0x0,-0x401c(%rbp)
mov    -0x401c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11bb <fn3+0x9b>
mov    $0x0,%al
call   1040 <tgt@plt>
movslq -0x401c(%rbp),%rax
movsd  -0x2010(%rbp,%rax,8),%xmm0
ff ff
movslq -0x401c(%rbp),%rax
movsd  -0x4010(%rbp,%rax,8),%xmm2
ff ff
movsd  -0x4018(%rbp),%xmm1
ff
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x4018(%rbp)
ff
mov    -0x401c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x401c(%rbp)
jmp    1159 <fn3+0x39>
movsd  -0x4018(%rbp),%xmm0
ff
add    $0x4020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fn3>:
push   %r14
push   %rbx
sub    $0x4018,%rsp
mov    %edi,%ebx
lea    0x2010(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %ebx,%edx
call   1030 <fn1@plt>
test   %ebx,%ebx
jle    118d <fn3+0x6d>
mov    %ebx,%r14d
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
nopl   0x0(%rax)
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1040 <tgt@plt>
movsd  0x2010(%rsp,%rbx,8),%xmm0
mulsd  0x10(%rsp,%rbx,8),%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1150 <fn3+0x30>
jmp    1190 <fn3+0x70>
xorps  %xmm0,%xmm0
add    $0x4018,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @fn3(i32 %0) {
%2 = alloca i32
%3 = alloca [1024 x double]
%4 = alloca [1024 x double]
%5 = alloca double
%6 = alloca i32
store i32 %0, i32* %2
store double 0.000000e+00, double* %5
%7 = getelementptr inbounds [1024 x double], [1024 x double]* %3, i64 0, i64 0
%8 = getelementptr inbounds [1024 x double], [1024 x double]* %4, i64 0, i64 0
%9 = load i32, i32* %2
%10 = call i32 @fn1(double* %7, double* %8, i32 %9)
store i32 0, i32* %6
br label %11
11: ; preds = %27, %1
%12 = load i32, i32* %6
%13 = load i32, i32* %2
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %30
15: ; preds = %11
%16 = call i32 (...) @tgt()
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [1024 x double], [1024 x double]* %3, i64 0, i64 %18
%20 = load double, double* %19
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [1024 x double], [1024 x double]* %4, i64 0, i64 %22
%24 = load double, double* %23
%25 = load double, double* %5
%26 = call double @llvm.fmuladd.f64(double %20, double %24, double %25)
store double %26, double* %5
br label %27
27: ; preds = %15
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
br label %11
30: ; preds = %11
%31 = load double, double* %5
ret double %31
}

LLVM IR (-O2):
define double @fn3(i32 %0) {
%2 = alloca [1024 x double]
%3 = alloca [1024 x double]
%4 = bitcast [1024 x double]* %2 to i8*
%5 = bitcast [1024 x double]* %3 to i8*
%6 = getelementptr inbounds [1024 x double], [1024 x double]* %2, i64 0, i64 0
%7 = getelementptr inbounds [1024 x double], [1024 x double]* %3, i64 0, i64 0
%8 = call i32 @fn1(double* %6, double* %7, i32 %0)
%9 = icmp sgt i32 %0, 0
br i1 %9, label %10, label %23
10: ; preds = %1
%11 = zext i32 %0 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %21, %12 ]
%14 = phi double [ 0.000000e+00, %10 ], [ %20, %12 ]
%15 = call i32 (...) @tgt()
%16 = getelementptr inbounds [1024 x double], [1024 x double]* %2, i64 0, i64 %13
%17 = load double, double* %16
%18 = getelementptr inbounds [1024 x double], [1024 x double]* %3, i64 0, i64 %13
%19 = load double, double* %18
%20 = call double @llvm.fmuladd.f64(double %17, double %19, double %14)
%21 = add nuw nsw i64 %13, 1
%22 = icmp eq i64 %21, %11
br i1 %22, label %23, label %12
23: ; preds = %12, %1
%24 = phi double [ 0.000000e+00, %1 ], [ %20, %12 ]
ret double %24
}