#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fwrite(float *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void write_result_ocl(float *res, int xDim, int yDim, char *dst) {
  FILE *out = fopen(dst, "wb");
  if (out == NULL) {
    fprintf(stderr, "Error: Couldn't write result to file!\n");
    return;
  }
  int i, j, n;
  for (i = 0; i < xDim; i++) {
    for (j = 0; j < yDim; j++) {
      n = fwrite(res, sizeof(float), 1, out);
      res++;
    }
  }
}


x86 assembly (clang, -O0):
<write_result_ocl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeaf(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117f <write_result_ocl+0x4f>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
lea    0xe8e(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11ec <write_result_ocl+0xbc>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ec <write_result_ocl+0xbc>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11d9 <write_result_ocl+0xa9>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1050 <fwrite@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1199 <write_result_ocl+0x69>
jmp    11de <write_result_ocl+0xae>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1186 <write_result_ocl+0x56>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_result_ocl>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%r14d
mov    %rdi,%rbp
lea    0xeb5(%rip),%rsi
mov    %rcx,%rdi
call   1040 <fopen@plt>
test   %rax,%rax
je     11bf <write_result_ocl+0x8f>
test   %r14d,%r14d
jle    11b0 <write_result_ocl+0x80>
mov    %rax,%r13
xor    %r12d,%r12d
jmp    1179 <write_result_ocl+0x49>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r12d
cmp    %r14d,%r12d
je     11b0 <write_result_ocl+0x80>
test   %r15d,%r15d
jle    1170 <write_result_ocl+0x40>
mov    %r15d,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1050 <fwrite@plt>
add    $0x4,%rbp
add    $0xffffffff,%ebx
jne    1190 <write_result_ocl+0x60>
jmp    1170 <write_result_ocl+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fprintf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.1 = [39 x i8] c"Error: Couldn't write result to file!\0A\00"
define void @write_result_ocl(float* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca float*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store float* %0, float** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%13 = load i8*, i8** %8
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %9
%15 = load i32*, i32** %9
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %4
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %43
20: ; preds = %4
store i32 0, i32* %10
br label %21
21: ; preds = %40, %20
%22 = load i32, i32* %10
%23 = load i32, i32* %6
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %43
25: ; preds = %21
store i32 0, i32* %11
br label %26
26: ; preds = %36, %25
%27 = load i32, i32* %11
%28 = load i32, i32* %7
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %39
30: ; preds = %26
%31 = load float*, float** %5
%32 = load i32*, i32** %9
%33 = call i32 @fwrite(float* %31, i32 4, i32 1, i32* %32)
store i32 %33, i32* %12
%34 = load float*, float** %5
%35 = getelementptr inbounds float, float* %34, i32 1
store float* %35, float** %5
br label %36
36: ; preds = %30
%37 = load i32, i32* %11
%38 = add nsw i32 %37, 1
store i32 %38, i32* %11
br label %26
39: ; preds = %26
br label %40
40: ; preds = %39
%41 = load i32, i32* %10
%42 = add nsw i32 %41, 1
store i32 %42, i32* %10
br label %21
43: ; preds = %17, %21
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.1 = [39 x i8] c"Error: Couldn't write result to file!\0A\00"
define void @write_result_ocl(float* nocapture %0, i32 %1, i32 %2, i8* nocapture %3) {
%5 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %28
9: ; preds = %7
%10 = icmp sgt i32 %2, 0
br label %14
11: ; preds = %4
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %28
14: ; preds = %9, %24
%15 = phi float* [ %0, %9 ], [ %25, %24 ]
%16 = phi i32 [ 0, %9 ], [ %26, %24 ]
br i1 %10, label %17, label %24
17: ; preds = %14, %17
%18 = phi float* [ %21, %17 ], [ %15, %14 ]
%19 = phi i32 [ %22, %17 ], [ 0, %14 ]
%20 = tail call i32 @fwrite(float* %18, i32 4, i32 1, i32* %5)
%21 = getelementptr inbounds float, float* %18, i64 1
%22 = add nuw nsw i32 %19, 1
%23 = icmp eq i32 %22, %2
br i1 %23, label %24, label %17
24: ; preds = %17, %14
%25 = phi float* [ %15, %14 ], [ %21, %17 ]
%26 = add nuw nsw i32 %16, 1
%27 = icmp eq i32 %26, %1
br i1 %27, label %28, label %14
28: ; preds = %24, %7, %11
ret void
}