// File: chuckwolber[P]Cube/test/../Cube.cpp
// Function: Cube::rotateLayer(Layer, bool)
void Cube::rotateLayer(Layer layer, bool clockwise) {
    unsigned int subCubeSize, subLayerMax;
    unsigned int ulr, ulc, urr, urc, llr, llc, lrr, lrc;

    /**
     * We have to set this to a throw-away value because -Ofast optimization
     * causes an unassigned variable to emit -Werror=maybe-uninitialized. This
     * warning cannot be squelched when using LLVM because of LLVM bug
     * https://bugs.llvm.org/show_bug.cgi?id=24979
     */
    Coordinate ul = {Layer::U, true};
   
    getLayerUpperLeft(ul, layer);
    subLayerMax = (unsigned int)ceil((float)cubeSize/2);
   
    for (unsigned int subLayer=0; subLayer<subLayerMax; subLayer++) {
        subCubeSize = cubeSize - 2*subLayer;
      
        ulr = ul.row + subLayer;
        urc = ul.col + subLayer + subCubeSize - 1;
        llc = ul.col + subLayer;
        lrr = ul.row + subLayer + subCubeSize - 1;
      
        for (unsigned int i=0; i<(subCubeSize - 1); i++) {
            ulc = ul.col + subLayer + i;
            urr = ul.row + subLayer + i;
            llr = ul.row + subLayer + subCubeSize - 1 - i;
            lrc = ul.col + subLayer + subCubeSize - 1 - i;
         
            fourWayRotate({{ulr, ulc},  // Upper Left
                           {urr, urc},  // Upper Right
                           {lrr, lrc},  // Lower Right
                           {llr, llc}}, // Lower Left
                            clockwise);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movb %dl, %al
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
andb $0x1, %al
movb %al, -0xd(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x70(%rbp)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, -0x40(%rbp)
movl -0xc(%rbp), %edx
leaq -0x40(%rbp), %rsi
callq 0x8af0
movq -0x70(%rbp), %rax
movl 0x8(%rax), %eax
cvtsi2ss %rax, %xmm0
movss 0x7a35(%rip), %xmm1     # 0x10294
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x2050
cvttsd2si %xmm0, %rax
movl %eax, -0x18(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x18(%rbp), %eax
jae 0x89a1
movq -0x70(%rbp), %rax
movl 0x8(%rax), %eax
movl -0x44(%rbp), %ecx
shll %ecx
subl %ecx, %eax
movl %eax, -0x14(%rbp)
movl -0x40(%rbp), %eax
addl -0x44(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x3c(%rbp), %eax
addl -0x44(%rbp), %eax
addl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x3c(%rbp), %eax
addl -0x44(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x40(%rbp), %eax
addl -0x44(%rbp), %eax
addl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jae 0x8991
movq -0x70(%rbp), %rdi
movl -0x3c(%rbp), %eax
addl -0x44(%rbp), %eax
addl -0x48(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x40(%rbp), %eax
addl -0x44(%rbp), %eax
addl -0x48(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x40(%rbp), %eax
addl -0x44(%rbp), %eax
addl -0x14(%rbp), %eax
subl $0x1, %eax
subl -0x48(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x3c(%rbp), %eax
addl -0x44(%rbp), %eax
addl -0x14(%rbp), %eax
subl $0x1, %eax
subl -0x48(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x4c(%rbp)
movb -0xd(%rbp), %al
leaq -0x68(%rbp), %rcx
andb $0x1, %al
movq (%rcx), %rdx
movq %rdx, (%rsp)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rsp)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rsp)
movq 0x18(%rcx), %rcx
movq %rcx, 0x18(%rsp)
movzbl %al, %esi
callq 0x8b80
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x88cf
jmp 0x8993
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x887b
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)