// File: ddunbar[P]PDSample/RNG.cpp
// Function: RNG::getInt32()
unsigned long RNG::getInt32()
{
    unsigned long y;
    static unsigned long mag01[2]={0x0UL, MATRIX_A};
    /* mag01[x] = x * MATRIX_A  for x=0,1 */

    if (mti >= N) { /* generate N words at one time */
        int kk;

        for (kk=0;kk<N-M;kk++) {
            y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
            mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
        }
        for (;kk<N-1;kk++) {
            y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
            mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
        }
        y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
        mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];

        mti = 0;
    }
  
    y = mt[mti++];

    /* Tempering */
    y ^= (y >> 11);
    y ^= (y << 7) & 0x9d2c5680UL;
    y ^= (y << 15) & 0xefc60000UL;
    y ^= (y >> 18);

    return y;
}

// Assembly:
movq %rdi, -0x8(%rsp)
movq -0x8(%rsp), %rax
movq %rax, -0x20(%rsp)
movslq 0x1380(%rax), %rax
cmpq $0x270, %rax            # imm = 0x270
jl 0x2b79
movl $0x0, -0x14(%rsp)
movslq -0x14(%rsp), %rax
cmpq $0xe3, %rax
jge 0x2a91
movq -0x20(%rsp), %rax
movslq -0x14(%rsp), %rdx
movabsq $0x80000000, %rcx       # imm = 0x80000000
andq (%rax,%rdx,8), %rcx
movl -0x14(%rsp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rdx
andq $0x7fffffff, %rdx       # imm = 0x7FFFFFFF
orq %rdx, %rcx
movq %rcx, -0x10(%rsp)
movslq -0x14(%rsp), %rcx
movq 0xc68(%rax,%rcx,8), %rdx
movq -0x10(%rsp), %rcx
shrq %rcx
xorq %rcx, %rdx
movq -0x10(%rsp), %rsi
andq $0x1, %rsi
leaq 0x1d73c(%rip), %rcx     # 0x201b0
xorq (%rcx,%rsi,8), %rdx
movslq -0x14(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rsp)
jmp 0x2a0a
jmp 0x2a93
movslq -0x14(%rsp), %rax
cmpq $0x26f, %rax            # imm = 0x26F
jge 0x2b1a
movq -0x20(%rsp), %rax
movslq -0x14(%rsp), %rdx
movabsq $0x80000000, %rcx       # imm = 0x80000000
andq (%rax,%rdx,8), %rcx
movl -0x14(%rsp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rdx
andq $0x7fffffff, %rdx       # imm = 0x7FFFFFFF
orq %rdx, %rcx
movq %rcx, -0x10(%rsp)
movslq -0x14(%rsp), %rcx
movq -0x718(%rax,%rcx,8), %rdx
movq -0x10(%rsp), %rcx
shrq %rcx
xorq %rcx, %rdx
movq -0x10(%rsp), %rsi
andq $0x1, %rsi
leaq 0x1d6b3(%rip), %rcx     # 0x201b0
xorq (%rcx,%rsi,8), %rdx
movslq -0x14(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rsp)
jmp 0x2a93
movq -0x20(%rsp), %rax
movabsq $0x80000000, %rcx       # imm = 0x80000000
andq 0x1378(%rax), %rcx
movq (%rax), %rdx
andq $0x7fffffff, %rdx       # imm = 0x7FFFFFFF
orq %rdx, %rcx
movq %rcx, -0x10(%rsp)
movq 0xc60(%rax), %rcx
movq -0x10(%rsp), %rdx
shrq %rdx
xorq %rdx, %rcx
movq -0x10(%rsp), %rsi
andq $0x1, %rsi
leaq 0x1d64c(%rip), %rdx     # 0x201b0
xorq (%rdx,%rsi,8), %rcx
movq %rcx, 0x1378(%rax)
movl $0x0, 0x1380(%rax)
movq -0x20(%rsp), %rax
movl 0x1380(%rax), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0x1380(%rax)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x10(%rsp)
movq -0x10(%rsp), %rax
shrq $0xb, %rax
xorq -0x10(%rsp), %rax
movq %rax, -0x10(%rsp)
movq -0x10(%rsp), %rax
shlq $0x7, %rax
movabsq $0x9d2c5680, %rcx       # imm = 0x9D2C5680
andq %rcx, %rax
xorq -0x10(%rsp), %rax
movq %rax, -0x10(%rsp)
movq -0x10(%rsp), %rax
shlq $0xf, %rax
movabsq $0xefc60000, %rcx       # imm = 0xEFC60000
andq %rcx, %rax
xorq -0x10(%rsp), %rax
movq %rax, -0x10(%rsp)
movq -0x10(%rsp), %rax
shrq $0x12, %rax
xorq -0x10(%rsp), %rax
movq %rax, -0x10(%rsp)
movq -0x10(%rsp), %rax
retq
nopw (%rax,%rax)