// File: /workspace/github_cpp_makefile_star2_O3/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, 0xc(%rsp)
movq %rcx, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movq %rsi, %r13
movq %rdi, (%rsp)
cmpb $0x2d, (%rsi)
jne 0x1fa4b
cmpb $0x0, 0x1(%r13)
je 0x1fd84
leaq 0x701d(%rip), %rsi      # 0x26a6f
movq %r13, %rdi
callq 0x3370
movq %rax, %r14
leaq 0x7980(%rip), %rsi      # 0x273e4
xorl %ebp, %ebp
movl $0x7, %edi
movq %r13, %rdx
movq 0x10(%rsp), %r12
movl %r12d, %ecx
movq 0x18(%rsp), %r15
movl %r15d, %r8d
movl 0xc(%rsp), %ebx
movl %ebx, %r9d
xorl %eax, %eax
callq 0x1cede
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %ebx, %ecx
shll %cl, %eax
notl %eax
movq (%rsp), %rdi
movl %r12d, %esi
movl %r15d, %edx
movl %eax, %ecx
movl $0x3, %r8d
xorl %r9d, %r9d
callq 0x150b6
testl %r15d, %r15d
jle 0x1fb64
movl 0x10(%rsp), %r12d
cmpl $0x0, 0x10(%rsp)
jle 0x1fb58
movslq %ebp, %r13
xorl %r15d, %r15d
movq %r14, %rdi
callq 0x34b0
movq (%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, 0xc(%rsp)
jl 0x1fb4c
movq %r14, %rdi
callq 0x34b0
movq (%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 0x1fad0
incl %ebp
cmpl 0x18(%rsp), %ebp
jne 0x1fabf
movq 0x10(%rsp), %rcx
leal 0x1(%rcx), %eax
shrl $0x1f, %eax
leal (%rcx,%rax), %edx
incl %edx
sarl %edx
movq 0x18(%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, 0x50(%rsp)
cmpl $0x2, %edx
movl $0x1, %eax
movl $0x1, %r13d
movl %edx, 0x28(%rsp)
cmovgel %edx, %r13d
cmpl $0x2, %ecx
movl %ecx, 0x24(%rsp)
cmovgel %ecx, %eax
movl %eax, 0x2c(%rsp)
movl $0x1, %r12d
movq (%rsp), %rax
movq (%rax), %rdi
movq %r12, 0x58(%rsp)
shlq $0x6, %r12
leaq (%rdi,%r12), %rdx
addq $0x24, %rdx
addq %r12, %rdi
movl 0x28(%rsp), %eax
movl %eax, -0xc(%rdx)
movl 0x24(%rsp), %eax
movl %eax, -0x8(%rdx)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%rdx)
movq 0x50(%rsp), %rsi
callq 0xe8d6
cmpl $0x0, 0x18(%rsp)
jle 0x1fcba
xorl %r15d, %r15d
cmpl $0x0, 0x10(%rsp)
jle 0x1fcac
movslq %r15d, %rbp
xorl %ebx, %ebx
movq %r14, %rdi
callq 0x34b0
movq (%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, 0xc(%rsp)
jl 0x1fca0
movq %r14, %rdi
callq 0x34b0
movq (%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 0x1fc1c
incl %r15d
cmpl 0x2c(%rsp), %r15d
jne 0x1fc0c
movq 0x58(%rsp), %r12
incq %r12
cmpq $0x3, %r12
jne 0x1fbbd
movq (%rsp), %rax
leaq 0x18(%rax), %r15
leaq 0x30(%rsp), %rsi
movl $0x0, (%rsi)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rsi)
movq $0x0, 0x18(%rsi)
movq %r15, %rdi
callq 0x23f60
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x1fd0d
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
leaq 0x38(%rsp), %rdi
movl $0x3, -0x8(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
leaq 0x64(%rsp), %rdx
movl $0x0, (%rdx)
xorl %esi, %esi
callq 0xf66e
leaq 0x30(%rsp), %rsi
movq %r15, %rdi
callq 0x63a0
movq 0x10283(%rip), %rax     # 0x2ffd0
cmpq (%rax), %r14
je 0x1fd5a
movq %r14, %rdi
callq 0x32a0
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x1fd71
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq (%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10245(%rip), %rax     # 0x2ffd0
movq (%rax), %r14
jmp 0x1fa5d
jmp 0x1fd97
jmp 0x1fd97
movq %rax, %r14
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x1fdb6
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
jmp 0x1fdb6
movq %rax, %r14
movq (%rsp), %rdi
callq 0xde46
movq %r14, %rdi
callq 0x3590