// File: cloudinary[P]fuif/transform/2dmatch.h
// Function: compute_offset(int, int&, int&)
void compute_offset(int code, int &xoffset, int &yoffset) {
    int onion_layer = 0;
    int onion_layer_size = 4;
    int ocode=code;
    while (code > onion_layer_size) { code -= onion_layer_size; onion_layer++; onion_layer_size += 4; }
    if (onion_layer & 1) {
        // odd layer: going right to left
        if (code <= onion_layer) {
            xoffset = 1 + onion_layer;  yoffset = -code;   // right vertical bottom-to-top segment
        } else if (code <= 3+3*onion_layer) {
            xoffset = 2 +2*onion_layer - code;  yoffset = -1-onion_layer;   // horizontal right-to-left segment
        } else {
            xoffset = -1 - onion_layer;  yoffset = -4 -4*onion_layer + code;    // left vertical top-to-bottom segment
        }
    } else {
        // even layer: going left to right
        if (code <= 1+onion_layer) {
            xoffset = -1 - onion_layer;  yoffset = 1-code;   // left vertical bottom-to-top segment
        } else if (code <= 4+3*onion_layer) {
            xoffset = -3 -2*onion_layer + code;  yoffset = -1-onion_layer;   // horizontal left-to-right segment
        } else {
            xoffset = 1 + onion_layer;  yoffset = -5 -4*onion_layer + code;    // right vertical top-to-bottom segment
        }
    }
}

// Assembly:
movl %edi, -0x4(%rsp)
movq %rsi, -0x10(%rsp)
movq %rdx, -0x18(%rsp)
movl $0x0, -0x1c(%rsp)
movl $0x4, -0x20(%rsp)
movl -0x4(%rsp), %eax
movl %eax, -0x24(%rsp)
movl -0x4(%rsp), %eax
cmpl -0x20(%rsp), %eax
jle 0xe096
movl -0x20(%rsp), %ecx
movl -0x4(%rsp), %eax
subl %ecx, %eax
movl %eax, -0x4(%rsp)
movl -0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rsp)
movl -0x20(%rsp), %eax
addl $0x4, %eax
movl %eax, -0x20(%rsp)
jmp 0xe066
movl -0x1c(%rsp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xe133
movl -0x4(%rsp), %eax
cmpl -0x1c(%rsp), %eax
jg 0xe0cd
movl -0x1c(%rsp), %ecx
addl $0x1, %ecx
movq -0x10(%rsp), %rax
movl %ecx, (%rax)
xorl %ecx, %ecx
subl -0x4(%rsp), %ecx
movq -0x18(%rsp), %rax
movl %ecx, (%rax)
jmp 0xe12e
movl -0x4(%rsp), %eax
imull $0x3, -0x1c(%rsp), %ecx
addl $0x3, %ecx
cmpl %ecx, %eax
jg 0xe103
movl -0x1c(%rsp), %ecx
shll %ecx
addl $0x2, %ecx
subl -0x4(%rsp), %ecx
movq -0x10(%rsp), %rax
movl %ecx, (%rax)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
subl -0x1c(%rsp), %ecx
movq -0x18(%rsp), %rax
movl %ecx, (%rax)
jmp 0xe12c
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
subl -0x1c(%rsp), %ecx
movq -0x10(%rsp), %rax
movl %ecx, (%rax)
movl -0x1c(%rsp), %eax
shll $0x2, %eax
movl $0xfffffffc, %ecx       # imm = 0xFFFFFFFC
subl %eax, %ecx
addl -0x4(%rsp), %ecx
movq -0x18(%rsp), %rax
movl %ecx, (%rax)
jmp 0xe12e
jmp 0xe1c9
movl -0x4(%rsp), %eax
movl -0x1c(%rsp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jg 0xe164
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
subl -0x1c(%rsp), %ecx
movq -0x10(%rsp), %rax
movl %ecx, (%rax)
movl $0x1, %ecx
subl -0x4(%rsp), %ecx
movq -0x18(%rsp), %rax
movl %ecx, (%rax)
jmp 0xe1c7
movl -0x4(%rsp), %eax
imull $0x3, -0x1c(%rsp), %ecx
addl $0x4, %ecx
cmpl %ecx, %eax
jg 0xe19e
movl -0x1c(%rsp), %eax
shll %eax
movl $0xfffffffd, %ecx       # imm = 0xFFFFFFFD
subl %eax, %ecx
addl -0x4(%rsp), %ecx
movq -0x10(%rsp), %rax
movl %ecx, (%rax)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
subl -0x1c(%rsp), %ecx
movq -0x18(%rsp), %rax
movl %ecx, (%rax)
jmp 0xe1c5
movl -0x1c(%rsp), %ecx
addl $0x1, %ecx
movq -0x10(%rsp), %rax
movl %ecx, (%rax)
movl -0x1c(%rsp), %eax
shll $0x2, %eax
movl $0xfffffffb, %ecx       # imm = 0xFFFFFFFB
subl %eax, %ecx
addl -0x4(%rsp), %ecx
movq -0x18(%rsp), %rax
movl %ecx, (%rax)
jmp 0xe1c7
jmp 0xe1c9
retq
nopw (%rax,%rax)