#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 fn2(int x, int y, int z) {
  double b[1024], c[1024], s = 0;
  int i, j;
  fn1(b, c, x);
#pragma omp target data map(to : b)
  {
#pragma omp target map(tofrom : c, s)
#pragma omp teams num_teams(y) thread_limit(z) reduction(+ : s) firstprivate(x)
#pragma omp distribute dist_schedule(static, 4) collapse(1)
    for (j = 0; j < x; j += y)
#pragma omp parallel for reduction(+ : s)
      for (i = j; i < j + y; i++)
        tgt(), s += b[i] * c[i];
#pragma omp target update from(b, tgtv)
  }
  return s;
}


x86 assembly (clang, -O0):
<fn2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4020,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%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,-0x4020(%rbp)
mov    -0x4020(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11fd <fn2+0xdd>
mov    -0x4020(%rbp),%eax
mov    %eax,-0x401c(%rbp)
mov    -0x401c(%rbp),%eax
mov    -0x4020(%rbp),%ecx
add    -0x8(%rbp),%ecx
cmp    %ecx,%eax
jge    11e4 <fn2+0xc4>
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    117a <fn2+0x5a>
jmp    11e9 <fn2+0xc9>
mov    -0x8(%rbp),%eax
add    -0x4020(%rbp),%eax
mov    %eax,-0x4020(%rbp)
jmp    115f <fn2+0x3f>
movsd  -0x4018(%rbp),%xmm0
ff
add    $0x4020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fn2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x4018,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
lea    0x2010(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %ebx,%edx
call   1030 <fn1@plt>
test   %ebx,%ebx
jle    11ad <fn2+0x8d>
movslq %ebp,%r15
mov    %ebx,%r14d
xorps  %xmm0,%xmm0
xor    %ebp,%ebp
jmp    1165 <fn2+0x45>
cs nopw 0x0(%rax,%rax,1)
cmp    %r14,%rbp
jge    11b0 <fn2+0x90>
mov    %rbp,%rbx
add    %r15,%rbp
test   %r15d,%r15d
jle    1160 <fn2+0x40>
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    %rbp,%rbx
jl     1170 <fn2+0x50>
jmp    1160 <fn2+0x40>
xorps  %xmm0,%xmm0
add    $0x4018,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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