// File: /workspace/github_cpp_makefile_star2_O1/cloudinary[P]fuif/./import/read_pam.h
// Function: read_PAM_file(char const*)
Image read_PAM_file(const char *filename) {
    FILE *fp = NULL;
    if (!strcmp(filename,"-")) fp = stdin;
    else fp = fopen(filename,"rb");

    char buf[PPMREADBUFLEN], *t;
    if (!fp) {
        e_printf("Could not open file: %s\n", filename);
        return Image();
    }
    unsigned int width=0,height=0;
    unsigned int maxval=0,nbchans=0;
    do {
        /* # comments before the first line */
        t = fgets(buf, PPMREADBUFLEN, fp);
        if ( t == NULL ) { fclose(fp); return Image(); }
    } while ( strncmp(buf, "#", 1) == 0 || strncmp(buf, "\n", 1) == 0);
    int type=0;
    if ( (!strncmp(buf, "P4", 2)) ) type=4;
    if ( (!strncmp(buf, "P5", 2)) ) type=5;
    if ( (!strncmp(buf, "P6", 2)) ) type=6;
    if ( (!strncmp(buf, "P7", 2)) ) type=7;
    if (type==0) {
        if (buf[0] == 'P') e_printf("PNM file is not of type P4, P5, P6 or P7, cannot read other types.\n");
        else v_printf(8,"This does not look like a PNM file.\n");
        fclose(fp);
        return Image();
    }
    t += 2;

    v_printf(7,"Trying to load a PNM/PAM file of type P%i\n",type);
    if (type < 7) {
      if (!(width = read_pnm_int(fp,buf,&t))) return Image();
      if (!(height = read_pnm_int(fp,buf,&t))) return Image();
      if (type>4) {
        if (!(maxval = read_pnm_int(fp,buf,&t))) return Image();
        if ( maxval > 0xffff ) {
          e_printf("Invalid PNM file (more than 16-bit?)\n");
          fclose(fp);
          return Image();
        }
      } else maxval=1;
      nbchans=(type==6?3:1);
    } else {
      int maxlines = 100;
      do {
        t = fgets(buf, PPMREADBUFLEN, fp);
        if ( t == NULL ) {
            fclose(fp);
            return Image();
        }
        if (strncmp(buf, "#", 1) == 0 || strncmp(buf, "\n", 1) == 0)
            continue;

        sscanf(buf, "WIDTH %u\n", &width);
        sscanf(buf, "HEIGHT %u\n", &height);
        sscanf(buf, "DEPTH %u\n", &nbchans);
        sscanf(buf, "MAXVAL %u\n", &maxval);

        if (maxlines-- < 1) {
            e_printf("Problem while parsing PAM header.\n");
            fclose(fp);
            return Image();
        }
      } while ( strncmp(buf, "ENDHDR", 6) != 0 );
      if (nbchans>4 || nbchans <1 || width <1 || height < 1 || maxval<1 || maxval > 0xffff) {
        e_printf("Couldn't parse PAM header, or unsupported kind of PAM file.\n");
        fclose(fp);
        return Image();
      }
    }

    v_printf(7,"Loading %ix%i PNM/PAM file with %i channels and maxval=%i\n",width,height,nbchans,maxval);
    Image image(width,height, maxval, nbchans);
    if (type==4) {
      char byte=0;
      for (unsigned int y=0; y<height; y++) {
        for (unsigned int x=0; x<width; x++) {
                if (x%8 == 0) byte = fgetc(fp);
                image.channel[0].value(y,x) = (byte & (128>>(x%8)) ? 0 : 1);
        }
      }
    } else {
      if (maxval > 0xff) {
        for (unsigned int y=0; y<height; y++) {
          for (unsigned int x=0; x<width; x++) {
            for (unsigned int c=0; c<nbchans; c++) {
                pixel_type pixel= (fgetc(fp) << 8);
                pixel += fgetc(fp);
                if (pixel > (int)maxval) {
                    fclose(fp);
                    e_printf("Invalid PNM/PAM file: value %i is larger than declared maxval %u\n", pixel, maxval);
                    return Image();
                }
                image.channel[c].value(y,x) = pixel;
            }
          }
        }
      } else {
        for (unsigned int y=0; y<height; y++) {
          for (unsigned int x=0; x<width; x++) {
            for (unsigned int c=0; c<nbchans; c++) {
                image.channel[c].value(y,x) = fgetc(fp);
            }
          }
        }
      }
    }
    if (fp != stdin) fclose(fp);
    return image;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x76ca(%rip), %rsi      # 0x26a59
movq %r15, %rdi
callq 0x33e0
testl %eax, %eax
je 0x1f3af
leaq 0x76cf(%rip), %rsi      # 0x26a71
movq %r15, %rdi
callq 0x3370
movq %rax, %r14
jmp 0x1f3b9
movq 0x10c1a(%rip), %rax     # 0x2ffd0
movq (%rax), %r14
testq %r14, %r14
je 0x1f46b
xorl %eax, %eax
movl %eax, (%rsp)
movl %eax, 0x4(%rsp)
movl %eax, 0xc(%rsp)
movl %eax, 0x8(%rsp)
leaq 0xf0(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdx
callq 0x34e0
testq %rax, %rax
je 0x1f420
leaq 0xf0(%rsp), %r15
movzbl 0xf0(%rsp), %ecx
cmpl $0x23, %ecx
je 0x1f40b
cmpl $0xa, %ecx
jne 0x1f4d9
movq %r15, %rdi
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdx
callq 0x34e0
testq %rax, %rax
jne 0x1f3f5
movq %rax, 0x18(%rsp)
movq %r14, %rdi
callq 0x32a0
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movups %xmm0, 0x10(%rbx)
movups %xmm0, 0x20(%rbx)
xorl %eax, %eax
movq %rax, 0x30(%rbx)
movabsq $0xa00000001, %rcx      # imm = 0xA00000001
movq %rcx, 0x38(%rbx)
movups %xmm0, 0x40(%rbx)
movups %xmm0, 0x50(%rbx)
movl $0xff, 0x60(%rbx)
movups %xmm0, 0x78(%rbx)
movq %rax, 0x88(%rbx)
jmp 0x1f4b9
leaq 0x7d91(%rip), %rdi      # 0x27203
xorl %r14d, %r14d
movq %r15, %rsi
xorl %eax, %eax
callq 0x3796
movq %r14, 0x30(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rbx)
movups %xmm0, 0x10(%rbx)
movups %xmm0, (%rbx)
movabsq $0xa00000001, %rax      # imm = 0xA00000001
movq %rax, 0x38(%rbx)
movups %xmm0, 0x40(%rbx)
movups %xmm0, 0x50(%rbx)
movl $0xff, 0x60(%rbx)
movups %xmm0, 0x78(%rbx)
movq %r14, 0x88(%rbx)
movups %xmm0, 0x64(%rbx)
movb $0x1, 0xa8(%rbx)
movq %rbx, %rax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, 0x18(%rsp)
movzwl 0xf0(%rsp), %ecx
xorl %edx, %edx
cmpl $0x3450, %ecx           # imm = 0x3450
sete %dl
shll $0x2, %edx
cmpl $0x3550, %ecx           # imm = 0x3550
movl $0x5, %esi
cmovnel %edx, %esi
cmpl $0x3650, %ecx           # imm = 0x3650
movl $0x6, %edx
cmovnel %esi, %edx
cmpl $0x3750, %ecx           # imm = 0x3750
movl $0x7, %r15d
cmovnel %edx, %r15d
testl %r15d, %r15d
je 0x1f661
movzwl %cx, %ebp
addq $0x2, %rax
movq %rax, 0x18(%rsp)
leaq 0x7d49(%rip), %rsi      # 0x27285
movl $0x7, %edi
movl %r15d, %edx
xorl %eax, %eax
callq 0x1d0d6
cmpl $0x3750, %ebp           # imm = 0x3750
jne 0x1f682
movl %r15d, 0x14(%rsp)
movl $0x64, %r13d
leaq 0xf0(%rsp), %r15
movl $0x48444e45, %ebp       # imm = 0x48444E45
movq %r15, %rdi
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdx
callq 0x34e0
movq %rax, %r12
testq %rax, %rax
je 0x1f71c
movzbl 0xf0(%rsp), %eax
cmpl $0xa, %eax
je 0x1f5ff
cmpl $0x23, %eax
je 0x1f5ff
movq %r15, %rdi
leaq 0x7d2f(%rip), %rsi      # 0x272d6
movq %rsp, %rdx
xorl %eax, %eax
callq 0x3290
movq %r15, %rdi
leaq 0x7d25(%rip), %rsi      # 0x272e0
leaq 0x4(%rsp), %rdx
xorl %eax, %eax
callq 0x3290
movq %r15, %rdi
leaq 0x7d1a(%rip), %rsi      # 0x272eb
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x3290
movq %r15, %rdi
leaq 0x7d0e(%rip), %rsi      # 0x272f5
leaq 0xc(%rsp), %rdx
xorl %eax, %eax
callq 0x3290
testl %r13d, %r13d
jle 0x1f9a2
decl %r13d
movl 0xf0(%rsp), %eax
xorl %ebp, %eax
movzwl 0xf4(%rsp), %ecx
xorl $0x5244, %ecx           # imm = 0x5244
orl %eax, %ecx
jne 0x1f56f
movq %r12, 0x18(%rsp)
movl 0x8(%rsp), %eax
addl $-0x5, %eax
cmpl $-0x4, %eax
movl 0x14(%rsp), %r15d
jb 0x1f655
cmpl $0x0, (%rsp)
je 0x1f655
cmpl $0x0, 0x4(%rsp)
je 0x1f655
movl $0xffff0000, %eax       # imm = 0xFFFF0000
addl 0xc(%rsp), %eax
cmpl $0xffff0000, %eax       # imm = 0xFFFF0000
ja 0x1f744
leaq 0x7cce(%rip), %rdi      # 0x2732a
jmp 0x1f9ae
cmpb $0x50, 0xf0(%rsp)
jne 0x1f704
leaq 0x7ba6(%rip), %rdi      # 0x2721c
xorl %eax, %eax
callq 0x3796
jmp 0x1f425
leaq 0xf0(%rsp), %rsi
leaq 0x18(%rsp), %rdx
movq %r14, %rdi
callq 0x1f2ca
movl %eax, (%rsp)
testl %eax, %eax
je 0x1f6f1
leaq 0xf0(%rsp), %rsi
leaq 0x18(%rsp), %rdx
movq %r14, %rdi
callq 0x1f2ca
movl %eax, 0x4(%rsp)
testl %eax, %eax
je 0x1f6f1
cmpl $0x5, %r15d
jb 0x1f726
leaq 0xf0(%rsp), %rsi
leaq 0x18(%rsp), %rdx
movq %r14, %rdi
callq 0x1f2ca
movl %eax, 0xc(%rsp)
testl %eax, %eax
je 0x1f6f1
cmpl $0x10000, %eax          # imm = 0x10000
jb 0x1f72e
leaq 0x7bc4(%rip), %rdi      # 0x272b0
jmp 0x1f9ae
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rbx)
movups %xmm0, 0x10(%rbx)
movups %xmm0, (%rbx)
jmp 0x1f43b
leaq 0x7b55(%rip), %rsi      # 0x27260
movl $0x8, %edi
xorl %eax, %eax
callq 0x1d0d6
jmp 0x1f425
movq %r12, 0x18(%rsp)
jmp 0x1f425
movl $0x1, 0xc(%rsp)
xorl %eax, %eax
cmpl $0x3650, %ebp           # imm = 0x3650
sete %al
leal 0x1(,%rax,2), %eax
movl %eax, 0x8(%rsp)
movl (%rsp), %edx
movl 0x4(%rsp), %ecx
movl 0x8(%rsp), %r8d
movl 0xc(%rsp), %r9d
leaq 0x7c0b(%rip), %rsi      # 0x27367
movl $0x7, %edi
xorl %eax, %eax
callq 0x1d0d6
movl (%rsp), %esi
movl 0x4(%rsp), %edx
movl 0xc(%rsp), %ecx
movl 0x8(%rsp), %r8d
leaq 0x40(%rsp), %rdi
xorl %r9d, %r9d
callq 0x15138
cmpl $0x4, %r15d
jne 0x1f80f
cmpl $0x0, 0x4(%rsp)
je 0x1fa7c
xorl %r15d, %r15d
xorl %eax, %eax
cmpl $0x0, (%rsp)
je 0x1f800
xorl %r12d, %r12d
movl %r12d, %ebp
andl $0x7, %ebp
jne 0x1f7b8
movq %r14, %rdi
callq 0x34c0
movzbl %al, %edx
movl %ebp, %ecx
shll %cl, %edx
xorl %ecx, %ecx
testb %dl, %dl
setns %cl
movq 0x40(%rsp), %rdx
movl 0x18(%rdx), %esi
imull %r15d, %esi
addl %r12d, %esi
movslq %esi, %rsi
movq (%rdx), %rdi
movq 0x8(%rdx), %r8
subq %rdi, %r8
sarq %r8
addq $0x24, %rdx
cmpq %rsi, %r8
leaq (%rdi,%rsi,2), %rsi
cmovbeq %rdx, %rsi
movw %cx, (%rsi)
incl %r12d
cmpl (%rsp), %r12d
jb 0x1f7a8
incl %r15d
cmpl 0x4(%rsp), %r15d
jb 0x1f79f
jmp 0x1fa7c
cmpl $0xff, 0xc(%rsp)
movl 0x4(%rsp), %eax
jbe 0x1f9ff
testl %eax, %eax
setne %al
je 0x1fa7c
leaq 0x40(%rbx), %rcx
movq %rcx, 0x38(%rsp)
leaq 0x64(%rbx), %rcx
movq %rcx, 0x30(%rsp)
leaq 0x78(%rbx), %rcx
movq %rcx, 0x28(%rsp)
movl $0x0, 0x24(%rsp)
movb %al, 0x12(%rsp)
cmpl $0x0, (%rsp)
setne %al
je 0x1f986
movl $0x0, 0x14(%rsp)
movb %al, 0x13(%rsp)
cmpl $0x0, 0x8(%rsp)
je 0x1f963
movl $0x24, %r13d
xorl %r15d, %r15d
movq %r14, %rdi
callq 0x34c0
movl %eax, %ebp
shll $0x8, %ebp
movq %r14, %rdi
callq 0x34c0
addl %ebp, %eax
movswl %ax, %ebp
movl 0xc(%rsp), %r12d
cmpl %r12d, %ebp
jle 0x1f912
movq %r14, %rdi
callq 0x32a0
movl 0xc(%rsp), %edx
leaq 0x7aeb(%rip), %rdi      # 0x273a2
movl %ebp, %esi
xorl %eax, %eax
callq 0x3796
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rbx)
movups %xmm0, 0x10(%rbx)
movups %xmm0, (%rbx)
xorl %ecx, %ecx
movq %rcx, 0x30(%rbx)
movabsq $0xa00000001, %rax      # imm = 0xA00000001
movq %rax, 0x38(%rbx)
movq 0x38(%rsp), %rax
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movl $0xff, 0x60(%rbx)
movq 0x28(%rsp), %rax
movq %rcx, 0x10(%rax)
movups %xmm0, (%rax)
movq 0x30(%rsp), %rax
movups %xmm0, (%rax)
movb $0x1, 0xa8(%rbx)
jmp 0x1f94a
movq 0x40(%rsp), %rcx
leaq (%rcx,%r13), %rdx
movl -0xc(%rcx,%r13), %esi
imull 0x24(%rsp), %esi
addl 0x14(%rsp), %esi
movslq %esi, %rsi
movq -0x24(%rcx,%r13), %rdi
movq -0x1c(%rcx,%r13), %rcx
subq %rdi, %rcx
sarq %rcx
cmpq %rsi, %rcx
leaq (%rdi,%rsi,2), %rcx
cmovbeq %rdx, %rcx
movw %ax, (%rcx)
cmpl %r12d, %ebp
jg 0x1f97b
incq %r15
movl 0x8(%rsp), %eax
addq $0x40, %r13
cmpq %rax, %r15
jb 0x1f880
movl 0x14(%rsp), %eax
incl %eax
movl %eax, 0x14(%rsp)
cmpl (%rsp), %eax
setb %al
jb 0x1f868
jmp 0x1f986
testb $0x1, 0x13(%rsp)
jne 0x1fbb1
movl 0x24(%rsp), %eax
incl %eax
movl %eax, 0x24(%rsp)
cmpl 0x4(%rsp), %eax
setb %al
jb 0x1f84f
jmp 0x1fa7c
movq %r12, 0x18(%rsp)
leaq 0x7952(%rip), %rdi      # 0x27300
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x3796
movq %r14, %rdi
callq 0x32a0
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movups %xmm0, 0x10(%rbx)
movups %xmm0, 0x20(%rbx)
movq %r15, 0x30(%rbx)
movabsq $0xa00000001, %rax      # imm = 0xA00000001
movq %rax, 0x38(%rbx)
movups %xmm0, 0x40(%rbx)
movups %xmm0, 0x50(%rbx)
movl $0xff, 0x60(%rbx)
movups %xmm0, 0x78(%rbx)
movq %r15, 0x88(%rbx)
jmp 0x1f4b9
testl %eax, %eax
je 0x1fa7c
xorl %r15d, %r15d
cmpl $0x0, (%rsp)
je 0x1fa72
xorl %ebp, %ebp
cmpl $0x0, 0x8(%rsp)
je 0x1fa6b
movl $0x24, %r12d
xorl %r13d, %r13d
movq %r14, %rdi
callq 0x34c0
movq 0x40(%rsp), %rcx
leaq (%rcx,%r12), %rdx
movl -0xc(%rcx,%r12), %esi
imull %r15d, %esi
addl %ebp, %esi
movslq %esi, %rsi
movq -0x24(%rcx,%r12), %rdi
movq -0x1c(%rcx,%r12), %rcx
subq %rdi, %rcx
sarq %rcx
cmpq %rsi, %rcx
leaq (%rdi,%rsi,2), %rcx
cmovbeq %rdx, %rcx
movw %ax, (%rcx)
incq %r13
movl 0x8(%rsp), %eax
addq $0x40, %r12
cmpq %rax, %r13
jb 0x1fa1e
incl %ebp
cmpl (%rsp), %ebp
jb 0x1fa0e
incl %r15d
cmpl 0x4(%rsp), %r15d
jb 0x1fa06
movq 0x1054d(%rip), %rax     # 0x2ffd0
cmpq (%rax), %r14
je 0x1fa90
movq %r14, %rdi
callq 0x32a0
movaps 0x40(%rsp), %xmm0
movups %xmm0, (%rbx)
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rbx)
xorl %eax, %eax
movq %rax, 0x50(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movups 0x58(%rsp), %xmm1
movups %xmm1, 0x18(%rbx)
movq 0x68(%rsp), %rcx
movq %rcx, 0x28(%rbx)
movq %rax, 0x68(%rsp)
movups %xmm0, 0x58(%rsp)
movaps 0x70(%rsp), %xmm1
movups %xmm1, 0x30(%rbx)
movaps 0x80(%rsp), %xmm1
movups %xmm1, 0x40(%rbx)
movq 0x90(%rsp), %rcx
movq %rcx, 0x50(%rbx)
movq %rax, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movups 0x98(%rsp), %xmm1
movups 0xa4(%rsp), %xmm2
movups %xmm2, 0x64(%rbx)
movups %xmm1, 0x58(%rbx)
movups 0xb8(%rsp), %xmm1
movups %xmm1, 0x78(%rbx)
movq 0xc8(%rsp), %rcx
movq %rcx, 0x88(%rbx)
movq %rax, 0xc8(%rsp)
movups %xmm0, 0xb8(%rsp)
movups 0xd9(%rsp), %xmm0
movups %xmm0, 0x99(%rbx)
movaps 0xd0(%rsp), %xmm0
movups %xmm0, 0x90(%rbx)
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0x1fb7b
movq 0xc8(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x1fb98
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
leaq 0x58(%rsp), %rdi
callq 0xe808
leaq 0x40(%rsp), %rdi
callq 0xe220
jmp 0x1f4c4
testb $0x1, 0x12(%rsp)
je 0x1fa7c
jmp 0x1fb5e
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0xded8
movq %rbx, %rdi
callq 0x35a0