// File: /workspace/github_cpp_makefile_star2_O3/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
cmpb $0x2d, (%rsi)
jne 0x1f1cb
cmpb $0x0, 0x1(%r15)
je 0x1f2f9
leaq 0x789d(%rip), %rsi      # 0x26a6f
movq %r15, %rdi
callq 0x3370
movq %rax, %r14
testq %r14, %r14
je 0x1f28b
xorl %eax, %eax
movl %eax, 0x8(%rsp)
movl %eax, 0xc(%rsp)
movl %eax, 0x14(%rsp)
movl %eax, 0x10(%rsp)
leaq 0xf0(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdx
callq 0x34d0
testq %rax, %rax
je 0x1f245
leaq 0xf0(%rsp), %r15
movzbl 0xf0(%rsp), %ecx
cmpl $0x23, %ecx
je 0x1f230
cmpl $0xa, %ecx
jne 0x1f308
movq %r15, %rdi
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdx
callq 0x34d0
testq %rax, %rax
jne 0x1f21a
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 0x1f2d9
leaq 0x7f71(%rip), %rdi      # 0x27203
xorl %r14d, %r14d
movq %r15, %rsi
xorl %eax, %eax
callq 0x379e
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 0x10cd0(%rip), %rax     # 0x2ffd0
movq (%rax), %r14
jmp 0x1f1dd
movzwl 0xf0(%rsp), %r15d
xorl %ecx, %ecx
cmpl $0x3450, %r15d          # imm = 0x3450
sete %cl
shll $0x2, %ecx
cmpl $0x3550, %r15d          # imm = 0x3550
movl $0x5, %edx
cmovnel %ecx, %edx
cmpl $0x3650, %r15d          # imm = 0x3650
movl $0x6, %ecx
cmovnel %edx, %ecx
cmpl $0x3750, %r15d          # imm = 0x3750
movl $0x7, %ebp
cmovnel %ecx, %ebp
testl %ebp, %ebp
je 0x1f499
addq $0x2, %rax
movq %rax, 0x20(%rsp)
leaq 0x7f20(%rip), %rsi      # 0x27285
movl $0x7, %edi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1cede
cmpl $0x3750, %r15d          # imm = 0x3750
jne 0x1f4b6
movl $0x64, %r12d
leaq 0xf0(%rsp), %r15
movl $0x48444e45, %r13d      # imm = 0x48444E45
movq %r15, %rdi
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdx
callq 0x34d0
testq %rax, %rax
je 0x1f245
movzbl 0xf0(%rsp), %eax
cmpl $0xa, %eax
je 0x1f423
cmpl $0x23, %eax
je 0x1f423
movq %r15, %rdi
leaq 0x7f0d(%rip), %rsi      # 0x272d6
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x3290
movq %r15, %rdi
leaq 0x7f01(%rip), %rsi      # 0x272e0
leaq 0xc(%rsp), %rdx
xorl %eax, %eax
callq 0x3290
movq %r15, %rdi
leaq 0x7ef6(%rip), %rsi      # 0x272eb
leaq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x3290
movq %r15, %rdi
leaq 0x7eea(%rip), %rsi      # 0x272f5
leaq 0x14(%rsp), %rdx
xorl %eax, %eax
callq 0x3290
testl %r12d, %r12d
jle 0x1f565
decl %r12d
movl 0xf0(%rsp), %eax
xorl %r13d, %eax
movzwl 0xf4(%rsp), %ecx
xorl $0x5244, %ecx           # imm = 0x5244
orl %eax, %ecx
jne 0x1f394
movl 0x10(%rsp), %r8d
leal -0x5(%r8), %eax
cmpl $-0x4, %eax
setb %cl
movl 0x8(%rsp), %edx
testl %edx, %edx
sete %sil
movl 0xc(%rsp), %eax
testl %eax, %eax
sete %dil
orb %sil, %dil
orb %cl, %dil
movl 0x14(%rsp), %r9d
leal -0x10000(%r9), %ecx
cmpl $0xffff0001, %ecx       # imm = 0xFFFF0001
setb %cl
orb %dil, %cl
cmpb $0x1, %cl
jne 0x1f5ee
leaq 0x7e96(%rip), %rdi      # 0x2732a
jmp 0x1f56c
cmpb $0x50, %r15b
jne 0x1f54d
leaq 0x7d72(%rip), %rdi      # 0x2721c
xorl %eax, %eax
callq 0x379e
jmp 0x1f245
leaq 0xf0(%rsp), %rsi
leaq 0x20(%rsp), %rdx
movq %r14, %rdi
callq 0x1f0fd
movl %eax, 0x8(%rsp)
testl %eax, %eax
je 0x1f53a
leaq 0xf0(%rsp), %rsi
leaq 0x20(%rsp), %rdx
movq %r14, %rdi
callq 0x1f0fd
movl %eax, 0xc(%rsp)
testl %eax, %eax
je 0x1f53a
cmpl $0x3650, %r15d          # imm = 0x3650
je 0x1f506
cmpl $0x3550, %r15d          # imm = 0x3550
jne 0x1f5bd
leaq 0xf0(%rsp), %rsi
leaq 0x20(%rsp), %rdx
movq %r14, %rdi
callq 0x1f0fd
movl %eax, 0x14(%rsp)
testl %eax, %eax
je 0x1f53a
movl %eax, %r9d
cmpl $0xffff, %eax           # imm = 0xFFFF
jbe 0x1f5cd
leaq 0x7d78(%rip), %rdi      # 0x272b0
jmp 0x1f56c
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rbx)
movups %xmm0, 0x10(%rbx)
movups %xmm0, (%rbx)
jmp 0x1f25b
leaq 0x7d0c(%rip), %rsi      # 0x27260
movl $0x8, %edi
xorl %eax, %eax
callq 0x1cede
jmp 0x1f245
leaq 0x7d94(%rip), %rdi      # 0x27300
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x379e
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 0x1f2d9
movl $0x1, 0x14(%rsp)
movl $0x1, %r9d
jmp 0x1f5d1
movl 0xc(%rsp), %eax
xorl %ecx, %ecx
cmpl $0x3650, %r15d          # imm = 0x3650
sete %cl
leal 0x1(,%rcx,2), %r8d
movl %r8d, 0x10(%rsp)
movl 0x8(%rsp), %edx
leaq 0x7d72(%rip), %rsi      # 0x27367
movl $0x7, %edi
movl %eax, %ecx
xorl %eax, %eax
callq 0x1cede
movl 0x8(%rsp), %esi
movl 0xc(%rsp), %edx
movl 0x14(%rsp), %ecx
movl 0x10(%rsp), %r8d
leaq 0x40(%rsp), %rdi
xorl %r9d, %r9d
callq 0x150b6
cmpl $0x4, %ebp
jne 0x1f6bb
movl 0xc(%rsp), %ecx
testl %ecx, %ecx
je 0x1f858
xorl %r15d, %r15d
movl 0x8(%rsp), %edx
movl %edx, %esi
xorl %eax, %eax
testl %esi, %esi
je 0x1f6ac
xorl %r12d, %r12d
movl %r12d, %ebp
andl $0x7, %ebp
jne 0x1f65c
movq %r14, %rdi
callq 0x34b0
movl 0x8(%rsp), %edx
movzbl %al, %esi
movl %ebp, %ecx
shll %cl, %esi
xorl %ecx, %ecx
testb %sil, %sil
setns %cl
movq 0x40(%rsp), %rsi
movl 0x18(%rsi), %edi
imull %r15d, %edi
addl %r12d, %edi
movslq %edi, %rdi
movq (%rsi), %r8
movq 0x8(%rsi), %r9
subq %r8, %r9
sarq %r9
addq $0x24, %rsi
cmpq %rdi, %r9
leaq (%r8,%rdi,2), %rdi
cmovbeq %rsi, %rdi
movw %cx, (%rdi)
incl %r12d
cmpl %edx, %r12d
jb 0x1f648
movl 0xc(%rsp), %ecx
movl %edx, %esi
jmp 0x1f6ae
xorl %esi, %esi
incl %r15d
cmpl %ecx, %r15d
jb 0x1f641
jmp 0x1f858
cmpl $0xff, 0x14(%rsp)
movl 0xc(%rsp), %eax
jbe 0x1f7be
testl %eax, %eax
je 0x1f858
leaq 0x40(%rbx), %rcx
movq %rcx, 0x28(%rsp)
leaq 0x64(%rbx), %rcx
movq %rcx, 0x38(%rsp)
leaq 0x78(%rbx), %rcx
movq %rcx, 0x30(%rsp)
movq $0x0, 0x18(%rsp)
movl 0x8(%rsp), %ecx
movl %ecx, %edx
testl %edx, %edx
je 0x1f7a3
xorl %r12d, %r12d
movl 0x10(%rsp), %eax
testl %eax, %eax
movl $0x0, %eax
je 0x1f78f
movl $0x24, %r13d
xorl %r15d, %r15d
movq %r14, %rdi
callq 0x34b0
movl %eax, %ebp
shll $0x8, %ebp
movq %r14, %rdi
callq 0x34b0
addl %ebp, %eax
movswl %ax, %ebp
cmpl 0x14(%rsp), %ebp
jg 0x1f970
movq 0x40(%rsp), %rcx
leaq (%rcx,%r13), %rdx
movl -0xc(%rcx,%r13), %esi
imull 0x18(%rsp), %esi
addl %r12d, %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)
incq %r15
movl 0x10(%rsp), %eax
addq $0x40, %r13
cmpq %rax, %r15
jb 0x1f720
movl 0x8(%rsp), %ecx
incl %r12d
cmpl %ecx, %r12d
jb 0x1f70e
movl 0xc(%rsp), %eax
movl %ecx, %edx
jmp 0x1f7a5
xorl %edx, %edx
movq 0x18(%rsp), %rsi
incl %esi
movq %rsi, 0x18(%rsp)
cmpl %eax, %esi
jb 0x1f6ff
jmp 0x1f858
testl %eax, %eax
je 0x1f858
xorl %r15d, %r15d
movl 0x8(%rsp), %ecx
movl %ecx, %edx
testl %edx, %edx
je 0x1f84a
xorl %ebp, %ebp
movl 0x10(%rsp), %eax
testl %eax, %eax
movl $0x0, %eax
je 0x1f83c
movl $0x24, %r12d
xorl %r13d, %r13d
movq %r14, %rdi
callq 0x34b0
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 0x10(%rsp), %eax
addq $0x40, %r12
cmpq %rax, %r13
jb 0x1f7eb
movl 0x8(%rsp), %ecx
incl %ebp
cmpl %ecx, %ebp
jb 0x1f7d9
movl 0xc(%rsp), %eax
movl %ecx, %edx
jmp 0x1f84c
xorl %edx, %edx
incl %r15d
cmpl %eax, %r15d
jb 0x1f7cf
movq 0x10771(%rip), %rax     # 0x2ffd0
cmpq (%rax), %r14
je 0x1f86c
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 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x1f957
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
leaq 0x58(%rsp), %rdi
callq 0xe794
leaq 0x40(%rsp), %rdi
callq 0xe188
jmp 0x1f2e4
movq %r14, %rdi
callq 0x32a0
movl 0x14(%rsp), %edx
leaq 0x7a1f(%rip), %rdi      # 0x273a2
movl %ebp, %esi
xorl %eax, %eax
callq 0x379e
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rbx)
movups %xmm0, 0x10(%rbx)
movups %xmm0, (%rbx)
xorl %eax, %eax
movq %rax, 0x30(%rbx)
movabsq $0xa00000001, %rcx      # imm = 0xA00000001
movq %rcx, 0x38(%rbx)
movq 0x28(%rsp), %rcx
movups %xmm0, 0x10(%rcx)
movups %xmm0, (%rcx)
movl $0xff, 0x60(%rbx)
movq 0x30(%rsp), %rcx
movq %rax, 0x10(%rcx)
movups %xmm0, (%rcx)
movq 0x38(%rsp), %rax
movups %xmm0, (%rax)
movb $0x1, 0xa8(%rbx)
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0x1f93a
movq 0xc8(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
jmp 0x1f93a
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0xde46
movq %rbx, %rdi
callq 0x3590