#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *, char *);
output_f(float *w, int B, int H, char *filename) {
  int i, j, temp;
  FILE *fpo;
  if ((fpo = fopen(filename, "w")) == NULL) {
    printf("Couldn't open %s for writing !\n", filename);
    exit(-1);
  }
  fprintf(fpo, "P2\n%d %d\n%d\n", B, H, 255);
  for (j = 0; j < H; j++) {
    for (i = 0; i < B; i++) {
      temp = (int)w[j * B + i];
      fprintf(fpo, "%d ", temp);
    }
    fprintf(fpo, "\n");
  }
  fclose(fpo);
}


x86 assembly (clang, -O0):
<output_f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    119e <output_f+0x4e>
mov    -0x20(%rbp),%rsi
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe73(%rip),%rsi
mov    $0xff,%r8d
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    123e <output_f+0xee>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    121e <output_f+0xce>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
imul   -0x14(%rbp),%ecx
add    -0x24(%rbp),%ecx
movslq %ecx,%rcx
cvttss2si (%rax,%rcx,4),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xe26(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d6 <output_f+0x86>
mov    -0x38(%rbp),%rdi
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11c3 <output_f+0x73>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_f>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r12
mov    %edx,%r15d
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0xe7f(%rip),%rsi
mov    %rcx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1254 <output_f+0xf4>
mov    %rax,%rbp
lea    0xe86(%rip),%rsi
mov    %rax,%rdi
mov    %r14d,%edx
mov    %r15d,%ecx
mov    $0xff,%r8d
xor    %eax,%eax
call   1060 <fprintf@plt>
test   %r15d,%r15d
jle    123e <output_f+0xde>
mov    %r14d,%eax
movslq %r14d,%rcx
mov    %r15d,%edx
mov    %rdx,0x8(%rsp)
mov    %r14d,%r14d
shl    $0x2,%rcx
mov    %rcx,0x10(%rsp)
lea    0xe53(%rip),%r15
xor    %r13d,%r13d
mov    %eax,0x4(%rsp)
jmp    1211 <output_f+0xb1>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xa,%edi
mov    %rbp,%rsi
call   1050 <fputc@plt>
add    $0x1,%r13
add    0x10(%rsp),%rbx
cmp    0x8(%rsp),%r13
mov    0x4(%rsp),%eax
je     123e <output_f+0xde>
test   %eax,%eax
jle    11f0 <output_f+0x90>
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
cvttss2si (%rbx,%r12,4),%edx
mov    %rbp,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%r12
cmp    %r12,%r14
jne    1220 <output_f+0xc0>
jmp    11f0 <output_f+0x90>
mov    %rbp,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
lea    0xda7(%rip),%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [32 x i8] c"Couldn't open %s for writing !\0A\00"
@.str.2 = [13 x i8] c"P2\0A%d %d\0A%d\0A\00"
@.str.3 = [4 x i8] c"%d \00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @output_f(float* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca float*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
store float* %0, float** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%14 = load i8*, i8** %9
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %13
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %4
%18 = load i8*, i8** %9
%19 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %4
%22 = load i32*, i32** %13
%23 = load i32, i32* %7
%24 = load i32, i32* %8
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 %24, i32 255)
store i32 0, i32* %11
br label %26
26: ; preds = %55, %21
%27 = load i32, i32* %11
%28 = load i32, i32* %8
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %58
30: ; preds = %26
store i32 0, i32* %10
br label %31
31: ; preds = %49, %30
%32 = load i32, i32* %10
%33 = load i32, i32* %7
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %52
35: ; preds = %31
%36 = load float*, float** %6
%37 = load i32, i32* %11
%38 = load i32, i32* %7
%39 = mul nsw i32 %37, %38
%40 = load i32, i32* %10
%41 = add nsw i32 %39, %40
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds float, float* %36, i64 %42
%44 = load float, float* %43
%45 = fptosi float %44 to i32
store i32 %45, i32* %12
%46 = load i32*, i32** %13
%47 = load i32, i32* %12
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %35
%50 = load i32, i32* %10
%51 = add nsw i32 %50, 1
store i32 %51, i32* %10
br label %31
52: ; preds = %31
%53 = load i32*, i32** %13
%54 = call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %55
55: ; preds = %52
%56 = load i32, i32* %11
%57 = add nsw i32 %56, 1
store i32 %57, i32* %11
br label %26
58: ; preds = %26
%59 = load i32*, i32** %13
%60 = call i32 @fclose(i32* %59)
%61 = load i32, i32* %5
ret i32 %61
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [32 x i8] c"Couldn't open %s for writing !\0A\00"
@.str.2 = [13 x i8] c"P2\0A%d %d\0A%d\0A\00"
@.str.3 = [4 x i8] c"%d \00"
define i32 @output_f(float* nocapture %0, i32 %1, i32 %2, i8* %3) {
%5 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %4
%11 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %1, i32 %2, i32 255)
%12 = icmp sgt i32 %2, 0
br i1 %12, label %13, label %35
13: ; preds = %10
%14 = icmp sgt i32 %1, 0
%15 = sext i32 %1 to i64
%16 = zext i32 %2 to i64
%17 = zext i32 %1 to i64
br label %18
18: ; preds = %13, %31
%19 = phi i64 [ 0, %13 ], [ %33, %31 ]
br i1 %14, label %20, label %31
20: ; preds = %18
%21 = mul nsw i64 %19, %15
br label %22
22: ; preds = %20, %22
%23 = phi i64 [ 0, %20 ], [ %29, %22 ]
%24 = add nsw i64 %23, %21
%25 = getelementptr inbounds float, float* %0, i64 %24
%26 = load float, float* %25
%27 = fptosi float %26 to i32
%28 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = add nuw nsw i64 %23, 1
%30 = icmp eq i64 %29, %17
br i1 %30, label %31, label %22
31: ; preds = %22, %18
%32 = tail call i32 @fputc(i32 10, i32* %5)
%33 = add nuw nsw i64 %19, 1
%34 = icmp eq i64 %33, %16
br i1 %34, label %35, label %18
35: ; preds = %31, %10
%36 = tail call i32 @fclose(i32* %5)
ret i32 undef
}