#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*/ cl_mem;
typedef scalar_t__ cl_int;
typedef int /*<<< orphan*/ cl_command_queue;

/* Variables and functions */
scalar_t__ CL_SUCCESS;
int /*<<< orphan*/ CL_TRUE;
scalar_t__ clEnqueueReadBuffer(int /*<<< orphan*/, int /*<<< orphan*/,
                               int /*<<< orphan*/, int /*<<< orphan*/, int,
                               double *, int /*<<< orphan*/,
                               int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ clFinish(int /*<<< orphan*/);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
void printCL_C(cl_mem *cl_u, cl_command_queue *command_queue, int Nx, int Ny) {
  double *u;
  int i = 0;
  int j = 0;
  cl_int ret = 0;
  u = (double *)malloc(2 * Nx * Ny * sizeof(double));
  ret = clEnqueueReadBuffer(*command_queue, *cl_u, CL_TRUE, 0,
                            2 * Nx * Ny * sizeof(double), u, 0, NULL, NULL);
  ret = clFinish(*command_queue);
  if (ret != CL_SUCCESS) {
    printf("failed");
  }
  for (i = 0; i < Nx; i++) {
    for (j = 0; j < Ny; j++) {
      printf("%f ", u[2 * i + Nx * 2 * j]);
    }
    printf("\n");
  }
  printf("\n");
  free(u);
}


x86 assembly (clang, -O0):
<printCL_C>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
imul   -0x18(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
mov    0x2e3e(%rip),%rax
mov    (%rax),%edx
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
imul   -0x18(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%r8d
mov    -0x20(%rbp),%r9
xor    %ecx,%ecx
xor    %eax,%eax
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   1070 <clEnqueueReadBuffer@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1040 <clFinish@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2dd5(%rip),%rcx
cmp    (%rcx),%rax
je     121a <printCL_C+0xca>
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1296 <printCL_C+0x146>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    127a <printCL_C+0x12a>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
shl    $0x1,%ecx
mov    -0x14(%rbp),%edx
shl    $0x1,%edx
imul   -0x28(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xda2(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1234 <printCL_C+0xe4>
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1221 <printCL_C+0xd1>
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printCL_C>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %rsi,%r13
mov    %rdi,%r12
lea    (%r14,%r14,1),%ebp
mov    %ecx,0x1c(%rsp)
imul   %ebp,%ebx
shl    $0x3,%ebx
mov    %ebx,%edi
call   1070 <malloc@plt>
mov    %rax,%r9
mov    0x0(%r13),%edi
mov    (%r12),%esi
mov    0x2e48(%rip),%rax
mov    (%rax),%edx
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
xor    %ecx,%ecx
mov    %ebx,%r8d
mov    %r9,0x20(%rsp)
call   1080 <clEnqueueReadBuffer@plt>
mov    0x0(%r13),%edi
call   1050 <clFinish@plt>
mov    0x2e08(%rip),%rcx
cmp    (%rcx),%rax
je     11e3 <printCL_C+0x83>
lea    0xe24(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
test   %r14d,%r14d
jle    127b <printCL_C+0x11b>
movslq %ebp,%rbp
mov    %r14d,%eax
mov    %rax,0x30(%rsp)
mov    0x1c(%rsp),%eax
mov    %rax,0x28(%rsp)
shl    $0x3,%rbp
xor    %r14d,%r14d
lea    0xdf9(%rip),%rbx
xor    %r15d,%r15d
jmp    1239 <printCL_C+0xd9>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0xa,%edi
call   1040 <putchar@plt>
add    $0x1,%r15
add    $0x2,%r14d
cmp    0x30(%rsp),%r15
je     127b <printCL_C+0x11b>
cmpl   $0x0,0x1c(%rsp)
jle    1220 <printCL_C+0xc0>
movslq %r14d,%rax
mov    0x20(%rsp),%rcx
lea    (%rcx,%rax,8),%r13
mov    0x28(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  0x0(%r13),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1060 <printf@plt>
add    %rbp,%r13
add    $0xffffffffffffffff,%r12
jne    1260 <printCL_C+0x100>
jmp    1220 <printCL_C+0xc0>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    0x20(%rsp),%rdi
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@CL_TRUE = global i32 0
@CL_SUCCESS = global i64 0
@.str = [7 x i8] c"failed\00"
@.str.1 = [4 x i8] c"%f \00"
@.str.2 = [2 x i8] c"\0A\00"
define void @printCL_C(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %10
store i32 0, i32* %11
store i64 0, i64* %12
%13 = load i32, i32* %7
%14 = mul nsw i32 2, %13
%15 = load i32, i32* %8
%16 = mul nsw i32 %14, %15
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 8
%19 = trunc i64 %18 to i32
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to double*
store double* %21, double** %9
%22 = load i32*, i32** %6
%23 = load i32, i32* %22
%24 = load i32*, i32** %5
%25 = load i32, i32* %24
%26 = load i32, i32* @CL_TRUE
%27 = load i32, i32* %7
%28 = mul nsw i32 2, %27
%29 = load i32, i32* %8
%30 = mul nsw i32 %28, %29
%31 = sext i32 %30 to i64
%32 = mul i64 %31, 8
%33 = trunc i64 %32 to i32
%34 = load double*, double** %9
%35 = call i64 @clEnqueueReadBuffer(i32 %23, i32 %25, i32 %26, i32 0, i32 %33, double* %34, i32 0, i32* null, i32* null)
store i64 %35, i64* %12
%36 = load i32*, i32** %6
%37 = load i32, i32* %36
%38 = call i64 @clFinish(i32 %37)
store i64 %38, i64* %12
%39 = load i64, i64* %12
%40 = load i64, i64* @CL_SUCCESS
%41 = icmp ne i64 %39, %40
br i1 %41, label %42, label %44
42: ; preds = %4
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %44
44: ; preds = %42, %4
store i32 0, i32* %10
br label %45
45: ; preds = %72, %44
%46 = load i32, i32* %10
%47 = load i32, i32* %7
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %75
49: ; preds = %45
store i32 0, i32* %11
br label %50
50: ; preds = %67, %49
%51 = load i32, i32* %11
%52 = load i32, i32* %8
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %70
54: ; preds = %50
%55 = load double*, double** %9
%56 = load i32, i32* %10
%57 = mul nsw i32 2, %56
%58 = load i32, i32* %7
%59 = mul nsw i32 %58, 2
%60 = load i32, i32* %11
%61 = mul nsw i32 %59, %60
%62 = add nsw i32 %57, %61
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds double, double* %55, i64 %63
%65 = load double, double* %64
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %65)
br label %67
67: ; preds = %54
%68 = load i32, i32* %11
%69 = add nsw i32 %68, 1
store i32 %69, i32* %11
br label %50
70: ; preds = %50
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %72
72: ; preds = %70
%73 = load i32, i32* %10
%74 = add nsw i32 %73, 1
store i32 %74, i32* %10
br label %45
75: ; preds = %45
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%77 = load double*, double** %9
%78 = call i32 @free(double* %77)
ret void
}

LLVM IR (-O2):
@CL_TRUE = global i32 0
@CL_SUCCESS = global i64 0
@.str = [7 x i8] c"failed\00"
@.str.1 = [4 x i8] c"%f \00"
define void @printCL_C(i32* nocapture %0, i32* nocapture %1, i32 %2, i32 %3) {
%5 = shl nsw i32 %2, 1
%6 = shl i32 %3, 3
%7 = mul i32 %6, %5
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to double*
%10 = load i32, i32* %1
%11 = load i32, i32* %0
%12 = load i32, i32* @CL_TRUE
%13 = tail call i64 @clEnqueueReadBuffer(i32 %10, i32 %11, i32 %12, i32 0, i32 %7, double* %9, i32 0, i32* null, i32* null)
%14 = load i32, i32* %1
%15 = tail call i64 @clFinish(i32 %14)
%16 = load i64, i64* @CL_SUCCESS
%17 = icmp eq i64 %15, %16
br i1 %17, label %20, label %18
18: ; preds = %4
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %4
%21 = icmp sgt i32 %2, 0
br i1 %21, label %22, label %46
22: ; preds = %20
%23 = icmp sgt i32 %3, 0
%24 = sext i32 %5 to i64
%25 = zext i32 %2 to i64
%26 = zext i32 %3 to i64
br label %27
27: ; preds = %22, %42
%28 = phi i64 [ 0, %22 ], [ %44, %42 ]
br i1 %23, label %29, label %42
29: ; preds = %27
%30 = trunc i64 %28 to i32
%31 = shl i32 %30, 1
%32 = sext i32 %31 to i64
br label %33
33: ; preds = %29, %33
%34 = phi i64 [ 0, %29 ], [ %40, %33 ]
%35 = mul nsw i64 %34, %24
%36 = add nsw i64 %35, %32
%37 = getelementptr inbounds double, double* %9, i64 %36
%38 = load double, double* %37
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %38)
%40 = add nuw nsw i64 %34, 1
%41 = icmp eq i64 %40, %26
br i1 %41, label %42, label %33
42: ; preds = %33, %27
%43 = tail call i32 @putchar(i32 10)
%44 = add nuw nsw i64 %28, 1
%45 = icmp eq i64 %44, %25
br i1 %45, label %46, label %27
46: ; preds = %42, %20
%47 = tail call i32 @putchar(i32 10)
%48 = tail call i32 @free(double* %9)
ret void
}