// File: /workspace/github_c_makefile_star2_O3/johsteffens[P]beth/lib/bcore/bcore_img.c
// Function: bcore_img_u2_s_pnm_from_source
bcore_img_u2_s* bcore_img_u2_s_pnm_from_source( bcore_img_u2_s* o, bcore_source* source )
{
    BLM_INIT();

    // We avoid source-parse functions so that source can stay a mere data buffer.
    // Instead we scan the first text lines into a string:
    st_s* first_three_lines = BLM_CREATE( st_s );
    sz_t count = 0;
    while( !bcore_source_a_eos( source ) )
    {
        char c = bcore_source_a_get_char( source );
        st_s_push_char( first_three_lines, c );
        if( c == '\n' )
        {
            count++;
            if( count == 3 ) break;
        }
    }

    uz_t rows = 0, cols = 0;

    bcore_source_a_parse_fa
    (
        BLM_A_PUSH( bcore_source_string_s_create_from_string( first_three_lines ) ),
        "P6 #<uz_t*> #<uz_t*> 255\n",
        &cols,
        &rows
    );

    bcore_img_u2_s_set_size( o, rows, cols );

    for( sz_t i = 0; i < o->rows; i++ )
    {
        for( sz_t j = 0; j < o->cols; j++ )
        {
            u0_t rgb[ 3 ];
            bcore_source_a_get_data( source, rgb, 3 );
            bcore_img_u2_s_set_rgb( o, i, j, rgb[ 0 ], rgb[ 1 ], rgb[ 2 ] );
        }
    }

    BLM_DOWN();
    return o;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x71e05(%rip), %rax     # 0x19bdd0
movq (%rax), %rsi
leaq 0x28(%rsp), %r15
movq %r15, 0x18(%rsp)
movq %r15, %rdi
callq 0xd6675
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x109c82
movabsq $-0x503db0e6e1c2e704, %rsi # imm = 0xAFC24F191E3D18FC
movq %r15, %rdi
movq %rax, %rdx
callq 0xd67bd
movq %rax, %r12
movq (%r14), %r15
leaq 0x72cbc(%rip), %rdx     # 0x19ccc8
movl (%rdx), %eax
cltq
leaq (%rax,%rax,2), %rax
movq 0x20(%rdx,%rax,8), %rcx
movq 0x18(%rdx,%rax,8), %rdx
andq %r15, %rdx
shlq $0x4, %rdx
leaq (%rcx,%rdx), %rax
movq (%rcx,%rdx), %rdx
movl $0x8, %ecx
cmpq %r15, %rdx
je 0x12a061
movq 0x10(%rax), %rdx
movl $0x18, %ecx
cmpq %r15, %rdx
je 0x12a061
movq 0x20(%rax), %rdx
movl $0x28, %ecx
cmpq %r15, %rdx
je 0x12a061
movq 0x30(%rax), %rdx
movl $0x38, %ecx
cmpq %r15, %rdx
jne 0x12a06a
movq (%rax,%rcx), %rbp
testq %rbp, %rbp
jne 0x12a091
movabsq $-0x7e8ee9b9b4bbaa8, %rdi # imm = 0xF817116464B44558
movq %r15, %rsi
callq 0xe9bc5
movq %rax, %rbp
leaq 0x72c42(%rip), %rdi     # 0x19ccc8
movq %r15, %rsi
movq %rax, %rdx
callq 0x115fac
movq 0x40(%rbp), %rax
testq %rax, %rax
jne 0x12a0ad
movq %rbp, %rdi
leaq 0xfce5(%rip), %rsi      # 0x139d89
callq 0xeb49c
movq 0x40(%rbp), %rax
movq %r14, %rdi
callq *%rax
testb %al, %al
jne 0x12a18b
movq (%r14), %r15
leaq 0x72c04(%rip), %rdx     # 0x19ccc8
movl (%rdx), %eax
cltq
leaq (%rax,%rax,2), %rax
movq 0x20(%rdx,%rax,8), %rcx
movq 0x18(%rdx,%rax,8), %rdx
andq %r15, %rdx
shlq $0x4, %rdx
leaq (%rcx,%rdx), %rax
movq (%rcx,%rdx), %rdx
movl $0x8, %ecx
cmpq %r15, %rdx
je 0x12a119
movq 0x10(%rax), %rdx
movl $0x18, %ecx
cmpq %r15, %rdx
je 0x12a119
movq 0x20(%rax), %rdx
movl $0x28, %ecx
cmpq %r15, %rdx
je 0x12a119
movq 0x30(%rax), %rdx
movl $0x38, %ecx
cmpq %r15, %rdx
jne 0x12a122
movq (%rax,%rcx), %rbp
testq %rbp, %rbp
jne 0x12a149
movabsq $-0x7e8ee9b9b4bbaa8, %rdi # imm = 0xF817116464B44558
movq %r15, %rsi
callq 0xe9bc5
movq %rax, %rbp
leaq 0x72b8a(%rip), %rdi     # 0x19ccc8
movq %r15, %rsi
movq %rax, %rdx
callq 0x115fac
movq 0x10(%rbp), %rax
movb $0x0, 0x8(%rsp)
movl $0x1, %edx
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq *%rax
movsbl 0x8(%rsp), %ebp
movq %r12, %rdi
movl %ebp, %esi
callq 0x10a448
leaq 0x1(%r13), %rax
cmpl $0xa, %ebp
cmoveq %rax, %r13
jne 0x12a002
cmpq $0x3, %rax
jne 0x12a002
xorl %eax, %eax
leaq 0x8(%rsp), %r15
movq %rax, (%r15)
leaq 0x20(%rsp), %rbp
movq %rax, (%rbp)
movq %r12, %rdi
callq 0xe4653
leaq 0x28(%rsp), %rdi
movq %rax, %rsi
callq 0xd6a3c
leaq 0x24d84(%rip), %rsi     # 0x14ef3e
movq %rax, %rdi
movq %rbp, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x100150
movq (%r15), %rsi
movq (%rbp), %rdx
movq %rbx, %rdi
callq 0x129c1e
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0x12a35d
movq 0x18(%rbx), %rcx
xorl %ebp, %ebp
xorl %edx, %edx
testq %rcx, %rcx
je 0x12a34b
movq %rdx, 0x10(%rsp)
xorl %r12d, %r12d
movq (%r14), %r13
leaq 0x72abf(%rip), %rdx     # 0x19ccc8
movl (%rdx), %eax
cltq
leaq (%rax,%rax,2), %rax
movq 0x20(%rdx,%rax,8), %rcx
movq 0x18(%rdx,%rax,8), %rdx
andq %r13, %rdx
shlq $0x4, %rdx
leaq (%rcx,%rdx), %rax
movq (%rcx,%rdx), %rdx
movl $0x8, %ecx
cmpq %r13, %rdx
je 0x12a25e
movq 0x10(%rax), %rdx
movl $0x18, %ecx
cmpq %r13, %rdx
je 0x12a25e
movq 0x20(%rax), %rdx
movl $0x28, %ecx
cmpq %r13, %rdx
je 0x12a25e
movq 0x30(%rax), %rdx
movl $0x38, %ecx
cmpq %r13, %rdx
jne 0x12a267
movq (%rax,%rcx), %r15
testq %r15, %r15
jne 0x12a28e
movabsq $-0x7e8ee9b9b4bbaa8, %rdi # imm = 0xF817116464B44558
movq %r13, %rsi
callq 0xe9bc5
movq %rax, %r15
leaq 0x72a45(%rip), %rdi     # 0x19ccc8
movq %r13, %rsi
movq %rax, %rdx
callq 0x115fac
movq 0x10(%r15), %rax
testq %rax, %rax
jne 0x12a2aa
movq %r15, %rdi
leaq 0xfaf5(%rip), %rsi      # 0x139d96
callq 0xeb49c
movq 0x10(%r15), %rax
movl $0x3, %edx
movq %r14, %rdi
leaq 0x5(%rsp), %rsi
callq *%rax
movq 0x8(%rbx), %rdi
movabsq $-0x59225ce9298deaed, %rax # imm = 0xA6DDA316D6721513
cmpq %rax, %rdi
jne 0x12a2e6
movzbl 0x5(%rsp), %eax
shll $0x10, %eax
movzwl 0x6(%rsp), %ecx
rolw $0x8, %cx
movzwl %cx, %r15d
orl %eax, %r15d
jmp 0x12a320
callq 0xd6ec4
testq %rax, %rax
leaq 0x1e420(%rip), %rcx     # 0x148715
cmoveq %rcx, %rax
xorl %r15d, %r15d
leaq 0x24c96(%rip), %rdi     # 0x14ef99
leaq 0x24c68(%rip), %rsi     # 0x14ef72
movl $0x58, %edx
leaq 0x24c6a(%rip), %rcx     # 0x14ef80
movq %rax, %r8
xorl %eax, %eax
callq 0xbe6f9
movq 0x20(%rbx), %rax
imulq %rbp, %rax
addq 0x28(%rbx), %rax
movl %r15d, (%rax,%r12,4)
incq %r12
movq 0x18(%rbx), %rcx
cmpq %rcx, %r12
jb 0x12a1ff
movq 0x10(%rbx), %rax
movq 0x10(%rsp), %rdx
jmp 0x12a34d
xorl %ecx, %ecx
incq %rdx
addq $0x4, %rbp
cmpq %rax, %rdx
jb 0x12a1ee
leaq 0x18(%rsp), %rdi
callq 0xd6d0d
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq