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

    v_printf(7,"Loading %s as a %ix%i %i-bit YUV file\n",filename,w,h,bitdepth);
    Image image(w, h, (1<<bitdepth) -1, 3);
    int shift = bitdepth-8;
    for (int y=0; y<h; y++) {
        for (int x=0; x<w; x++) {
            image.channel[0].value(y,x) = fgetc(fp);
            if (bitdepth > 8) { image.channel[0].value(y,x) += (fgetc(fp)<<8); }
        }
    }

    for (int c=1; c<3; c++) {
      image.channel[c].w = (w+1)/2;
      image.channel[c].h = (h+1)/2;
      image.channel[c].hshift = 1;
      image.channel[c].vshift = 1;
      image.channel[c].resize();
      for (int y=0; y<(h+1)/2; y++) {
        for (int x=0; x<(w+1)/2; x++) {
            image.channel[c].value(y,x) = fgetc(fp);
            if (bitdepth > 8) { image.channel[c].value(y,x) += (fgetc(fp)<<8); }
        }
      }
    }
    image.transform.push_back(Transform(TRANSFORM_YCbCr));
    Transform subsampling(TRANSFORM_ChromaSubsample);
    subsampling.parameters.push_back(0); // 4:2:0
    image.transform.push_back(subsampling);
    if (fp != stdin) fclose(fp);
    return image;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r8d, 0x14(%rsp)
movq %rcx, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movq %rsi, %r13
movq %rdi, 0x8(%rsp)
leaq 0x6e5a(%rip), %rsi      # 0x26a59
movq %r13, %rdi
callq 0x33e0
testl %eax, %eax
je 0x1fc1f
leaq 0x6e5f(%rip), %rsi      # 0x26a71
movq %r13, %rdi
callq 0x3370
movq %rax, %r14
jmp 0x1fc29
movq 0x103aa(%rip), %rax     # 0x2ffd0
movq (%rax), %r14
leaq 0x77b4(%rip), %rsi      # 0x273e4
xorl %ebp, %ebp
movl $0x7, %edi
movq %r13, %rdx
movq 0x18(%rsp), %r12
movl %r12d, %ecx
movq 0x20(%rsp), %r15
movl %r15d, %r8d
movl 0x14(%rsp), %ebx
movl %ebx, %r9d
xorl %eax, %eax
callq 0x1d0d6
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %ebx, %ecx
shll %cl, %eax
notl %eax
movq 0x8(%rsp), %rdi
movl %r12d, %esi
movl %r15d, %edx
movl %eax, %ecx
movl $0x3, %r8d
xorl %r9d, %r9d
callq 0x15138
testl %r15d, %r15d
jle 0x1fd33
movl 0x18(%rsp), %r12d
cmpl $0x0, 0x18(%rsp)
jle 0x1fd27
movslq %ebp, %r13
xorl %r15d, %r15d
movq %r14, %rdi
callq 0x34c0
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
movslq 0x18(%rcx), %rdx
imulq %r13, %rdx
addq %r15, %rdx
movq (%rcx), %rsi
movq 0x8(%rcx), %rdi
subq %rsi, %rdi
sarq %rdi
addq $0x24, %rcx
cmpq %rdx, %rdi
leaq (%rsi,%rdx,2), %rdx
cmovbeq %rcx, %rdx
movw %ax, (%rdx)
cmpl $0x9, 0x14(%rsp)
jl 0x1fd1b
movq %r14, %rdi
callq 0x34c0
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
movslq 0x18(%rcx), %rdx
imulq %r13, %rdx
addq %r15, %rdx
movq (%rcx), %rsi
movq 0x8(%rcx), %rdi
subq %rsi, %rdi
sarq %rdi
addq $0x24, %rcx
cmpq %rdx, %rdi
leaq (%rsi,%rdx,2), %rdx
cmovbeq %rcx, %rdx
shll $0x8, %eax
addw %ax, (%rdx)
incq %r15
cmpl %r15d, %r12d
jne 0x1fc9d
incl %ebp
cmpl 0x20(%rsp), %ebp
jne 0x1fc8c
movq 0x18(%rsp), %rcx
leal 0x1(%rcx), %eax
shrl $0x1f, %eax
leal (%rcx,%rax), %edx
incl %edx
sarl %edx
movq 0x20(%rsp), %rcx
leal 0x1(%rcx), %eax
shrl $0x1f, %eax
addl %eax, %ecx
incl %ecx
sarl %ecx
movl %ecx, %eax
imull %edx, %eax
cltq
movq %rax, 0x58(%rsp)
cmpl $0x2, %edx
movl $0x1, %eax
movl $0x1, %r13d
movl %edx, 0x4c(%rsp)
cmovgel %edx, %r13d
cmpl $0x2, %ecx
movl %ecx, 0x48(%rsp)
cmovgel %ecx, %eax
movl %eax, 0x50(%rsp)
movl $0x1, %r12d
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq %r12, 0x60(%rsp)
shlq $0x6, %r12
leaq (%rdi,%r12), %rdx
addq $0x24, %rdx
addq %r12, %rdi
movl 0x4c(%rsp), %eax
movl %eax, -0xc(%rdx)
movl 0x48(%rsp), %eax
movl %eax, -0x8(%rdx)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%rdx)
movq 0x58(%rsp), %rsi
callq 0xe944
cmpl $0x0, 0x20(%rsp)
jle 0x1fe8c
xorl %r15d, %r15d
cmpl $0x0, 0x18(%rsp)
jle 0x1fe7e
movslq %r15d, %rbp
xorl %ebx, %ebx
movq %r14, %rdi
callq 0x34c0
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
addq %r12, %rcx
addq $0x24, %rcx
movslq -0xc(%rcx), %rdx
imulq %rbp, %rdx
addq %rbx, %rdx
movq -0x24(%rcx), %rsi
movq -0x1c(%rcx), %rdi
subq %rsi, %rdi
sarq %rdi
cmpq %rdx, %rdi
leaq (%rsi,%rdx,2), %rdx
cmovbeq %rcx, %rdx
movw %ax, (%rdx)
cmpl $0x9, 0x14(%rsp)
jl 0x1fe72
movq %r14, %rdi
callq 0x34c0
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
addq %r12, %rcx
addq $0x24, %rcx
movslq -0xc(%rcx), %rdx
imulq %rbp, %rdx
addq %rbx, %rdx
movq -0x24(%rcx), %rsi
movq -0x1c(%rcx), %rdi
subq %rsi, %rdi
sarq %rdi
cmpq %rdx, %rdi
leaq (%rsi,%rdx,2), %rdx
cmovbeq %rcx, %rdx
shll $0x8, %eax
addw %ax, (%rdx)
incq %rbx
cmpl %ebx, %r13d
jne 0x1fdec
incl %r15d
cmpl 0x50(%rsp), %r15d
jne 0x1fddc
movq 0x60(%rsp), %r12
incq %r12
cmpq $0x3, %r12
jne 0x1fd8c
movq 0x8(%rsp), %rax
leaq 0x18(%rax), %r15
leaq 0x28(%rsp), %rsi
movl $0x0, (%rsi)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rsi)
movq $0x0, 0x18(%rsi)
movq %r15, %rdi
callq 0x241d4
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1fee0
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movl $0x3, 0x28(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
movl $0x0, 0x54(%rsp)
movq 0x38(%rsp), %rsi
testq %rsi, %rsi
je 0x1ff1c
movl $0x0, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x1ff2b
leaq 0x30(%rsp), %rdi
leaq 0x54(%rsp), %rdx
callq 0xf6da
leaq 0x28(%rsp), %rsi
movq %r15, %rdi
callq 0x63e4
movq 0x10091(%rip), %rax     # 0x2ffd0
cmpq (%rax), %r14
je 0x1ff4c
movq %r14, %rdi
callq 0x32a0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1ff63
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq 0x8(%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1ff7b
jmp 0x1ff7b
movq %rax, %r14
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1ff9a
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
jmp 0x1ff9a
movq %rax, %r14
movq 0x8(%rsp), %rdi
callq 0xded8
movq %r14, %rdi
callq 0x35a0