// File: /workspace/github_c_makefile_star2_O2/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)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movl %r8d, %r12d
imull %ecx, %r12d
movl %esi, %r13d
subl %r12d, %r13d
movl %r8d, -0x3c(%rbp)
jge 0x2fce
leaq 0x35ca(%rip), %rsi      # 0x6596
jmp 0x3044
movl %r8d, %esi
leal (%r15,%r15), %eax
movl %eax, %ecx
imull %r8d, %ecx
cmpl %r14d, %ecx
jle 0x2fe9
leaq 0x35b2(%rip), %rsi      # 0x6599
jmp 0x3044
movq -0x48(%rbp), %rdx
leal (%rax,%rdx), %ecx
imull %esi, %ecx
cmpl %r14d, %ecx
jle 0x3001
leaq 0x359d(%rip), %rsi      # 0x659c
jmp 0x3044
leal (%rax,%rdx,2), %eax
imull %esi, %eax
cmpl %r14d, %eax
jle 0x3015
leaq 0x358c(%rip), %rsi      # 0x659f
jmp 0x3044
movl %r15d, %ecx
imull %edx, %ecx
addl %eax, %ecx
cmpl %r14d, %ecx
jle 0x302b
leaq 0x3579(%rip), %rsi      # 0x65a2
jmp 0x3044
leal (%rdx,%rdx), %ecx
imull %r15d, %ecx
addl %ecx, %eax
cmpl %r14d, %eax
jle 0x32af
leaq 0x3561(%rip), %rsi      # 0x65a5
leaq -0x68(%rbp), %rdi
callq 0x22c0
leaq 0x3542(%rip), %rsi      # 0x6596
leaq -0x68(%rbp), %rdi
callq 0x497d
testb %al, %al
je 0x309e
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), %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 0x313b
leaq 0x34f4(%rip), %rsi      # 0x6599
leaq -0x68(%rbp), %rdi
callq 0x497d
testb %al, %al
je 0x30e8
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), %edx
incl %edx
movl %edx, -0x34(%rbp)
imull %ecx, %r15d
addl %r15d, %edx
movl %edx, -0x30(%rbp)
addl %eax, %r15d
jmp 0x3137
leaq 0x34ad(%rip), %rsi      # 0x659c
leaq -0x68(%rbp), %rdi
callq 0x497d
testb %al, %al
je 0x3191
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)
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)
andq $0x0, 0x10(%rbx)
leaq -0x38(%rbp), %rsi
movq %rbx, %rdi
callq 0x491c
leaq -0x34(%rbp), %rsi
movq %rbx, %rdi
callq 0x491c
leaq -0x30(%rbp), %rsi
movq %rbx, %rdi
callq 0x491c
leaq -0x2c(%rbp), %rsi
movq %rbx, %rdi
callq 0x491c
leaq -0x68(%rbp), %rdi
callq 0x20a0
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3407(%rip), %rsi      # 0x659f
leaq -0x68(%rbp), %rdi
callq 0x497d
testb %al, %al
je 0x31eb
movq -0x48(%rbp), %rdi
leal (%rdi,%r15,2), %eax
movl -0x3c(%rbp), %ecx
imull %ecx, %eax
subl %eax, %r14d
movl %r14d, %eax
cltd
idivl %ecx
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 0x3096
leaq 0x33b0(%rip), %rsi      # 0x65a2
leaq -0x68(%rbp), %rdi
callq 0x497d
testb %al, %al
movq -0x48(%rbp), %r12
je 0x3240
leal (%r15,%r12), %eax
imull -0x3c(%rbp), %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 0x3096
leaq 0x335e(%rip), %rsi      # 0x65a5
leaq -0x68(%rbp), %rdi
callq 0x497d
testb %al, %al
je 0x32e1
leal (%r15,%r12), %eax
movl %r15d, %ecx
imull %r12d, %ecx
movl -0x3c(%rbp), %esi
imull %esi, %eax
addl %eax, %eax
subl %ecx, %r14d
subl %eax, %r14d
movl %r14d, %eax
cltd
idivl %r15d
leal 0x1(%r12), %ecx
incl %r15d
imull %esi, %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 0x3096
pushq $0x10
popq %rdi
callq 0x20b0
movq %rax, %rbx
leaq 0x32e7(%rip), %rsi      # 0x65a8
movq %rax, %rdi
callq 0x22b0
movq 0x5d10(%rip), %rsi      # 0x8fe0
movq 0x5cf1(%rip), %rdx      # 0x8fc8
movq %rbx, %rdi
callq 0x2270
jmp 0x332e
pushq $0x10
popq %rdi
callq 0x20b0
movq %rax, %rbx
leaq 0x32d1(%rip), %rsi      # 0x65c4
leaq -0x88(%rbp), %rdi
leaq -0x68(%rbp), %rdx
callq 0x498d
movb $0x1, %r15b
leaq -0x88(%rbp), %rsi
movq %rbx, %rdi
callq 0x21c0
xorl %r15d, %r15d
movq 0x5cb9(%rip), %rsi      # 0x8fd8
movq 0x5c92(%rip), %rdx      # 0x8fb8
movq %rbx, %rdi
callq 0x2270
movq %rax, %r14
leaq -0x88(%rbp), %rdi
callq 0x20a0
testb %r15b, %r15b
jne 0x3349
jmp 0x3363
jmp 0x3346
movq %rax, %r14
movq %rbx, %rdi
callq 0x20e0
jmp 0x3363
movq %rax, %r14
jmp 0x3363
movq %rax, %r14
movq %rbx, %rdi
callq 0x4a12
leaq -0x68(%rbp), %rdi
callq 0x20a0
movq %r14, %rdi
callq 0x2290