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

    /* The way to calculate the points 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 points in the
     * respective way. */
    int temp;
    int point_1, point_2, point_3, point_4;
    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
        point_1 = zCell*(Nx+1)*(Ny+1) + yCell*(Nx+1);
        point_2 = point_1 + (Nx+1)*(Ny+1);
        point_3 = point_2 + (Nx+1);
        point_4 = point_1 + (Nx+1);
    }
    else if (normal == "x+")
    {
        /* To get the formula for point_1, start with the formula for point_1 of face x-,
         * and replace externalFaceId by (externalFaceId-Ny*Nz), and then add Nx. */
        temp  = externalFaceId - (Ny*Nz);
        int zCell = int(temp/Ny);
        int yCell = temp%Ny;
        point_1 = zCell*(Nx+1)*(Ny+1) + yCell*(Nx+1) + Nx;
        point_2 = point_1 + (Nx+1);
        point_3 = point_2 + (Nx+1)*(Ny+1);
        point_4 = point_1 + (Nx+1)*(Ny+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
        point_1 = zCell*(Nx+1)*(Ny+1) + xCell;
        point_2 = point_1 + 1;
        point_3 = point_2 + (Nx+1)*(Ny+1);
        point_4 = point_3 -1;
    }
    else if (normal == "y+")
    {
        /* To get the formula for point_1, start with the formula for point_1 of face y-,
         * and replace externalFaceId by (externalFaceId-Nx*Nz), and then add (Nx+1)*Ny. */
        temp  = externalFaceId - (2*Ny*Nz + Nx*Nz);
        int xCell = int(temp/Nz);
        int zCell = temp%Nz;
        point_1 = zCell*(Nx+1)*(Ny+1) + xCell + (Nx+1)*Ny;
        point_2 = point_1 + (Nx+1)*(Ny+1);
        point_3 = point_2 + 1;
        point_4 = point_1 + 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
        point_1 = yCell*(Nx+1) + xCell;
        point_2 = point_1 + (Nx+1);
        point_3 = point_2 + 1;
        point_4 = point_1 + 1;
    }
    else if (normal == "z+")
    {
        /* To get the formula for point_1, start with the formula for point_1 of face z-,
         * and replace externalFaceId by (externalFaceId-Nx*Ny), and then add (Nx+1)*(Ny+1)*Nz. */
        temp  = externalFaceId - (2*Ny*Nz + 2*Nx*Nz + Nx*Ny);
        int xCell = int(temp/Ny);
        int yCell = temp%Ny;
        point_1 = yCell*(Nx+1) + xCell + (Nx+1)*(Ny+1)*Nz;
        point_2 = point_1 + 1;
        point_3 = point_2 + (Nx+1);
        point_4 = point_3 -1;
    }
    else
        throw logic_error("Unexpected value for normal: " + normal);

    Points points;
    points.push_back(point_1);
    points.push_back(point_2);
    points.push_back(point_3);
    points.push_back(point_4);

    return points;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %ecx, %r15d
movq %rdx, -0x40(%rbp)
movl %esi, %r14d
movq %rdi, %rbx
leaq -0x58(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movl %r8d, %r12d
imull %ecx, %r12d
movl %esi, %r13d
subl %r12d, %r13d
movl %r8d, -0x44(%rbp)
jge 0x34e8
leaq 0x30cc(%rip), %rcx      # 0x65b2
jmp 0x355d
leal (%r15,%r15), %eax
movl %eax, %ecx
imull %r8d, %ecx
cmpl %r14d, %ecx
jle 0x3500
leaq 0x30b7(%rip), %rcx      # 0x65b5
jmp 0x355d
movq -0x40(%rbp), %rdx
leal (%rax,%rdx), %ecx
imull %r8d, %ecx
cmpl %r14d, %ecx
jle 0x3519
leaq 0x30a1(%rip), %rcx      # 0x65b8
jmp 0x355d
leal (%rax,%rdx,2), %eax
imull %r8d, %eax
cmpl %r14d, %eax
jle 0x352e
leaq 0x308f(%rip), %rcx      # 0x65bb
jmp 0x355d
movl %r15d, %ecx
imull %edx, %ecx
addl %eax, %ecx
cmpl %r14d, %ecx
jle 0x3544
leaq 0x307c(%rip), %rcx      # 0x65be
jmp 0x355d
leal (%rdx,%rdx), %ecx
imull %r15d, %ecx
addl %ecx, %eax
cmpl %r14d, %eax
jle 0x38a4
leaq 0x3064(%rip), %rcx      # 0x65c1
leaq -0x68(%rbp), %rdi
movl $0x2, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x2210
leaq 0x303b(%rip), %rsi      # 0x65b2
leaq -0x68(%rbp), %rdi
callq 0x2050
testl %eax, %eax
je 0x365a
leaq 0x3026(%rip), %rsi      # 0x65b5
leaq -0x68(%rbp), %rdi
callq 0x2050
testl %eax, %eax
je 0x3694
leaq 0x3011(%rip), %rsi      # 0x65b8
leaq -0x68(%rbp), %rdi
callq 0x2050
testl %eax, %eax
je 0x36ca
leaq 0x2ffc(%rip), %rsi      # 0x65bb
leaq -0x68(%rbp), %rdi
callq 0x2050
testl %eax, %eax
movl -0x44(%rbp), %r13d
je 0x37d1
leaq 0x2fe3(%rip), %rsi      # 0x65be
leaq -0x68(%rbp), %rdi
callq 0x2050
testl %eax, %eax
movq -0x40(%rbp), %r12
je 0x3816
leaq 0x2fca(%rip), %rsi      # 0x65c1
leaq -0x68(%rbp), %rdi
callq 0x2050
testl %eax, %eax
jne 0x3853
leal (%r15,%r12), %eax
movl %r15d, %ecx
imull %r12d, %ecx
imull %r13d, %eax
addl %eax, %eax
subl %ecx, %r14d
subl %eax, %r14d
movl %r14d, %eax
cltd
idivl %r15d
leal 0x1(%r12), %ecx
incl %r15d
imull %r13d, %r15d
addl %edx, %r15d
imull %ecx, %r15d
leal (%r15,%rax), %ecx
movl %ecx, -0x38(%rbp)
addl %r15d, %eax
incl %eax
movl %eax, -0x34(%rbp)
leal (%r12,%rcx), %eax
addl $0x2, %eax
movl %eax, -0x30(%rbp)
leal (%r12,%rcx), %eax
incl %eax
jmp 0x368f
movl %r14d, %eax
cltd
idivl %r15d
movq -0x40(%rbp), %rdi
leal 0x1(%rdi), %ecx
leal 0x1(%r15), %esi
imull %eax, %esi
addl %edx, %esi
leal (%r15,%rsi), %eax
incl %eax
imull %ecx, %esi
movl %esi, -0x38(%rbp)
imull %ecx, %eax
movl %eax, -0x34(%rbp)
addl %edi, %eax
incl %eax
movl %eax, -0x30(%rbp)
leal (%rsi,%rdi), %eax
incl %eax
movl %eax, -0x2c(%rbp)
jmp 0x3705
movl %r13d, %eax
cltd
idivl %r15d
movq -0x40(%rbp), %rsi
leal 0x1(%rsi), %ecx
incl %r15d
imull %r15d, %eax
addl %edx, %eax
imull %ecx, %eax
addl %esi, %eax
movl %eax, -0x38(%rbp)
leal (%rsi,%rax), %edx
incl %edx
movl %edx, -0x34(%rbp)
imull %ecx, %r15d
addl %r15d, %edx
movl %edx, -0x30(%rbp)
addl %eax, %r15d
jmp 0x3701
addl %r12d, %r12d
subl %r12d, %r14d
movl %r14d, %eax
cltd
idivl -0x44(%rbp)
movq -0x40(%rbp), %rcx
incl %ecx
incl %r15d
imull %ecx, %r15d
imull %r15d, %edx
leal (%rdx,%rax), %ecx
movl %ecx, -0x38(%rbp)
addl %edx, %eax
incl %eax
movl %eax, -0x34(%rbp)
leal (%r15,%rcx), %eax
incl %eax
movl %eax, -0x30(%rbp)
addl %ecx, %r15d
movl %r15d, -0x2c(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
movq 0x8(%rbx), %rsi
testq %rsi, %rsi
je 0x372b
movl -0x38(%rbp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x3737
leaq -0x38(%rbp), %rdx
movq %rbx, %rdi
callq 0x56e0
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x3750
movl -0x34(%rbp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x375c
leaq -0x34(%rbp), %rdx
movq %rbx, %rdi
callq 0x56e0
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x3775
movl -0x30(%rbp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x3781
leaq -0x30(%rbp), %rdx
movq %rbx, %rdi
callq 0x56e0
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x379a
movl -0x2c(%rbp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x37a6
leaq -0x2c(%rbp), %rdx
movq %rbx, %rdi
callq 0x56e0
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x37bf
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2160
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x40(%rbp), %rdi
leal (%rdi,%r15,2), %eax
imull %r13d, %eax
subl %eax, %r14d
movl %r14d, %eax
cltd
idivl %r13d
incl %edi
leal 0x1(%r15), %ecx
imull %ecx, %edx
addl %r15d, %edx
imull %edi, %edx
leal (%rdx,%rax), %esi
movl %esi, -0x38(%rbp)
imull %ecx, %edi
leal (%rsi,%rdi), %ecx
movl %ecx, -0x34(%rbp)
leal (%rdi,%rsi), %ecx
incl %ecx
movl %ecx, -0x30(%rbp)
addl %edx, %eax
incl %eax
jmp 0x368f
leal (%r15,%r12), %eax
imull %r13d, %eax
addl %eax, %eax
subl %eax, %r14d
movl %r14d, %eax
cltd
idivl %r15d
leal 0x1(%r12), %ecx
imull %edx, %ecx
leal (%rcx,%rax), %edx
movl %edx, -0x38(%rbp)
leal (%r12,%rdx), %esi
incl %esi
movl %esi, -0x34(%rbp)
addl %r12d, %edx
addl $0x2, %edx
movl %edx, -0x30(%rbp)
addl %ecx, %eax
incl %eax
jmp 0x368f
movl $0x10, %edi
callq 0x20b0
movq %rax, %rbx
leaq 0x2d79(%rip), %rsi      # 0x65e0
leaq -0x88(%rbp), %rdi
leaq -0x68(%rbp), %rdx
callq 0x55a5
movb $0x1, %r15b
leaq -0x88(%rbp), %rsi
movq %rbx, %rdi
callq 0x21d0
xorl %r15d, %r15d
movq 0x5745(%rip), %rsi      # 0x8fd8
movq 0x571e(%rip), %rdx      # 0x8fb8
movq %rbx, %rdi
callq 0x2290
jmp 0x38d6
movl $0x10, %edi
callq 0x20b0
movq %rax, %rbx
leaq 0x2d0c(%rip), %rsi      # 0x65c4
movq %rax, %rdi
callq 0x22d0
movq 0x5719(%rip), %rsi      # 0x8fe0
movq 0x56fa(%rip), %rdx      # 0x8fc8
movq %rbx, %rdi
callq 0x2290
movq %rax, %r14
jmp 0x3904
movq %rax, %r14
leaq -0x78(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x38ff
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2160
jmp 0x38ff
movq %rax, %r14
movb $0x1, %r15b
testb %r15b, %r15b
je 0x392a
movq %rbx, %rdi
callq 0x20f0
jmp 0x392a
movq %rax, %r14
jmp 0x392a
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x392a
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x2160
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x3943
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2160
movq %r14, %rdi
callq 0x22b0