#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 RAND_MAX;
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
double rand();
void wul() {
  int data = 8192;
  double *arr_a = (double *)malloc(sizeof(double) * data);
  double *arr_b = (double *)malloc(sizeof(double) * data);
  int i = 0;
  if (arr_a == NULL || arr_b == NULL) {
    printf("Unable to allocate memory in wul.\n");
  }
  for (i = 0; i < data; i++) {
    arr_a[i] = (double)(rand() / (1.0 + RAND_MAX));
  }
#pragma acc data copy(arr_b [0:data]), copyin(arr_a [0:data])
  {
#pragma acc parallel loop
    for (i = 0; i < data; i++) {
      arr_b[i] = arr_a[i] * 2;
    }
  }
  if (arr_a[0] < 0) {
    printf("Error in WUL\n");
  }
  free(arr_a);
  free(arr_b);
}


x86 assembly (clang, -O0):
<wul>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x2000,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1192 <wul+0x52>
cmpq   $0x0,-0x18(%rbp)
jne    119e <wul+0x5e>
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ea <wul+0xaa>
mov    $0x0,%al
call   1060 <rand@plt>
movsd  0xe48(%rip),%xmm1
mov    0x2e21(%rip),%rax
addsd  (%rax),%xmm1
divsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a5 <wul+0x65>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    122d <wul+0xed>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  0xdf3(%rip),%xmm0
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11f1 <wul+0xb1>
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
ucomisd (%rax),%xmm0
jbe    124a <wul+0x10a>
lea    0xdee(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wul>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x10000,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
mov    $0x10000,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
test   %r12,%r12
je     116c <wul+0x2c>
test   %r14,%r14
jne    1178 <wul+0x38>
lea    0xea2(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e69(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <rand@plt>
movsd  (%r15),%xmm1
addsd  0xe5c(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,(%r12,%rbx,8)
add    $0x1,%rbx
cmp    $0x2000,%rbx
jne    1190 <wul+0x50>
mov    %r12,%rax
add    $0x10000,%rax
cmp    %rax,%r14
jae    1234 <wul+0xf4>
mov    %r14,%rax
add    $0x10000,%rax
cmp    %rax,%r12
jae    1234 <wul+0xf4>
xor    %eax,%eax
nopl   0x0(%rax)
movsd  (%r12,%rax,8),%xmm0
addsd  %xmm0,%xmm0
movsd  %xmm0,(%r14,%rax,8)
movsd  0x8(%r12,%rax,8),%xmm0
addsd  %xmm0,%xmm0
movsd  %xmm0,0x8(%r14,%rax,8)
movsd  0x10(%r12,%rax,8),%xmm0
addsd  %xmm0,%xmm0
movsd  %xmm0,0x10(%r14,%rax,8)
movsd  0x18(%r12,%rax,8),%xmm0
addsd  %xmm0,%xmm0
movsd  %xmm0,0x18(%r14,%rax,8)
add    $0x4,%rax
cmp    $0x2000,%rax
jne    11e0 <wul+0xa0>
jmp    1292 <wul+0x152>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
movupd (%r12,%rax,8),%xmm0
movupd 0x10(%r12,%rax,8),%xmm1
addpd  %xmm0,%xmm0
addpd  %xmm1,%xmm1
movupd %xmm0,(%r14,%rax,8)
movupd %xmm1,0x10(%r14,%rax,8)
movupd 0x20(%r12,%rax,8),%xmm0
movupd 0x30(%r12,%rax,8),%xmm1
addpd  %xmm0,%xmm0
addpd  %xmm1,%xmm1
movupd %xmm0,0x20(%r14,%rax,8)
movupd %xmm1,0x30(%r14,%rax,8)
add    $0x8,%rax
cmp    $0x2000,%rax
jne    1240 <wul+0x100>
xorpd  %xmm0,%xmm0
ucomisd (%r12),%xmm0
jbe    12aa <wul+0x16a>
lea    0xd63(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [35 x i8] c"Unable to allocate memory in wul.\0A\00"
@RAND_MAX = global double 0.000000e+00
@.str.1 = [14 x i8] c"Error in WUL\0A\00"
define void @wul() {
%1 = alloca i32
%2 = alloca double*
%3 = alloca double*
%4 = alloca i32
store i32 8192, i32* %1
%5 = load i32, i32* %1
%6 = sext i32 %5 to i64
%7 = mul i64 8, %6
%8 = trunc i64 %7 to i32
%9 = call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to double*
store double* %10, double** %2
%11 = load i32, i32* %1
%12 = sext i32 %11 to i64
%13 = mul i64 8, %12
%14 = trunc i64 %13 to i32
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to double*
store double* %16, double** %3
store i32 0, i32* %4
%17 = load double*, double** %2
%18 = icmp eq double* %17, null
br i1 %18, label %22, label %19
19: ; preds = %0
%20 = load double*, double** %3
%21 = icmp eq double* %20, null
br i1 %21, label %22, label %24
22: ; preds = %19, %0
%23 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %19
store i32 0, i32* %4
br label %25
25: ; preds = %38, %24
%26 = load i32, i32* %4
%27 = load i32, i32* %1
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %41
29: ; preds = %25
%30 = call double (...) @rand()
%31 = load double, double* @RAND_MAX
%32 = fadd double 1.000000e+00, %31
%33 = fdiv double %30, %32
%34 = load double*, double** %2
%35 = load i32, i32* %4
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %34, i64 %36
store double %33, double* %37
br label %38
38: ; preds = %29
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 1
store i32 %40, i32* %4
br label %25
41: ; preds = %25
store i32 0, i32* %4
br label %42
42: ; preds = %57, %41
%43 = load i32, i32* %4
%44 = load i32, i32* %1
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %60
46: ; preds = %42
%47 = load double*, double** %2
%48 = load i32, i32* %4
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %47, i64 %49
%51 = load double, double* %50
%52 = fmul double %51, 2.000000e+00
%53 = load double*, double** %3
%54 = load i32, i32* %4
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %53, i64 %55
store double %52, double* %56
br label %57
57: ; preds = %46
%58 = load i32, i32* %4
%59 = add nsw i32 %58, 1
store i32 %59, i32* %4
br label %42
60: ; preds = %42
%61 = load double*, double** %2
%62 = getelementptr inbounds double, double* %61, i64 0
%63 = load double, double* %62
%64 = fcmp olt double %63, 0.000000e+00
br i1 %64, label %65, label %67
65: ; preds = %60
%66 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %67
67: ; preds = %65, %60
%68 = load double*, double** %2
%69 = call i32 @free(double* %68)
%70 = load double*, double** %3
%71 = call i32 @free(double* %70)
ret void
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
@str = [13 x i8] c"Error in WUL\00"
@str.2 = [34 x i8] c"Unable to allocate memory in wul.\00"
define void @wul() {
%1 = tail call i64 @malloc(i32 65536)
%2 = inttoptr i64 %1 to double*
%3 = inttoptr i64 %1 to i8*
%4 = tail call i64 @malloc(i32 65536)
%5 = inttoptr i64 %4 to double*
%6 = inttoptr i64 %4 to i8*
%7 = icmp eq i64 %1, 0
%8 = icmp eq i64 %4, 0
%9 = select i1 %7, i1 true, i1 %8
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.2, i64 0, i64 0))
br label %12
12: ; preds = %0, %10
br label %13
13: ; preds = %12, %13
%14 = phi i64 [ %20, %13 ], [ 0, %12 ]
%15 = tail call double (...) @rand()
%16 = load double, double* @RAND_MAX
%17 = fadd double %16, 1.000000e+00
%18 = fdiv double %15, %17
%19 = getelementptr inbounds double, double* %2, i64 %14
store double %18, double* %19
%20 = add nuw nsw i64 %14, 1
%21 = icmp eq i64 %20, 8192
br i1 %21, label %22, label %13
22: ; preds = %13
%23 = getelementptr double, double* %5, i64 8192
%24 = bitcast double* %23 to i8*
%25 = getelementptr double, double* %2, i64 8192
%26 = bitcast double* %25 to i8*
%27 = icmp ult i8* %6, %26
%28 = icmp ult i8* %3, %24
%29 = and i1 %27, %28
br i1 %29, label %59, label %30
30: ; preds = %22, %30
%31 = phi i64 [ %57, %30 ], [ 0, %22 ]
%32 = getelementptr inbounds double, double* %2, i64 %31
%33 = bitcast double* %32 to <2 x double>*
%34 = load <2 x double>, <2 x double>* %33
%35 = getelementptr inbounds double, double* %32, i64 2
%36 = bitcast double* %35 to <2 x double>*
%37 = load <2 x double>, <2 x double>* %36
%38 = fmul <2 x double> %34, <double 2.000000e+00, double 2.000000e+00>
%39 = fmul <2 x double> %37, <double 2.000000e+00, double 2.000000e+00>
%40 = getelementptr inbounds double, double* %5, i64 %31
%41 = bitcast double* %40 to <2 x double>*
store <2 x double> %38, <2 x double>* %41
%42 = getelementptr inbounds double, double* %40, i64 2
%43 = bitcast double* %42 to <2 x double>*
store <2 x double> %39, <2 x double>* %43
%44 = or i64 %31, 4
%45 = getelementptr inbounds double, double* %2, i64 %44
%46 = bitcast double* %45 to <2 x double>*
%47 = load <2 x double>, <2 x double>* %46
%48 = getelementptr inbounds double, double* %45, i64 2
%49 = bitcast double* %48 to <2 x double>*
%50 = load <2 x double>, <2 x double>* %49
%51 = fmul <2 x double> %47, <double 2.000000e+00, double 2.000000e+00>
%52 = fmul <2 x double> %50, <double 2.000000e+00, double 2.000000e+00>
%53 = getelementptr inbounds double, double* %5, i64 %44
%54 = bitcast double* %53 to <2 x double>*
store <2 x double> %51, <2 x double>* %54
%55 = getelementptr inbounds double, double* %53, i64 2
%56 = bitcast double* %55 to <2 x double>*
store <2 x double> %52, <2 x double>* %56
%57 = add nuw nsw i64 %31, 8
%58 = icmp eq i64 %57, 8192
br i1 %58, label %82, label %30
59: ; preds = %22, %59
%60 = phi i64 [ %80, %59 ], [ 0, %22 ]
%61 = getelementptr inbounds double, double* %2, i64 %60
%62 = load double, double* %61
%63 = fmul double %62, 2.000000e+00
%64 = getelementptr inbounds double, double* %5, i64 %60
store double %63, double* %64
%65 = or i64 %60, 1
%66 = getelementptr inbounds double, double* %2, i64 %65
%67 = load double, double* %66
%68 = fmul double %67, 2.000000e+00
%69 = getelementptr inbounds double, double* %5, i64 %65
store double %68, double* %69
%70 = or i64 %60, 2
%71 = getelementptr inbounds double, double* %2, i64 %70
%72 = load double, double* %71
%73 = fmul double %72, 2.000000e+00
%74 = getelementptr inbounds double, double* %5, i64 %70
store double %73, double* %74
%75 = or i64 %60, 3
%76 = getelementptr inbounds double, double* %2, i64 %75
%77 = load double, double* %76
%78 = fmul double %77, 2.000000e+00
%79 = getelementptr inbounds double, double* %5, i64 %75
store double %78, double* %79
%80 = add nuw nsw i64 %60, 4
%81 = icmp eq i64 %80, 8192
br i1 %81, label %82, label %59
82: ; preds = %30, %59
%83 = load double, double* %2
%84 = fcmp olt double %83, 0.000000e+00
br i1 %84, label %85, label %87
85: ; preds = %82
%86 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %87
87: ; preds = %85, %82
%88 = tail call i32 @free(double* %2)
%89 = tail call i32 @free(double* %5)
ret void
}