#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void printFloatMapAsPgm(float ***map, const unsigned int MAP_SIZE, char *fn) {
  int i, j, max = -1;
  FILE *f;
  char *filename =
      (char *)malloc((strlen("ds_map.pgm") + strlen(fn)) * sizeof(char) + 1);
  strcpy(filename, fn);
  strcat(filename, "ds_map.pgm");
  f = fopen(filename, "w");
  fprintf(f, "P2\n");
  fprintf(f, "%u %u\n", MAP_SIZE, MAP_SIZE);
  fprintf(f, "255\n");
  for (i = 0; i < MAP_SIZE; ++i) {
    for (j = 0; j < MAP_SIZE; ++j) {
      fprintf(f, "%d ", (int)((*map)[i][j] * 255.0f));
    }
    fprintf(f, "\n");
  }
  fclose(f);
  free(filename);
}


x86 assembly (clang, -O0):
<printFloatMapAsPgm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xffffffff,-0x24(%rbp)
lea    0xe63(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
add    %ecx,%eax
cltq
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rdi
lea    0xe1e(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x38(%rbp),%rdi
lea    0xe19(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xdf3(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
lea    0xde8(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    12c5 <printFloatMapAsPgm+0x145>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    12a5 <printFloatMapAsPgm+0x125>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x20(%rbp),%rcx
movss  0xd80(%rip),%xmm0
mulss  (%rax,%rcx,4),%xmm0
cvttss2si %xmm0,%edx
lea    0xd91(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1255 <printFloatMapAsPgm+0xd5>
mov    -0x30(%rbp),%rdi
lea    0xd63(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1242 <printFloatMapAsPgm+0xc2>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printFloatMapAsPgm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%r13d
mov    %rdi,%r15
lea    0xe49(%rip),%r12
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    (%rax,%rbp,1),%edi
add    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
call   10b0 <strcat@plt>
lea    0xe17(%rip),%rsi
mov    %rbp,(%rsp)
mov    %rbp,%rdi
call   10a0 <fopen@plt>
mov    %rax,%r14
lea    0xe03(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10c0 <fwrite@plt>
lea    0xdee(%rip),%rsi
mov    %r14,%rdi
mov    %r13d,%edx
mov    %r13d,%ecx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xdde(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10c0 <fwrite@plt>
test   %r13d,%r13d
je     12c4 <printFloatMapAsPgm+0x124>
mov    %r13d,%r13d
lea    0xdc2(%rip),%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r15),%rax
mov    (%rax,%rbx,8),%rax
movss  (%rax,%rbp,4),%xmm0
mulss  0xd6c(%rip),%xmm0
cvttss2si %xmm0,%edx
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1280 <printFloatMapAsPgm+0xe0>
mov    $0xa,%edi
mov    %r14,%rsi
call   1070 <fputc@plt>
add    $0x1,%rbx
cmp    %r13,%rbx
jne    1270 <printFloatMapAsPgm+0xd0>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    (%rsp),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"ds_map.pgm\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"P2\0A\00"
@.str.3 = [7 x i8] c"%u %u\0A\00"
@.str.4 = [5 x i8] c"255\0A\00"
@.str.5 = [4 x i8] c"%d \00"
@.str.6 = [2 x i8] c"\0A\00"
define void @printFloatMapAsPgm(float*** %0, i32 %1, i8* %2) {
%4 = alloca float***
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i8*
store float*** %0, float**** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
store i32 -1, i32* %9
%12 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%13 = load i8*, i8** %6
%14 = call i32 @strlen(i8* %13)
%15 = add nsw i32 %12, %14
%16 = sext i32 %15 to i64
%17 = mul i64 %16, 1
%18 = add i64 %17, 1
%19 = trunc i64 %18 to i32
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %11
%22 = load i8*, i8** %11
%23 = load i8*, i8** %6
%24 = call i32 @strcpy(i8* %22, i8* %23)
%25 = load i8*, i8** %11
%26 = call i32 @strcat(i8* %25, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%27 = load i8*, i8** %11
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %28, i32** %10
%29 = load i32*, i32** %10
%30 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32*, i32** %10
%32 = load i32, i32* %5
%33 = load i32, i32* %5
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %32, i32 %33)
%35 = load i32*, i32** %10
%36 = call i32 (i32*, i8*, ...) @fprintf(i32* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %7
br label %37
37: ; preds = %67, %3
%38 = load i32, i32* %7
%39 = load i32, i32* %5
%40 = icmp ult i32 %38, %39
br i1 %40, label %41, label %70
41: ; preds = %37
store i32 0, i32* %8
br label %42
42: ; preds = %61, %41
%43 = load i32, i32* %8
%44 = load i32, i32* %5
%45 = icmp ult i32 %43, %44
br i1 %45, label %46, label %64
46: ; preds = %42
%47 = load i32*, i32** %10
%48 = load float***, float**** %4
%49 = load float**, float*** %48
%50 = load i32, i32* %7
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds float*, float** %49, i64 %51
%53 = load float*, float** %52
%54 = load i32, i32* %8
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds float, float* %53, i64 %55
%57 = load float, float* %56
%58 = fmul float %57, 2.550000e+02
%59 = fptosi float %58 to i32
%60 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %59)
br label %61
61: ; preds = %46
%62 = load i32, i32* %8
%63 = add nsw i32 %62, 1
store i32 %63, i32* %8
br label %42
64: ; preds = %42
%65 = load i32*, i32** %10
%66 = call i32 (i32*, i8*, ...) @fprintf(i32* %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %67
67: ; preds = %64
%68 = load i32, i32* %7
%69 = add nsw i32 %68, 1
store i32 %69, i32* %7
br label %37
70: ; preds = %37
%71 = load i32*, i32** %10
%72 = call i32 @fclose(i32* %71)
%73 = load i8*, i8** %11
%74 = call i32 @free(i8* %73)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"ds_map.pgm\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"P2\0A\00"
@.str.3 = [7 x i8] c"%u %u\0A\00"
@.str.4 = [5 x i8] c"255\0A\00"
@.str.5 = [4 x i8] c"%d \00"
define void @printFloatMapAsPgm(float*** nocapture %0, i32 %1, i8* %2) {
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @strlen(i8* %2)
%6 = add i32 %4, 1
%7 = add i32 %6, %5
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @strcpy(i8* %9, i8* %2)
%11 = tail call i32 @strcat(i8* %9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 3, i64 1, i32* %12)
%14 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %1, i32 %1)
%15 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 4, i64 1, i32* %12)
%16 = icmp eq i32 %1, 0
br i1 %16, label %37, label %17
17: ; preds = %3
%18 = zext i32 %1 to i64
br label %19
19: ; preds = %17, %33
%20 = phi i64 [ 0, %17 ], [ %35, %33 ]
br label %21
21: ; preds = %19, %21
%22 = phi i64 [ 0, %19 ], [ %31, %21 ]
%23 = load float**, float*** %0
%24 = getelementptr inbounds float*, float** %23, i64 %20
%25 = load float*, float** %24
%26 = getelementptr inbounds float, float* %25, i64 %22
%27 = load float, float* %26
%28 = fmul float %27, 2.550000e+02
%29 = fptosi float %28 to i32
%30 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %29)
%31 = add nuw nsw i64 %22, 1
%32 = icmp eq i64 %31, %18
br i1 %32, label %33, label %21
33: ; preds = %21
%34 = tail call i32 @fputc(i32 10, i32* %12)
%35 = add nuw nsw i64 %20, 1
%36 = icmp eq i64 %35, %18
br i1 %36, label %37, label %19
37: ; preds = %33, %3
%38 = tail call i32 @fclose(i32* %12)
%39 = tail call i32 @free(i8* %9)
ret void
}