// File: /workspace/github_c_makefile_star2_O3/janmojzis[P]mcencrypt/mcencrypt.c
// Function: main
int main(int argc, char **argv) {

    long long r;

    /* get publickey */
    if (!checkfd(4, POLLIN)) die_usage(NAME, "read publickey failed", "<message 4<publickey >ciphertext");
    limits();
    r = readblock(4, g.pk, sizeof g.pk);
    if (r == -1) die_temp(NAME, "read publickey failed");
    if (r != sizeof g.pk) die_perm(NAME, "read publickey failed: short public key");
    close(4);

    /* KEM - generate ciphertext + symetric key */
    if (crypto_kem_mceliece8192128sha512_enc(g.c, g.k, g.pk) != 0) die_temp(NAME, "encryption failed");
    if (writeall(1, g.c, sizeof g.c) == -1) die_temp(NAME, "write ciphertext failed");

    /* symetric key and nonce for encryption */
    chacha20_init(&g.chacha20ctx, g.k, g.k + chacha20_KEYBYTES);
    randombytes(g.k, sizeof g.k);

    /* symetric key for authentication */
    memset(g.ak, 0, sizeof g.ak);
    chacha20_blocks(&g.chacha20ctx, g.ak, g.ak, sizeof g.ak);
    poly1305_init(&g.poly1305ctx, g.ak);
    randombytes(g.ak, sizeof g.ak);

    /* authenticate ciphertext */
    poly1305_blocks(&g.poly1305ctx, g.c, sizeof g.c); /* XXX sizeof g.c must be power of 16 */
    randombytes(g.c, sizeof g.c);

    /* read input and write encrypted output */
    for (;;) {
        r = readblock(0, g.buf, sizeof g.buf);
        if (r == -1) die_temp(NAME, "read message failed");
        inputlen += r;
        if (inputlen > MAX) die_perm(NAME, "read message failed: input message too long");
        chacha20_blocks(&g.chacha20ctx, g.buf, g.buf, r);
        poly1305_blocks(&g.poly1305ctx, g.buf, r);
        if (writeall(1, g.buf, r) == -1) die_temp(NAME, "write ciphertext failed");
        if (r != sizeof g.buf) break;
    }

    /* write authenticator */
    poly1305_final(&g.poly1305ctx, g.a);
    if (writeall(1, g.a, sizeof g.a) == -1) die_temp(NAME, "write ciphertext failed");
    if (fsyncfd(1) == -1) die_temp(NAME, "write ciphertext failed");

    die(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl $0x4, %edi
movl $0x1, %esi
callq 0x3b04
testl %eax, %eax
jne 0x1275
leaq 0x6da2(%rip), %rdi      # 0x8004
leaq 0x6da5(%rip), %rsi      # 0x800e
leaq 0x6db4(%rip), %rdx      # 0x8024
callq 0x4ab0
callq 0x5ae8
leaq 0x9e37(%rip), %rsi      # 0xb0b8
movl $0x14b800, %edx         # imm = 0x14B800
movl $0x4, %edi
callq 0x69e0
cmpq $0x14b800, %rax         # imm = 0x14B800
je 0x12c4
cmpq $-0x1, %rax
jne 0x12b1
leaq 0x6d5f(%rip), %rdi      # 0x8004
leaq 0x6d62(%rip), %rsi      # 0x800e
callq 0x4bdf
leaq 0x6d4c(%rip), %rdi      # 0x8004
leaq 0x6d86(%rip), %rsi      # 0x8045
callq 0x4c4d
movl $0x4, %edi
callq 0x1080
leaq 0x155663(%rip), %rdi    # 0x156938
leaq 0x1555dc(%rip), %rsi    # 0x1568b8
leaq 0x9dd5(%rip), %rdx      # 0xb0b8
callq 0x5bc0
testl %eax, %eax
je 0x12ff
leaq 0x6d11(%rip), %rdi      # 0x8004
leaq 0x6d73(%rip), %rsi      # 0x806d
callq 0x4bdf
leaq 0x155632(%rip), %rsi    # 0x156938
movl $0xf0, %edx
movl $0x1, %edi
callq 0x6f98
cmpl $-0x1, %eax
jne 0x132d
leaq 0x6ce3(%rip), %rdi      # 0x8004
leaq 0x6d57(%rip), %rsi      # 0x807f
callq 0x4bdf
leaq 0x255704(%rip), %rbx    # 0x256a38
leaq 0x15557d(%rip), %r14    # 0x1568b8
leaq 0x155596(%rip), %rdx    # 0x1568d8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1b74
movl $0x40, %esi
movq %r14, %rdi
callq 0x6930
xorps %xmm0, %xmm0
movups %xmm0, 0x1555c4(%rip)   # 0x156928
movups %xmm0, 0x1555ad(%rip)   # 0x156918
movups %xmm0, 0x155596(%rip)   # 0x156908
movups %xmm0, 0x15557f(%rip)   # 0x1568f8
leaq 0x155578(%rip), %r15    # 0x1568f8
movl $0x40, %ecx
movq %rbx, %rdi
movq %r15, %rsi
movq %r15, %rdx
callq 0x1bc0
leaq 0x2556f6(%rip), %r14    # 0x256a90
movq %r14, %rdi
movq %r15, %rsi
callq 0x6398
movl $0x40, %esi
movq %r15, %rdi
callq 0x6930
leaq 0x15557f(%rip), %r15    # 0x156938
movl $0xf0, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x643d
movl $0xf0, %esi
movq %r15, %rdi
callq 0x6930
leaq 0x15565b(%rip), %r15    # 0x156a38
leaq 0x6c20(%rip), %r12      # 0x8004
movabsq $0x4000000000000001, %rbp # imm = 0x4000000000000001
movl $0x100000, %edx         # imm = 0x100000
xorl %edi, %edi
movq %r15, %rsi
callq 0x69e0
movq %rax, %r13
cmpq $-0x1, %rax
jne 0x1415
movq %r12, %rdi
leaq 0x6c87(%rip), %rsi      # 0x8097
callq 0x4bdf
movq 0x25570c(%rip), %rax    # 0x256b28
addq %r13, %rax
movq %rax, 0x255702(%rip)    # 0x256b28
cmpq %rbp, %rax
jb 0x143a
movq %r12, %rdi
leaq 0x6c76(%rip), %rsi      # 0x80ab
callq 0x4c4d
movq %rbx, %rdi
movq %r15, %rsi
movq %r15, %rdx
movq %r13, %rcx
callq 0x1bc0
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x643d
movl $0x1, %edi
movq %r15, %rsi
movq %r13, %rdx
callq 0x6f98
cmpl $-0x1, %eax
jne 0x147d
movq %r12, %rdi
leaq 0x6c07(%rip), %rsi      # 0x807f
callq 0x4bdf
cmpq $0x100000, %r13         # imm = 0x100000
je 0x13ee
leaq 0x2555ff(%rip), %rdi    # 0x256a90
leaq 0x155590(%rip), %rbx    # 0x156a28
movq %rbx, %rsi
callq 0x66ed
movl $0x10, %edx
movl $0x1, %edi
movq %rbx, %rsi
callq 0x6f98
cmpl $-0x1, %eax
jne 0x14ca
leaq 0x6b46(%rip), %rdi      # 0x8004
leaq 0x6bba(%rip), %rsi      # 0x807f
callq 0x4bdf
movl $0x1, %edi
callq 0x5264
cmpl $-0x1, %eax
jne 0x14ec
leaq 0x6b24(%rip), %rdi      # 0x8004
leaq 0x6b98(%rip), %rsi      # 0x807f
callq 0x4bdf
xorl %edi, %edi
callq 0x4c93
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq