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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fputc(unsigned char, int /*<<< orphan*/);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/, char *, float *);
int /*<<< orphan*/ sscanf(char *, char *, float *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  float outputf;
  unsigned char output;
  float input;
  float min, max;
  int i;
  int snx, sny;
  if (argc < 4) {
    fprintf(stderr, "not enough arguments\n");
    fprintf(stderr, "e.g. data2r8 25 1950 min max < intputfile > outputfile\n");
    exit(1);
  }
  snx = atoi(argv[1]);
  sny = atoi(argv[2]);
  sscanf(argv[3], "%f", &min);
  sscanf(argv[4], "%f", &max);
  fprintf(stderr, "snx=%d sny=%d min=%g max=%g\n", snx, sny, min, max);
  fflush(stderr);
  for (i = 0; i < snx * sny; i++) {
    fscanf(stdin, "%f", &input);
    outputf = (input - min) / (max - min) * 255.0;
    output = (unsigned char)(outputf);
    fputc(output, stdout);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11c8 <main+0x58>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe5f(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1070 <sscanf@plt>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
lea    0xe47(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1070 <sscanf@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x24(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xe19(%rip),%rsi
mov    $0x2,%al
call   1050 <fprintf@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x2c(%rbp),%ecx
imul   -0x30(%rbp),%ecx
cmp    %ecx,%eax
jge    12e5 <main+0x175>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
lea    0xdd8(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1030 <fscanf@plt>
movss  -0x1c(%rbp),%xmm0
movss  -0x20(%rbp),%xmm2
subss  %xmm2,%xmm0
movss  -0x24(%rbp),%xmm1
subss  %xmm2,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd52(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
cvttss2si -0x14(%rbp),%eax
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
mov    0x2d03(%rip),%rcx
mov    (%rcx),%esi
movzbl %al,%edi
call   1040 <fputc@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    125c <main+0xec>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x3,%edi
jle    1287 <main+0x117>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
mov    0x10(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebx
mov    0x18(%rbp),%rdi
lea    0xea8(%rip),%r15
lea    0x8(%rsp),%rdx
mov    %r15,%rsi
call   1070 <sscanf@plt>
mov    0x20(%rbp),%rdi
lea    0x4(%rsp),%rdx
mov    %r15,%rsi
call   1070 <sscanf@plt>
mov    0x2e09(%rip),%rbp
mov    0x0(%rbp),%edi
movss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  0x4(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xe68(%rip),%rsi
mov    %r14d,%edx
mov    %ebx,%ecx
mov    $0x2,%al
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
call   1060 <fflush@plt>
imul   %r14d,%ebx
test   %ebx,%ebx
jle    1278 <main+0x108>
mov    0x2dd8(%rip),%r15
lea    0xe3b(%rip),%r14
lea    0xc(%rsp),%r12
mov    0x2dad(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15),%edi
mov    %r14,%rsi
mov    %r12,%rdx
call   1030 <fscanf@plt>
movss  0xc(%rsp),%xmm0
movss  0x8(%rsp),%xmm1
subss  %xmm1,%xmm0
movss  0x4(%rsp),%xmm2
subss  %xmm1,%xmm2
divss  %xmm2,%xmm0
mulss  0xd9c(%rip),%xmm0
cvttss2si %xmm0,%eax
mov    0x0(%rbp),%esi
movzbl %al,%edi
call   1040 <fputc@plt>
add    $0xffffffff,%ebx
jne    1230 <main+0xc0>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d4a(%rip),%rbx
mov    (%rbx),%edi
lea    0xd6d(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xd73(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"not enough arguments\0A\00"
@.str.1 = [56 x i8] c"e.g. data2r8 25 1950 min max < intputfile > outputfile\0A\00"
@.str.2 = [3 x i8] c"%f\00"
@.str.3 = [29 x i8] c"snx=%d sny=%d min=%g max=%g\0A\00"
@stdin = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca float
%7 = alloca i8
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 4
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %12
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %13
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 3
%33 = load i8*, i8** %32
%34 = call i32 @sscanf(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %9)
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 4
%37 = load i8*, i8** %36
%38 = call i32 @sscanf(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %10)
%39 = load i32, i32* @stderr
%40 = load i32, i32* %12
%41 = load i32, i32* %13
%42 = load float, float* %9
%43 = fpext float %42 to double
%44 = load float, float* %10
%45 = fpext float %44 to double
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %40, i32 %41, double %43, double %45)
%47 = load i32, i32* @stderr
%48 = call i32 @fflush(i32 %47)
store i32 0, i32* %11
br label %49
49: ; preds = %73, %22
%50 = load i32, i32* %11
%51 = load i32, i32* %12
%52 = load i32, i32* %13
%53 = mul nsw i32 %51, %52
%54 = icmp slt i32 %50, %53
br i1 %54, label %55, label %76
55: ; preds = %49
%56 = load i32, i32* @stdin
%57 = call i32 @fscanf(i32 %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %8)
%58 = load float, float* %8
%59 = load float, float* %9
%60 = fsub float %58, %59
%61 = load float, float* %10
%62 = load float, float* %9
%63 = fsub float %61, %62
%64 = fdiv float %60, %63
%65 = fpext float %64 to double
%66 = fmul double %65, 2.550000e+02
%67 = fptrunc double %66 to float
store float %67, float* %6
%68 = load float, float* %6
%69 = fptoui float %68 to i8
store i8 %69, i8* %7
%70 = load i8, i8* %7
%71 = load i32, i32* @stdout
%72 = call i32 @fputc(i8 zeroext %70, i32 %71)
br label %73
73: ; preds = %55
%74 = load i32, i32* %11
%75 = add nsw i32 %74, 1
store i32 %75, i32* %11
br label %49
76: ; preds = %49
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"not enough arguments\0A\00"
@.str.1 = [56 x i8] c"e.g. data2r8 25 1950 min max < intputfile > outputfile\0A\00"
@.str.2 = [3 x i8] c"%f\00"
@.str.3 = [29 x i8] c"snx=%d sny=%d min=%g max=%g\0A\00"
@stdin = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = bitcast float* %3 to i8*
%7 = bitcast float* %4 to i8*
%8 = bitcast float* %5 to i8*
%9 = icmp slt i32 %0, 4
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32 @atoi(i8* %21)
%23 = getelementptr inbounds i8*, i8** %1, i64 3
%24 = load i8*, i8** %23
%25 = call i32 @sscanf(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %4)
%26 = getelementptr inbounds i8*, i8** %1, i64 4
%27 = load i8*, i8** %26
%28 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %5)
%29 = load i32, i32* @stderr
%30 = load float, float* %4
%31 = fpext float %30 to double
%32 = load float, float* %5
%33 = fpext float %32 to double
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %19, i32 %22, double %31, double %33)
%35 = load i32, i32* @stderr
%36 = call i32 @fflush(i32 %35)
%37 = mul i32 %22, %19
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %55
39: ; preds = %16, %39
%40 = phi i32 [ %53, %39 ], [ 0, %16 ]
%41 = load i32, i32* @stdin
%42 = call i32 @fscanf(i32 %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %3)
%43 = load float, float* %3
%44 = load float, float* %4
%45 = fsub float %43, %44
%46 = load float, float* %5
%47 = fsub float %46, %44
%48 = fdiv float %45, %47
%49 = fmul float %48, 2.550000e+02
%50 = fptoui float %49 to i8
%51 = load i32, i32* @stdout
%52 = call i32 @fputc(i8 zeroext %50, i32 %51)
%53 = add nuw nsw i32 %40, 1
%54 = icmp eq i32 %53, %37
br i1 %54, label %55, label %39
55: ; preds = %39, %16
ret i32 0
}