// File: /workspace/github_c_makefile_star2_O2/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 0x707b7(%rip), %rax     # 0x117dd0
movq (%rax), %rsi
leaq 0x28(%rsp), %r15
movq %r15, 0x18(%rsp)
movq %r15, %rdi
callq 0x717f5
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x8eb65
movabsq $-0x503db0e6e1c2e704, %rsi # imm = 0xAFC24F191E3D18FC
movq %r15, %rdi
movq %rax, %rdx
callq 0x71917
movq %rax, %r15
pushq $0x1
popq %rbp
movq (%r14), %rdi
callq 0xa7b58
movq %rax, %r12
movq 0x40(%rax), %rax
testq %rax, %rax
jne 0xa767b
movq %r12, %rdi
leaq 0xfb5e(%rip), %rsi      # 0xb71cf
callq 0x7ac00
movq 0x40(%r12), %rax
movq %r14, %rdi
callq *%rax
testb %al, %al
jne 0xa76c4
movq (%r14), %rdi
callq 0xa7b58
movb $0x0, 0x10(%rsp)
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
movq %rbp, %rdx
callq *0x10(%rax)
movsbl 0x10(%rsp), %r12d
movq %r15, %rdi
movl %r12d, %esi
callq 0x8f0ee
leaq 0x1(%r13), %rax
cmpl $0xa, %r12d
cmoveq %rax, %r13
jne 0xa7653
cmpq $0x3, %rax
jne 0xa7653
leaq 0x10(%rsp), %r12
andq $0x0, (%r12)
leaq 0x20(%rsp), %r13
andq $0x0, (%r13)
movq %r15, %rdi
callq 0x76c69
leaq 0x28(%rsp), %rdi
movq %rax, %rsi
callq 0x71a4d
leaq 0x258e3(%rip), %rsi     # 0xccfd7
xorl %r15d, %r15d
movq %rax, %rdi
movq %r13, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x88fce
movq (%r12), %rsi
movq (%r13), %rdx
movq %rbx, %rdi
callq 0xa73b8
pushq $0x3
popq %rbp
cmpq 0x10(%rbx), %r15
jae 0xa7786
xorl %r12d, %r12d
cmpq 0x18(%rbx), %r12
jae 0xa7781
movq (%r14), %rdi
callq 0xa7b58
movq %rax, %r13
movq 0x10(%rax), %rax
testq %rax, %rax
jne 0xa7750
movq %r13, %rdi
leaq 0xfa95(%rip), %rsi      # 0xb71dc
callq 0x7ac00
movq 0x10(%r13), %rax
movq %r14, %rdi
leaq 0xd(%rsp), %rsi
movq %rbp, %rdx
callq *%rax
movzbl 0xd(%rsp), %ecx
movzbl 0xe(%rsp), %r8d
movzbl 0xf(%rsp), %r9d
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xa77a2
incq %r12
jmp 0xa7723
incq %r15
jmp 0xa771a
leaq 0x18(%rsp), %rdi
callq 0x71b48
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq