// File: /workspace/github_c_makefile_star2_O0/ZmengXu[P]boxMesh/boxMesh.C
// Function: ownerOfExternalFace(int, int, int, int)
int ownerOfExternalFace(int externalFaceId, int Nx, int Ny, int Nz)
{
    /* Returns owner of face nInternalFaces+externalFaceId (which is an external face) */

    /* The way to calculate the owner depends on which face of the domain it belongs to:
     * The first Ny*Nz faces have outward normal (-1, 0, 0) (referred to as x-)
     * The next  Ny*Nz faces have outward normal ( 1, 0, 0) (referred to as x+)
     * The next  Nx*Nz faces have outward normal ( 0,-1, 0) (referred to as y-)
     * The next  Nx*Nz faces have outward normal ( 0, 1, 0) (referred to as y+)
     * The next  Nx*Ny faces have outward normal ( 0, 0,-1) (referred to as z-)
     * The next  Nx*Ny faces have outward normal ( 0, 0, 1) (referred to as z+)
     * The following tests check in which face of the domain the face is. */
    string normal;
    if   (externalFaceId < Ny*Nz)
        normal = "x-";
    else if (externalFaceId < 2*Ny*Nz)
        normal = "x+";
    else if (externalFaceId < 2*Ny*Nz + Nx*Nz)
        normal = "y-";
    else if (externalFaceId < 2*Ny*Nz + 2*Nx*Nz)
        normal = "y+";
    else if (externalFaceId < 2*Ny*Nz + 2*Nx*Nz + Nx*Ny)
        normal = "z-";
    else if (externalFaceId < 2*Ny*Nz + 2*Nx*Nz + 2*Nx*Ny)
        normal = "z+";
    else
        throw invalid_argument("externalFaceId is too large");

    /* Now that the normal to the face is known, calculate the owner in the
     * respective way. */
    int temp;
    int owner;
    if (normal == "x-")
    {
        temp  = externalFaceId;     // index on "x-" face
        int zCell = int(temp/Ny);   // z-grid-coordinate of face
        int yCell = temp%Ny;        // y-grid-coordinate of face
        owner = yCell*Nx + zCell*(Nx*Ny);
    }
    else if (normal == "x+")
    {
        temp  = externalFaceId - (Ny*Nz);
        int zCell = int(temp/Ny);
        int yCell = temp%Ny;
        owner = yCell*Nx + zCell*(Nx*Ny) + (Nx-1);
    }
    else if (normal == "y-")
    {
        temp  = externalFaceId - (2*Ny*Nz);     // index on "y-" face
        int xCell = int(temp/Nz);               // x-grid-coordinate of face
        int zCell = temp%Nz;                    // z-grid-coordinate of face
        owner = xCell + zCell*(Nx*Ny);
    }
    else if (normal == "y+")
    {
        temp  = externalFaceId - (2*Ny*Nz + Nx*Nz);
        int xCell = int(temp/Nz);
        int zCell = temp%Nz;
        owner = xCell + zCell*(Nx*Ny) + Nx*(Ny-1);
    }
    else if (normal == "z-")
    {
        temp  = externalFaceId - (2*Ny*Nz + 2*Nx*Nz);   // index on "z-" face
        int xCell = int(temp/Ny);                       // x-grid-coordinate of face
        int yCell = temp%Ny;                            // y-grid-coordinate of face
        owner = xCell + yCell*Nx;
    }
    else if (normal == "z+")
    {
        temp  = externalFaceId - (2*Ny*Nz + 2*Nx*Nz + Nx*Ny);
        int xCell = int(temp/Ny);
        int yCell = temp%Ny;
        owner = xCell + yCell*Nx + Nx*Ny*(Nz-1);
    }
    else
        throw logic_error("Unexpected value for normal: " + normal);

    return owner;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
movl %ecx, -0x10(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x2280
movl -0x4(%rbp), %eax
movl -0xc(%rbp), %ecx
imull -0x10(%rbp), %ecx
cmpl %ecx, %eax
jge 0x5056
leaq 0x4561(%rip), %rsi      # 0x9596
leaq -0x30(%rbp), %rdi
callq 0x2270
jmp 0x5040
jmp 0x51bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x5523
movl -0x4(%rbp), %eax
movl -0xc(%rbp), %ecx
shll %ecx
imull -0x10(%rbp), %ecx
cmpl %ecx, %eax
jge 0x507d
leaq 0x452c(%rip), %rsi      # 0x9599
leaq -0x30(%rbp), %rdi
callq 0x2270
jmp 0x5078
jmp 0x51bd
movl -0x4(%rbp), %eax
movl -0xc(%rbp), %ecx
shll %ecx
imull -0x10(%rbp), %ecx
movl -0x8(%rbp), %edx
imull -0x10(%rbp), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jge 0x50ad
leaq 0x44ff(%rip), %rsi      # 0x959c
leaq -0x30(%rbp), %rdi
callq 0x2270
jmp 0x50a8
jmp 0x51bb
movl -0x4(%rbp), %eax
movl -0xc(%rbp), %ecx
shll %ecx
imull -0x10(%rbp), %ecx
movl -0x8(%rbp), %edx
shll %edx
imull -0x10(%rbp), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jge 0x50df
leaq 0x44d0(%rip), %rsi      # 0x959f
leaq -0x30(%rbp), %rdi
callq 0x2270
jmp 0x50da
jmp 0x51b9
movl -0x4(%rbp), %eax
movl -0xc(%rbp), %ecx
shll %ecx
imull -0x10(%rbp), %ecx
movl -0x8(%rbp), %edx
shll %edx
imull -0x10(%rbp), %edx
addl %edx, %ecx
movl -0x8(%rbp), %edx
imull -0xc(%rbp), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jge 0x511a
leaq 0x4498(%rip), %rsi      # 0x95a2
leaq -0x30(%rbp), %rdi
callq 0x2270
jmp 0x5115
jmp 0x51b7
movl -0x4(%rbp), %eax
movl -0xc(%rbp), %ecx
shll %ecx
imull -0x10(%rbp), %ecx
movl -0x8(%rbp), %edx
shll %edx
imull -0x10(%rbp), %edx
addl %edx, %ecx
movl -0x8(%rbp), %edx
shll %edx
imull -0xc(%rbp), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jge 0x5154
leaq 0x445e(%rip), %rsi      # 0x95a5
leaq -0x30(%rbp), %rdi
callq 0x2270
jmp 0x5152
jmp 0x51b5
movl $0x10, %edi
callq 0x20d0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xa8(%rbp)
leaq 0x4436(%rip), %rsi      # 0x95a8
callq 0x23a0
jmp 0x5179
movq -0xa8(%rbp), %rdi
movq 0x7e59(%rip), %rsi      # 0xcfe0
movq 0x7e3a(%rip), %rdx      # 0xcfc8
callq 0x2340
jmp 0x5535
movq -0xa8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
callq 0x2140
jmp 0x5523
jmp 0x51b7
jmp 0x51b9
jmp 0x51bb
jmp 0x51bd
jmp 0x51bf
leaq 0x43d0(%rip), %rsi      # 0x9596
leaq -0x30(%rbp), %rdi
callq 0x61f0
movb %al, -0xa9(%rbp)
jmp 0x51d7
movb -0xa9(%rbp), %al
testb $0x1, %al
jne 0x51e3
jmp 0x521b
movl -0x4(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cltd
idivl -0xc(%rbp)
movl %eax, -0x48(%rbp)
movl -0x40(%rbp), %eax
cltd
idivl -0xc(%rbp)
movl %edx, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
imull -0x8(%rbp), %eax
movl -0x48(%rbp), %ecx
movl -0x8(%rbp), %edx
imull -0xc(%rbp), %edx
imull %edx, %ecx
addl %ecx, %eax
movl %eax, -0x44(%rbp)
jmp 0x5502
leaq 0x4377(%rip), %rsi      # 0x9599
leaq -0x30(%rbp), %rdi
callq 0x61f0
movb %al, -0xaa(%rbp)
jmp 0x5233
movb -0xaa(%rbp), %al
testb $0x1, %al
jne 0x523f
jmp 0x5288
movl -0x4(%rbp), %eax
movl -0xc(%rbp), %ecx
imull -0x10(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cltd
idivl -0xc(%rbp)
movl %eax, -0x50(%rbp)
movl -0x40(%rbp), %eax
cltd
idivl -0xc(%rbp)
movl %edx, -0x54(%rbp)
movl -0x54(%rbp), %eax
imull -0x8(%rbp), %eax
movl -0x50(%rbp), %ecx
movl -0x8(%rbp), %edx
imull -0xc(%rbp), %edx
imull %edx, %ecx
addl %ecx, %eax
movl -0x8(%rbp), %ecx
subl $0x1, %ecx
addl %ecx, %eax
movl %eax, -0x44(%rbp)
jmp 0x5500
leaq 0x430d(%rip), %rsi      # 0x959c
leaq -0x30(%rbp), %rdi
callq 0x61f0
movb %al, -0xab(%rbp)
jmp 0x52a0
movb -0xab(%rbp), %al
testb $0x1, %al
jne 0x52ac
jmp 0x52eb
movl -0x4(%rbp), %eax
movl -0xc(%rbp), %ecx
shll %ecx
imull -0x10(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cltd
idivl -0x10(%rbp)
movl %eax, -0x58(%rbp)
movl -0x40(%rbp), %eax
cltd
idivl -0x10(%rbp)
movl %edx, -0x5c(%rbp)
movl -0x58(%rbp), %eax
movl -0x5c(%rbp), %ecx
movl -0x8(%rbp), %edx
imull -0xc(%rbp), %edx
imull %edx, %ecx
addl %ecx, %eax
movl %eax, -0x44(%rbp)
jmp 0x54fe
leaq 0x42ad(%rip), %rsi      # 0x959f
leaq -0x30(%rbp), %rdi
callq 0x61f0
movb %al, -0xac(%rbp)
jmp 0x5303
movb -0xac(%rbp), %al
testb $0x1, %al
jne 0x530f
jmp 0x5365
movl -0x4(%rbp), %eax
movl -0xc(%rbp), %ecx
shll %ecx
imull -0x10(%rbp), %ecx
movl -0x8(%rbp), %edx
imull -0x10(%rbp), %edx
addl %edx, %ecx
subl %ecx, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cltd
idivl -0x10(%rbp)
movl %eax, -0x60(%rbp)
movl -0x40(%rbp), %eax
cltd
idivl -0x10(%rbp)
movl %edx, -0x64(%rbp)
movl -0x60(%rbp), %eax
movl -0x64(%rbp), %ecx
movl -0x8(%rbp), %edx
imull -0xc(%rbp), %edx
imull %edx, %ecx
addl %ecx, %eax
movl -0x8(%rbp), %ecx
movl -0xc(%rbp), %edx
subl $0x1, %edx
imull %edx, %ecx
addl %ecx, %eax
movl %eax, -0x44(%rbp)
jmp 0x54fc
leaq 0x4236(%rip), %rsi      # 0x95a2
leaq -0x30(%rbp), %rdi
callq 0x61f0
movb %al, -0xad(%rbp)
jmp 0x537d
movb -0xad(%rbp), %al
testb $0x1, %al
jne 0x5389
jmp 0x53cd
movl -0x4(%rbp), %eax
movl -0xc(%rbp), %ecx
shll %ecx
imull -0x10(%rbp), %ecx
movl -0x8(%rbp), %edx
shll %edx
imull -0x10(%rbp), %edx
addl %edx, %ecx
subl %ecx, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cltd
idivl -0xc(%rbp)
movl %eax, -0x68(%rbp)
movl -0x40(%rbp), %eax
cltd
idivl -0xc(%rbp)
movl %edx, -0x6c(%rbp)
movl -0x68(%rbp), %eax
movl -0x6c(%rbp), %ecx
imull -0x8(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x44(%rbp)
jmp 0x54fa
leaq 0x41d1(%rip), %rsi      # 0x95a5
leaq -0x30(%rbp), %rdi
callq 0x61f0
movb %al, -0xae(%rbp)
jmp 0x53e5
movb -0xae(%rbp), %al
testb $0x1, %al
jne 0x53f1
jmp 0x5450
movl -0x4(%rbp), %eax
movl -0xc(%rbp), %ecx
shll %ecx
imull -0x10(%rbp), %ecx
movl -0x8(%rbp), %edx
shll %edx
imull -0x10(%rbp), %edx
addl %edx, %ecx
movl -0x8(%rbp), %edx
imull -0xc(%rbp), %edx
addl %edx, %ecx
subl %ecx, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cltd
idivl -0xc(%rbp)
movl %eax, -0x70(%rbp)
movl -0x40(%rbp), %eax
cltd
idivl -0xc(%rbp)
movl %edx, -0x74(%rbp)
movl -0x70(%rbp), %eax
movl -0x74(%rbp), %ecx
imull -0x8(%rbp), %ecx
addl %ecx, %eax
movl -0x8(%rbp), %ecx
imull -0xc(%rbp), %ecx
movl -0x10(%rbp), %edx
subl $0x1, %edx
imull %edx, %ecx
addl %ecx, %eax
movl %eax, -0x44(%rbp)
jmp 0x54f8
movb $0x1, -0x99(%rbp)
movl $0x10, %edi
callq 0x20d0
movq %rax, -0xb8(%rbp)
leaq 0x4155(%rip), %rsi      # 0x95c4
leaq -0x98(%rbp), %rdi
leaq -0x30(%rbp), %rdx
callq 0x6220
jmp 0x5481
movq -0xb8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x22b0
jmp 0x5496
movq -0xb8(%rbp), %rdi
movb $0x0, -0x99(%rbp)
movq 0x7b2d(%rip), %rsi      # 0xcfd8
movq 0x7b06(%rip), %rdx      # 0xcfb8
callq 0x2340
jmp 0x5535
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x54df
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x2100
testb $0x1, -0x99(%rbp)
jne 0x54ea
jmp 0x54f6
movq -0xb8(%rbp), %rdi
callq 0x2140
jmp 0x5523
jmp 0x54fa
jmp 0x54fc
jmp 0x54fe
jmp 0x5500
jmp 0x5502
movl -0x44(%rbp), %eax
movl %eax, -0xbc(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x2100
movl -0xbc(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0x2100
movq -0x38(%rbp), %rdi
callq 0x2370
nopw %cs:(%rax,%rax)