// File: /workspace/github_c_makefile_star2_O1/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 0x738cd(%rip), %rax     # 0x1a8dd0
movq (%rax), %rsi
leaq 0x28(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0xe0431
movq 0x18(%rsp), %r15
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x114bbb
movabsq $-0x503db0e6e1c2e704, %rsi # imm = 0xAFC24F191E3D18FC
movq %r15, 0x8(%rsp)
movq %r15, %rdi
movq %rax, %rdx
callq 0xe0582
movq %rax, %r12
movq (%r14), %r15
leaq 0x7477e(%rip), %rdx     # 0x1a9cc8
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 0x1355a3
movq 0x10(%rax), %rdx
movl $0x18, %ecx
cmpq %r15, %rdx
je 0x1355a3
movq 0x20(%rax), %rdx
movl $0x28, %ecx
cmpq %r15, %rdx
je 0x1355a3
movq 0x30(%rax), %rdx
movl $0x38, %ecx
cmpq %r15, %rdx
jne 0x1356cc
movq (%rax,%rcx), %r13
testq %r13, %r13
jne 0x1355d3
movabsq $-0x7e8ee9b9b4bbaa8, %rdi # imm = 0xF817116464B44558
movq %r15, %rsi
callq 0xf3f85
movq %rax, %r13
leaq 0x74700(%rip), %rdi     # 0x1a9cc8
movq %r15, %rsi
movq %rax, %rdx
callq 0x12128c
cmpq $0x0, 0x40(%r13)
jne 0x1355e9
movq %r13, %rdi
leaq 0xf92d(%rip), %rsi      # 0x144f11
callq 0xf592c
movq %r14, %rdi
callq *0x40(%r13)
testb %al, %al
jne 0x1356d9
movq (%r14), %r15
leaq 0x746c6(%rip), %rdx     # 0x1a9cc8
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 0x135657
movq 0x10(%rax), %rdx
movl $0x18, %ecx
cmpq %r15, %rdx
je 0x135657
movq 0x20(%rax), %rdx
movl $0x28, %ecx
cmpq %r15, %rdx
je 0x135657
movq 0x30(%rax), %rdx
movl $0x38, %ecx
cmpq %r15, %rdx
jne 0x1356d4
movq (%rax,%rcx), %r13
testq %r13, %r13
jne 0x135687
movabsq $-0x7e8ee9b9b4bbaa8, %rdi # imm = 0xF817116464B44558
movq %r15, %rsi
callq 0xf3f85
movq %rax, %r13
leaq 0x7464c(%rip), %rdi     # 0x1a9cc8
movq %r15, %rsi
movq %rax, %rdx
callq 0x12128c
movb $0x0, 0x10(%rsp)
movl $0x1, %edx
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
callq *0x10(%r13)
movsbl 0x10(%rsp), %r15d
movq %r12, %rdi
movl %r15d, %esi
callq 0x115381
leaq 0x1(%rbp), %rax
cmpl $0xa, %r15d
cmoveq %rax, %rbp
jne 0x135540
cmpq $0x3, %rax
jne 0x135540
jmp 0x1356d9
xorl %r13d, %r13d
jmp 0x1355a7
xorl %r13d, %r13d
jmp 0x13565b
movq %r12, %rdi
xorl %r12d, %r12d
leaq 0x10(%rsp), %r15
movq %r12, (%r15)
leaq 0x20(%rsp), %r13
movq %r12, (%r13)
callq 0xee7cd
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0xe081c
leaq 0x247d5(%rip), %rsi     # 0x159ede
movq %rax, %rdi
movq %r13, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x10ad37
movq (%r15), %rsi
movq (%r13), %rdx
movq %rbx, %rdi
callq 0x13514f
cmpq %r12, 0x10(%rbx)
je 0x1358a7
xorl %ebp, %ebp
xorl %eax, %eax
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x18(%rbx)
je 0x135891
xorl %r12d, %r12d
movq (%r14), %r13
leaq 0x74575(%rip), %rdx     # 0x1a9cc8
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 0x1357ac
movq 0x10(%rax), %rdx
movl $0x18, %ecx
cmpq %r13, %rdx
je 0x1357ac
movq 0x20(%rax), %rdx
movl $0x28, %ecx
cmpq %r13, %rdx
je 0x1357ac
movq 0x30(%rax), %rdx
movl $0x38, %ecx
cmpq %r13, %rdx
jne 0x135889
movq (%rax,%rcx), %r15
testq %r15, %r15
jne 0x1357dc
movabsq $-0x7e8ee9b9b4bbaa8, %rdi # imm = 0xF817116464B44558
movq %r13, %rsi
callq 0xf3f85
movq %rax, %r15
leaq 0x744f7(%rip), %rdi     # 0x1a9cc8
movq %r13, %rsi
movq %rax, %rdx
callq 0x12128c
cmpq $0x0, 0x10(%r15)
jne 0x1357f2
movq %r15, %rdi
leaq 0xf731(%rip), %rsi      # 0x144f1e
callq 0xf592c
movl $0x3, %edx
movq %r14, %rdi
leaq 0x5(%rsp), %rsi
callq *0x10(%r15)
movq 0x8(%rbx), %rdi
movabsq $-0x59225ce9298deaed, %rax # imm = 0xA6DDA316D6721513
cmpq %rax, %rdi
jne 0x135830
movzbl 0x5(%rsp), %eax
shll $0x10, %eax
movzwl 0x6(%rsp), %ecx
rolw $0x8, %cx
movzwl %cx, %r15d
orl %eax, %r15d
jmp 0x13586a
callq 0xe0cbc
testq %rax, %rax
leaq 0x1deb0(%rip), %rcx     # 0x1536ef
cmoveq %rcx, %rax
xorl %r15d, %r15d
leaq 0x246ec(%rip), %rdi     # 0x159f39
leaq 0x246be(%rip), %rsi     # 0x159f12
movl $0x58, %edx
leaq 0x246c0(%rip), %rcx     # 0x159f20
movq %rax, %r8
xorl %eax, %eax
callq 0xc825d
movq 0x20(%rbx), %rax
imulq %rbp, %rax
addq 0x28(%rbx), %rax
movl %r15d, (%rax,%r12,4)
incq %r12
cmpq 0x18(%rbx), %r12
jb 0x135749
jmp 0x135891
xorl %r15d, %r15d
jmp 0x1357b0
movq 0x8(%rsp), %rax
incq %rax
addq $0x4, %rbp
cmpq 0x10(%rbx), %rax
jb 0x135736
leaq 0x18(%rsp), %rdi
callq 0xe0b11
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq