// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/shellaes128v1d5n64/ref/shellaes.c
// Function: CENC
void CENC(const u32 rkprime[], u8 S[], u8 F[], const u8 nonce[], unsigned long long int ptlen){

    u8 ctr[16];
    u8 G[16];
    u8 ct[16];
    int i, j=0;

    /*initialize ctr*/
    memset(ctr, 0, 16);
    memcpy(ctr, nonce, byte_length_nonce);

    /*produce the output S except the last block*/
    aesEncrypt(rkprime, ctr, G);

    while(ptlen>16){
        /*increase ctr by adding 1*/
        if(++ctr[15]==0){
            i=14;
            while(++ctr[i]==0){
                --i;
            }
        }
        /*update the value of G*/
        if(j==w){
            aesEncrypt(rkprime, ctr, G);
            j=0;
            continue;
        }

        aesEncrypt(rkprime, ctr, S);

        xor_byte_string(G, S, 16);

        S+=16;

        ptlen-=16;
        ++j;
    }

    /*produce the last block of S*/

    if(++ctr[15]==0){
          i=14;
          while(++ctr[i]==0){
               --i;
          }
    }

    if(j==w){
         aesEncrypt(rkprime, ctr, G);
         j=0;
         if(++ctr[15]==0){
            i=14;
            while(++ctr[i]==0){
                    --i;
            }
        }
    }

    aesEncrypt(rkprime, ctr, ct);
    xor_byte_string(G, ct, 16);

    memcpy(S, ct, ptlen);

    ++j;

    /*produce the value of F*/

    if(++ctr[15]==0){
          i=14;
          while(++ctr[i]==0){
               --i;
          }
    }

    if(j==w){
         aesEncrypt(rkprime, ctr, G);
         j=0;
         if(++ctr[15]==0){
            i=14;
            while(++ctr[i]==0){
                    --i;
            }
        }
    }

    aesEncrypt(rkprime, ctr, F);
    xor_byte_string(G, F, 16);

}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movq %rdx, 0x50(%rsp)
movq %rcx, 0x48(%rsp)
movq %r8, 0x40(%rsp)
movl $0x0, 0x8(%rsp)
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2070
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x60(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x2200
cmpq $0x10, 0x40(%rsp)
jbe 0x5c5f
movb 0x3f(%rsp), %al
addb $0x1, %al
movb %al, 0x3f(%rsp)
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x5be3
movl $0xe, 0xc(%rsp)
movslq 0xc(%rsp), %rcx
movb 0x30(%rsp,%rcx), %al
addb $0x1, %al
movb %al, 0x30(%rsp,%rcx)
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x5be1
movl 0xc(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x5bbd
jmp 0x5be3
cmpl $0x100, 0x8(%rsp)       # imm = 0x100
jne 0x5c0b
movq 0x60(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x2200
movl $0x0, 0x8(%rsp)
jmp 0x5b97
movq 0x60(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movq 0x58(%rsp), %rdx
callq 0x2200
leaq 0x20(%rsp), %rdi
movq 0x58(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
movq 0x58(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x58(%rsp)
movq 0x40(%rsp), %rax
subq $0x10, %rax
movq %rax, 0x40(%rsp)
movl 0x8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8(%rsp)
jmp 0x5b97
movb 0x3f(%rsp), %al
addb $0x1, %al
movb %al, 0x3f(%rsp)
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x5c9f
movl $0xe, 0xc(%rsp)
movslq 0xc(%rsp), %rcx
movb 0x30(%rsp,%rcx), %al
addb $0x1, %al
movb %al, 0x30(%rsp,%rcx)
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x5c9d
movl 0xc(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x5c79
jmp 0x5c9f
cmpl $0x100, 0x8(%rsp)       # imm = 0x100
jne 0x5d07
movq 0x60(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x2200
movl $0x0, 0x8(%rsp)
movb 0x3f(%rsp), %al
addb $0x1, %al
movb %al, 0x3f(%rsp)
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x5d05
movl $0xe, 0xc(%rsp)
movslq 0xc(%rsp), %rcx
movb 0x30(%rsp,%rcx), %al
addb $0x1, %al
movb %al, 0x30(%rsp,%rcx)
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x5d03
movl 0xc(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x5cdf
jmp 0x5d05
jmp 0x5d07
movq 0x60(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x2200
leaq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
movq 0x58(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq 0x40(%rsp), %rdx
callq 0x2270
movl 0x8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8(%rsp)
movb 0x3f(%rsp), %al
addb $0x1, %al
movb %al, 0x3f(%rsp)
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x5d8e
movl $0xe, 0xc(%rsp)
movslq 0xc(%rsp), %rcx
movb 0x30(%rsp,%rcx), %al
addb $0x1, %al
movb %al, 0x30(%rsp,%rcx)
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x5d8c
movl 0xc(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x5d68
jmp 0x5d8e
cmpl $0x100, 0x8(%rsp)       # imm = 0x100
jne 0x5df6
movq 0x60(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x2200
movl $0x0, 0x8(%rsp)
movb 0x3f(%rsp), %al
addb $0x1, %al
movb %al, 0x3f(%rsp)
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x5df4
movl $0xe, 0xc(%rsp)
movslq 0xc(%rsp), %rcx
movb 0x30(%rsp,%rcx), %al
addb $0x1, %al
movb %al, 0x30(%rsp,%rcx)
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x5df2
movl 0xc(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x5dce
jmp 0x5df4
jmp 0x5df6
movq 0x60(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movq 0x50(%rsp), %rdx
callq 0x2200
leaq 0x20(%rsp), %rdi
movq 0x50(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)