#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 */
scalar_t__ EOF;
int /*<<< orphan*/ errorf(char *, char const *);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputc(double, int /*<<< orphan*/ *);
int /*<<< orphan*/ *stdout;
scalar_t__ strcmp(char const *, char *);
void write_pgm_normalize_given_minmax_float(const char *fname,
                                            const float *data, int ncol,
                                            int nrow, float min, float max) {
  FILE *f;
  int i, j;
  if (max == min)
    errorf("Error: unable to normalize to max and min values. They are equal",
           fname);
  if (strcmp(fname, "-") == 0)
    f = stdout;
  else
    f = fopen(fname, "w");
  if (f == NULL)
    errorf("Error: unable to open output image file ", fname);
  fprintf(f, "P5\n");
  fprintf(f, "%u %u\n", ncol, nrow);
  fprintf(f, "%d\n", 255);
  for (i = 0; i < nrow; i++)
    for (j = 0; j < ncol; j++) {
      fputc((unsigned char)(data[j + i * ncol] - min > 0)
                ? 255.0 / (max - min) * (data[j + i * ncol] - min)
                : 0,
            f);
    }
  if (f != stdout && fclose(f) == EOF)
    errorf("Error: unable to close file while writing PGM file ", fname);
}


x86 assembly (clang, -O0):
<write_pgm_normalize_given_minmax_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movss  %xmm0,-0x1c(%rbp)
movss  %xmm1,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
ucomiss -0x1c(%rbp),%xmm0
jne    11a5 <write_pgm_normalize_given_minmax_float+0x45>
jp     11a5 <write_pgm_normalize_given_minmax_float+0x45>
mov    -0x8(%rbp),%rsi
lea    0xe68(%rip),%rdi
call   1070 <errorf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11d2 <write_pgm_normalize_given_minmax_float+0x72>
mov    0x2e12(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    11e6 <write_pgm_normalize_given_minmax_float+0x86>
mov    -0x8(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1201 <write_pgm_normalize_given_minmax_float+0xa1>
mov    -0x8(%rbp),%rsi
lea    0xe51(%rip),%rdi
call   1070 <errorf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe6a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe4b(%rip),%rsi
mov    $0xff,%edx
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1324 <write_pgm_normalize_given_minmax_float+0x1c4>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1311 <write_pgm_normalize_given_minmax_float+0x1b1>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    -0x2c(%rbp),%edx
imul   -0x14(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
subss  -0x1c(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
movzbl %al,%eax
cmp    $0x0,%eax
je     12e8 <write_pgm_normalize_given_minmax_float+0x188>
movss  -0x20(%rbp),%xmm0
subss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd4b(%rip),%xmm0
divsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    -0x2c(%rbp),%edx
imul   -0x14(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm1
subss  -0x1c(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    12f5 <write_pgm_normalize_given_minmax_float+0x195>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    12f5 <write_pgm_normalize_given_minmax_float+0x195>
movsd  -0x38(%rbp),%xmm0
mov    -0x28(%rbp),%rdi
call   1040 <fputc@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    125c <write_pgm_normalize_given_minmax_float+0xfc>
jmp    1316 <write_pgm_normalize_given_minmax_float+0x1b6>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1249 <write_pgm_normalize_given_minmax_float+0xe9>
mov    -0x28(%rbp),%rax
mov    0x2ca9(%rip),%rcx
cmp    (%rcx),%rax
je     1361 <write_pgm_normalize_given_minmax_float+0x201>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2ca0(%rip),%rcx
cmp    (%rcx),%rax
jne    1361 <write_pgm_normalize_given_minmax_float+0x201>
mov    -0x8(%rbp),%rsi
lea    0xd29(%rip),%rdi
call   1070 <errorf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_pgm_normalize_given_minmax_float>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,%r12d
mov    %edx,0x8(%rsp)
mov    %rsi,%rbx
mov    %rdi,%r14
movss  %xmm0,0xc(%rsp)
movss  %xmm1,0x10(%rsp)
ucomiss %xmm0,%xmm1
jne    11ad <write_pgm_normalize_given_minmax_float+0x3d>
jp     11ad <write_pgm_normalize_given_minmax_float+0x3d>
lea    0xe67(%rip),%rdi
mov    %r14,%rsi
call   1070 <errorf@plt>
lea    0xe99(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1323 <write_pgm_normalize_given_minmax_float+0x1b3>
lea    0xe83(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbp
test   %rbp,%rbp
jne    11eb <write_pgm_normalize_given_minmax_float+0x7b>
lea    0xe6e(%rip),%rdi
mov    %r14,%rsi
call   1070 <errorf@plt>
mov    %r14,0x18(%rsp)
lea    0xe83(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1090 <fwrite@plt>
lea    0xe6e(%rip),%rsi
mov    %rbp,%rdi
mov    0x8(%rsp),%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xe5d(%rip),%rsi
mov    %rbp,%rdi
mov    $0xff,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
test   %r12d,%r12d
jle    12d5 <write_pgm_normalize_given_minmax_float+0x165>
movss  0x10(%rsp),%xmm0
subss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xda8(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
mov    0x8(%rsp),%eax
movslq %eax,%r13
mov    %r12d,%ecx
mov    %rcx,0x20(%rsp)
mov    %eax,%r14d
shl    $0x2,%r13
xor    %r15d,%r15d
jmp    128e <write_pgm_normalize_given_minmax_float+0x11e>
nopl   (%rax)
add    $0x1,%r15
add    %r13,%rbx
cmp    0x20(%rsp),%r15
je     12d5 <write_pgm_normalize_given_minmax_float+0x165>
cmpl   $0x0,0x8(%rsp)
jle    1280 <write_pgm_normalize_given_minmax_float+0x110>
xor    %r12d,%r12d
jmp    12b4 <write_pgm_normalize_given_minmax_float+0x144>
nopw   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
mov    %rbp,%rdi
call   1040 <fputc@plt>
add    $0x1,%r12
cmp    %r12,%r14
je     1280 <write_pgm_normalize_given_minmax_float+0x110>
movss  (%rbx,%r12,4),%xmm0
subss  0xc(%rsp),%xmm0
ucomiss 0xd41(%rip),%xmm0
jbe    12a0 <write_pgm_normalize_given_minmax_float+0x130>
cvtss2sd %xmm0,%xmm0
mulsd  0x10(%rsp),%xmm0
jmp    12a3 <write_pgm_normalize_given_minmax_float+0x133>
mov    0x2cfc(%rip),%rax
cmp    (%rax),%rbp
je     1314 <write_pgm_normalize_given_minmax_float+0x1a4>
mov    %rbp,%rdi
call   1030 <fclose@plt>
mov    0x2cf8(%rip),%rcx
cmp    (%rcx),%rax
jne    1314 <write_pgm_normalize_given_minmax_float+0x1a4>
lea    0xd8d(%rip),%rdi
mov    0x18(%rsp),%rsi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <errorf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cae(%rip),%rax
mov    (%rax),%rbp
test   %rbp,%rbp
jne    11eb <write_pgm_normalize_given_minmax_float+0x7b>
jmp    11dc <write_pgm_normalize_given_minmax_float+0x6c>

LLVM IR (-O0):
@.str = [65 x i8] c"Error: unable to normalize to max and min values. They are equal\00"
@.str.1 = [2 x i8] c"-\00"
@stdout = global i32* null
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [41 x i8] c"Error: unable to open output image file \00"
@.str.4 = [4 x i8] c"P5\0A\00"
@.str.5 = [7 x i8] c"%u %u\0A\00"
@.str.6 = [4 x i8] c"%d\0A\00"
@EOF = global i64 0
@.str.7 = [52 x i8] c"Error: unable to close file while writing PGM file \00"
define void @write_pgm_normalize_given_minmax_float(i8* %0, float* %1, i32 %2, i32 %3, float %4, float %5) {
%7 = alloca i8*
%8 = alloca float*
%9 = alloca i32
%10 = alloca i32
%11 = alloca float
%12 = alloca float
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %7
store float* %1, float** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store float %4, float* %11
store float %5, float* %12
%16 = load float, float* %12
%17 = load float, float* %11
%18 = fcmp oeq float %16, %17
br i1 %18, label %19, label %22
19: ; preds = %6
%20 = load i8*, i8** %7
%21 = call i32 @errorf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %19, %6
%23 = load i8*, i8** %7
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = load i32*, i32** @stdout
store i32* %27, i32** %13
br label %31
28: ; preds = %22
%29 = load i8*, i8** %7
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %30, i32** %13
br label %31
31: ; preds = %28, %26
%32 = load i32*, i32** %13
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i8*, i8** %7
%36 = call i32 @errorf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %35)
br label %37
37: ; preds = %34, %31
%38 = load i32*, i32** %13
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%40 = load i32*, i32** %13
%41 = load i32, i32* %9
%42 = load i32, i32* %10
%43 = call i32 (i32*, i8*, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %41, i32 %42)
%44 = load i32*, i32** %13
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 255)
store i32 0, i32* %14
br label %46
46: ; preds = %100, %37
%47 = load i32, i32* %14
%48 = load i32, i32* %10
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %103
50: ; preds = %46
store i32 0, i32* %15
br label %51
51: ; preds = %96, %50
%52 = load i32, i32* %15
%53 = load i32, i32* %9
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %99
55: ; preds = %51
%56 = load float*, float** %8
%57 = load i32, i32* %15
%58 = load i32, i32* %14
%59 = load i32, i32* %9
%60 = mul nsw i32 %58, %59
%61 = add nsw i32 %57, %60
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds float, float* %56, i64 %62
%64 = load float, float* %63
%65 = load float, float* %11
%66 = fsub float %64, %65
%67 = fcmp ogt float %66, 0.000000e+00
%68 = zext i1 %67 to i32
%69 = trunc i32 %68 to i8
%70 = zext i8 %69 to i32
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %91
72: ; preds = %55
%73 = load float, float* %12
%74 = load float, float* %11
%75 = fsub float %73, %74
%76 = fpext float %75 to double
%77 = fdiv double 2.550000e+02, %76
%78 = load float*, float** %8
%79 = load i32, i32* %15
%80 = load i32, i32* %14
%81 = load i32, i32* %9
%82 = mul nsw i32 %80, %81
%83 = add nsw i32 %79, %82
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds float, float* %78, i64 %84
%86 = load float, float* %85
%87 = load float, float* %11
%88 = fsub float %86, %87
%89 = fpext float %88 to double
%90 = fmul double %77, %89
br label %92
91: ; preds = %55
br label %92
92: ; preds = %91, %72
%93 = phi double [ %90, %72 ], [ 0.000000e+00, %91 ]
%94 = load i32*, i32** %13
%95 = call i32 @fputc(double %93, i32* %94)
br label %96
96: ; preds = %92
%97 = load i32, i32* %15
%98 = add nsw i32 %97, 1
store i32 %98, i32* %15
br label %51
99: ; preds = %51
br label %100
100: ; preds = %99
%101 = load i32, i32* %14
%102 = add nsw i32 %101, 1
store i32 %102, i32* %14
br label %46
103: ; preds = %46
%104 = load i32*, i32** %13
%105 = load i32*, i32** @stdout
%106 = icmp ne i32* %104, %105
br i1 %106, label %107, label %115
107: ; preds = %103
%108 = load i32*, i32** %13
%109 = call i64 @fclose(i32* %108)
%110 = load i64, i64* @EOF
%111 = icmp eq i64 %109, %110
br i1 %111, label %112, label %115
112: ; preds = %107
%113 = load i8*, i8** %7
%114 = call i32 @errorf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.7, i64 0, i64 0), i8* %113)
br label %115
115: ; preds = %112, %107, %103
ret void
}

LLVM IR (-O2):
@.str = [65 x i8] c"Error: unable to normalize to max and min values. They are equal\00"
@.str.1 = [2 x i8] c"-\00"
@stdout = global i32* null
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [41 x i8] c"Error: unable to open output image file \00"
@.str.4 = [4 x i8] c"P5\0A\00"
@.str.5 = [7 x i8] c"%u %u\0A\00"
@.str.6 = [4 x i8] c"%d\0A\00"
@EOF = global i64 0
@.str.7 = [52 x i8] c"Error: unable to close file while writing PGM file \00"
define void @write_pgm_normalize_given_minmax_float(i8* %0, float* nocapture %1, i32 %2, i32 %3, float %4, float %5) {
%7 = fcmp oeq float %5, %4
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = tail call i32 @errorf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %10
10: ; preds = %8, %6
%11 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = load i32*, i32** @stdout
br label %17
15: ; preds = %10
%16 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %13
%18 = phi i32* [ %14, %13 ], [ %16, %15 ]
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @errorf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %22
22: ; preds = %20, %17
%23 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64 3, i64 1, i32* %18)
%24 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %2, i32 %3)
%25 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 255)
%26 = icmp sgt i32 %3, 0
br i1 %26, label %27, label %55
27: ; preds = %22
%28 = icmp sgt i32 %2, 0
%29 = fsub float %5, %4
%30 = fpext float %29 to double
%31 = fdiv double 2.550000e+02, %30
%32 = sext i32 %2 to i64
%33 = zext i32 %3 to i64
%34 = zext i32 %2 to i64
br label %35
35: ; preds = %27, %52
%36 = phi i64 [ 0, %27 ], [ %53, %52 ]
br i1 %28, label %37, label %52
37: ; preds = %35
%38 = mul nsw i64 %36, %32
br label %39
39: ; preds = %37, %39
%40 = phi i64 [ 0, %37 ], [ %50, %39 ]
%41 = add nsw i64 %40, %38
%42 = getelementptr inbounds float, float* %1, i64 %41
%43 = load float, float* %42
%44 = fsub float %43, %4
%45 = fcmp ogt float %44, 0.000000e+00
%46 = fpext float %44 to double
%47 = fmul double %31, %46
%48 = select i1 %45, double %47, double 0.000000e+00
%49 = tail call i32 @fputc(double %48, i32* %18)
%50 = add nuw nsw i64 %40, 1
%51 = icmp eq i64 %50, %34
br i1 %51, label %52, label %39
52: ; preds = %39, %35
%53 = add nuw nsw i64 %36, 1
%54 = icmp eq i64 %53, %33
br i1 %54, label %55, label %35
55: ; preds = %52, %22
%56 = load i32*, i32** @stdout
%57 = icmp eq i32* %18, %56
br i1 %57, label %64, label %58
58: ; preds = %55
%59 = tail call i64 @fclose(i32* %18)
%60 = load i64, i64* @EOF
%61 = icmp eq i64 %59, %60
br i1 %61, label %62, label %64
62: ; preds = %58
%63 = tail call i32 @errorf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.7, i64 0, i64 0), i8* %0)
br label %64
64: ; preds = %62, %58, %55
ret void
}