// File: /workspace/github_c_makefile_star2_O3/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, -0x48(%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, -0x3c(%rbp)
jge 0x351f
leaq 0x3095(%rip), %rcx      # 0x65b2
jmp 0x3594
leal (%r15,%r15), %eax
movl %eax, %ecx
imull %r8d, %ecx
cmpl %r14d, %ecx
jle 0x3537
leaq 0x3080(%rip), %rcx      # 0x65b5
jmp 0x3594
movq -0x48(%rbp), %rdx
leal (%rax,%rdx), %ecx
imull %r8d, %ecx
cmpl %r14d, %ecx
jle 0x3550
leaq 0x306a(%rip), %rcx      # 0x65b8
jmp 0x3594
leal (%rax,%rdx,2), %eax
imull %r8d, %eax
cmpl %r14d, %eax
jle 0x3565
leaq 0x3058(%rip), %rcx      # 0x65bb
jmp 0x3594
movl %r15d, %ecx
imull %edx, %ecx
addl %eax, %ecx
cmpl %r14d, %ecx
jle 0x357b
leaq 0x3045(%rip), %rcx      # 0x65be
jmp 0x3594
leal (%rdx,%rdx), %ecx
imull %r15d, %ecx
addl %ecx, %eax
cmpl %r14d, %eax
jle 0x38ea
leaq 0x302d(%rip), %rcx      # 0x65c1
leaq -0x68(%rbp), %rdi
movl $0x2, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x2210
leaq 0x3004(%rip), %rsi      # 0x65b2
leaq -0x68(%rbp), %rdi
callq 0x2050
testl %eax, %eax
je 0x3695
leaq 0x2fef(%rip), %rsi      # 0x65b5
leaq -0x68(%rbp), %rdi
callq 0x2050
testl %eax, %eax
je 0x36d6
leaq 0x2fda(%rip), %rsi      # 0x65b8
leaq -0x68(%rbp), %rdi
callq 0x2050
testl %eax, %eax
je 0x3711
leaq 0x2fc5(%rip), %rsi      # 0x65bb
leaq -0x68(%rbp), %rdi
callq 0x2050
testl %eax, %eax
movq -0x48(%rbp), %r13
je 0x380d
leaq 0x2fac(%rip), %rsi      # 0x65be
leaq -0x68(%rbp), %rdi
callq 0x2050
testl %eax, %eax
movl -0x3c(%rbp), %r12d
je 0x3858
leaq 0x2f93(%rip), %rsi      # 0x65c1
leaq -0x68(%rbp), %rdi
callq 0x2050
testl %eax, %eax
jne 0x3899
leal (%r15,%r13), %eax
movl %r15d, %ecx
imull %r13d, %ecx
imull %r12d, %eax
addl %eax, %eax
subl %ecx, %r14d
subl %eax, %r14d
movl %r14d, %eax
cltd
idivl %r15d
leal 0x1(%r13), %ecx
incl %r15d
imull %r12d, %r15d
addl %edx, %r15d
imull %ecx, %r15d
leal (%r15,%rax), %ecx
movl %ecx, -0x38(%rbp)
leal (%r15,%rax), %r12d
incl %r12d
movl %r12d, -0x34(%rbp)
leal (%rcx,%r13), %r14d
addl $0x2, %r14d
movl %r14d, -0x30(%rbp)
leal (%rcx,%r13), %eax
incl %eax
jmp 0x36d1
movl %r14d, %eax
cltd
idivl %r15d
movq -0x48(%rbp), %rdi
leal 0x1(%rdi), %ecx
leal 0x1(%r15), %esi
imull %eax, %esi
addl %edx, %esi
leal (%r15,%rsi), %r12d
incl %r12d
imull %ecx, %esi
movl %esi, -0x38(%rbp)
imull %ecx, %r12d
movl %r12d, -0x34(%rbp)
leal (%r12,%rdi), %r14d
incl %r14d
movl %r14d, -0x30(%rbp)
leal (%rsi,%rdi), %eax
incl %eax
movl %eax, -0x2c(%rbp)
jmp 0x3752
movl %r13d, %eax
cltd
idivl %r15d
movq -0x48(%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), %r12d
incl %r12d
movl %r12d, -0x34(%rbp)
imull %ecx, %r15d
leal (%r12,%r15), %r14d
movl %r14d, -0x30(%rbp)
addl %eax, %r15d
jmp 0x374e
addl %r12d, %r12d
subl %r12d, %r14d
movl %r14d, %eax
cltd
idivl -0x3c(%rbp)
movq -0x48(%rbp), %rcx
incl %ecx
incl %r15d
imull %ecx, %r15d
imull %r15d, %edx
leal (%rdx,%rax), %ecx
movl %ecx, -0x38(%rbp)
leal (%rdx,%rax), %r12d
incl %r12d
movl %r12d, -0x34(%rbp)
leal (%r15,%rcx), %r14d
incl %r14d
movl %r14d, -0x30(%rbp)
addl %ecx, %r15d
movl %r15d, -0x2c(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
leaq -0x38(%rbp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x5764
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rax
cmpq %rax, %rsi
je 0x3788
movl %r12d, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x379c
leaq -0x34(%rbp), %rdx
movq %rbx, %rdi
callq 0x5764
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rax
cmpq %rax, %rsi
je 0x37ae
movl %r14d, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x37c2
leaq -0x30(%rbp), %rdx
movq %rbx, %rdi
callq 0x5764
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rax
cmpq %rax, %rsi
je 0x37d6
movl -0x2c(%rbp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x37e2
leaq -0x2c(%rbp), %rdx
movq %rbx, %rdi
callq 0x5764
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x37fb
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
leal (%r13,%r15,2), %eax
movl -0x3c(%rbp), %ecx
imull %ecx, %eax
subl %eax, %r14d
movl %r14d, %eax
cltd
idivl %ecx
incl %r13d
leal 0x1(%r15), %ecx
imull %ecx, %edx
addl %r15d, %edx
imull %r13d, %edx
leal (%rdx,%rax), %esi
movl %esi, -0x38(%rbp)
imull %ecx, %r13d
leal (%rsi,%r13), %r12d
movl %r12d, -0x34(%rbp)
leal (%rsi,%r13), %r14d
incl %r14d
movl %r14d, -0x30(%rbp)
addl %edx, %eax
incl %eax
jmp 0x36d1
leal (%r15,%r13), %eax
imull %r12d, %eax
addl %eax, %eax
subl %eax, %r14d
movl %r14d, %eax
cltd
idivl %r15d
leal 0x1(%r13), %ecx
imull %edx, %ecx
leal (%rcx,%rax), %edx
movl %edx, -0x38(%rbp)
leal (%rdx,%r13), %r12d
incl %r12d
movl %r12d, -0x34(%rbp)
leal (%rdx,%r13), %r14d
addl $0x2, %r14d
movl %r14d, -0x30(%rbp)
addl %ecx, %eax
incl %eax
jmp 0x36d1
movl $0x10, %edi
callq 0x20b0
movq %rax, %rbx
leaq 0x2d33(%rip), %rsi      # 0x65e0
leaq -0x88(%rbp), %rdi
leaq -0x68(%rbp), %rdx
callq 0x5625
movb $0x1, %r15b
leaq -0x88(%rbp), %rsi
movq %rbx, %rdi
callq 0x21d0
xorl %r15d, %r15d
movq 0x56ff(%rip), %rsi      # 0x8fd8
movq 0x56d8(%rip), %rdx      # 0x8fb8
movq %rbx, %rdi
callq 0x2290
jmp 0x391c
movl $0x10, %edi
callq 0x20b0
movq %rax, %rbx
leaq 0x2cc6(%rip), %rsi      # 0x65c4
movq %rax, %rdi
callq 0x22d0
movq 0x56d3(%rip), %rsi      # 0x8fe0
movq 0x56b4(%rip), %rdx      # 0x8fc8
movq %rbx, %rdi
callq 0x2290
jmp 0x3941
movq %rax, %r14
leaq -0x78(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x393a
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2160
testb %r15b, %r15b
jne 0x3944
jmp 0x396a
movq %rax, %r14
movq %rbx, %rdi
callq 0x20f0
jmp 0x396a
movq %rax, %r14
jmp 0x396a
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x396a
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x2160
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x3983
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2160
movq %r14, %rdi
callq 0x22b0