// File: /workspace/github_c_makefile_star2_O3/sasairc[P]clangsay/src/cow.c
// Function: print_cow
static
int print_cow(COW* cow, COWOPT* opt)
{
    int     i       = 0,
            j       = 0;

    char*   though  = NULL;

    short   block   = 0;

    /* eyes table */
    struct  reptarg eyes[] = {
        {MODE_M_EYE,    EYES,   opt->eye},
        {MODE_BORG,     EYES,   BORG_EYES},
        {MODE_DEAD,     EYES,   DEAD_EYES},
        {MODE_GREEDY,   EYES,   GREEDY_EYES},
        {MODE_PARANOID, EYES,   PARANOID_EYES},
        {MODE_STONED,   EYES,   STONED_EYES},
        {MODE_TIRED,    EYES,   TIRED_EYES},
        {MODE_WIRED,    EYES,   WIRED_EYES},
        {MODE_YOUTHFUL, EYES,   YOUTHFUL_EYES},
        {0,             NULL,   NULL},
    };
    /* tongue table */
    struct  reptarg tongue[] = {
        {MODE_M_TONGUE, TONGUE, opt->tongue},
        {MODE_DEAD,     TONGUE, DEAD_TONGUE},
        {MODE_STONED,   TONGUE, DEAD_TONGUE},
        {0,             NULL,   NULL},
    };

    /* setting thoughts
     * 1. default
     * 2. --say
     * 3. --think
     */
    if (!(opt->mode & MODE_SAY) && !(opt->mode & MODE_THINK))
        though = SAY_THOUGHTS;
    else if (opt->mode & MODE_SAY)
        though = SAY_THOUGHTS;
    else if (opt->mode & MODE_THINK)
        though = THINK_THOUGHTS;

    /* print cow */
    i = 0;
    while (i < cow->lines) {
        /* replace thoughts */
        strrep(*(cow->data + i), THOUGHTS, though);
        /* replace backslash ( \\ -> \ ) */
        replace_escaped_backslash(*(cow->data + i));
        /* replace eyes*/
        j = 0;
        while (eyes[j].haystack != NULL || eyes[j].needle != NULL) {
            if (opt->mode & eyes[j].mode)
                strrep(*(cow->data + i), eyes[j].haystack, eyes[j].needle);
            j++;
        }
        /* default_eyes */
        strrep(*(cow->data + i), EYES, DEFAULT_EYES);

        /* replace tongue */
        j = 0;
        while (tongue[j].haystack != NULL || tongue[j].needle != NULL) {
            if (opt->mode & tongue[j].mode)
                strrep(*(cow->data + i), tongue[j].haystack, tongue[j].needle);
            j++;
        }
        /* default tongue */
        strrep(*(cow->data + i), TONGUE, DEFAULT_TONGUE);

        /* EOC to EOC */
        if (strstr(*(cow->data + i), "EOC")) {
            block = 1;
            i++;
            continue;
        } else if (strstr(*(cow->data + i), "EOC") && block == 1) {
            block = 0;
        }
        if (block == 1)
            fprintf(stdout, "%s\n",
                    *(cow->data + i));
        i++;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq %rsi, %rbx
movq %rdi, %r14
movl $0x800, 0x70(%rsp)      # imm = 0x800
leaq 0x1d5b(%rip), %rcx      # 0xc37b
movq %rcx, 0x78(%rsp)
movq 0x8(%rsi), %rax
movq %rax, 0x80(%rsp)
movl $0x8, 0x88(%rsp)
movq %rcx, 0x90(%rsp)
leaq 0x1d36(%rip), %rax      # 0xc381
movq %rax, 0x98(%rsp)
movl $0x10, %eax
movl %eax, 0xa0(%rsp)
movq %rcx, 0xa8(%rsp)
leaq 0x1d16(%rip), %rdx      # 0xc384
movq %rdx, 0xb0(%rsp)
movl $0x20, 0xb8(%rsp)
movq %rcx, 0xc0(%rsp)
leaq 0x1cf7(%rip), %rdx      # 0xc387
movq %rdx, 0xc8(%rsp)
movl $0x40, 0xd0(%rsp)
movq %rcx, 0xd8(%rsp)
leaq 0x1cd8(%rip), %rdx      # 0xc38a
movq %rdx, 0xe0(%rsp)
movl $0x80, %edx
movl %edx, 0xe8(%rsp)
movq %rcx, 0xf0(%rsp)
leaq 0x1cb8(%rip), %rsi      # 0xc38d
movq %rsi, 0xf8(%rsp)
movl $0x100, 0x100(%rsp) # imm = 0x100
movq %rcx, 0x108(%rsp)
leaq 0x1c99(%rip), %rsi      # 0xc390
movq %rsi, 0x110(%rsp)
movl $0x200, 0x118(%rsp) # imm = 0x200
movq %rcx, 0x120(%rsp)
leaq 0x1c7a(%rip), %rsi      # 0xc393
movq %rsi, 0x128(%rsp)
movl $0x400, 0x130(%rsp) # imm = 0x400
movq %rcx, 0x138(%rsp)
leaq 0x1c5b(%rip), %rcx      # 0xc396
movq %rcx, 0x140(%rsp)
xorl %ecx, %ecx
movq %rcx, 0x158(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x148(%rsp)
movl $0x1000, 0x10(%rsp)     # imm = 0x1000
leaq 0x1c32(%rip), %rsi      # 0xc399
movq %rsi, 0x18(%rsp)
movq 0x10(%rbx), %rdi
movq %rdi, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movq %rsi, 0x30(%rsp)
leaq 0x1c1c(%rip), %rax      # 0xc3a1
movq %rax, 0x38(%rsp)
movl %edx, 0x40(%rsp)
movq %rsi, 0x48(%rsp)
movq %rax, 0x50(%rsp)
movups %xmm0, 0x58(%rsp)
movq %rcx, 0x68(%rsp)
movl (%rbx), %eax
testb $0x4, %al
leaq 0x1c02(%rip), %rdx      # 0xc3af
cmoveq %rcx, %rdx
testb $0x2, %al
leaq 0x20d2(%rip), %rcx      # 0xc88c
cmovneq %rcx, %rdx
testb $0x6, %al
cmoveq %rcx, %rdx
movq %rdx, 0x8(%rsp)
cmpl $0x0, 0x10(%r14)
jle 0xa966
movb $0x1, %al
movl %eax, 0x4(%rsp)
leaq 0x20ab(%rip), %r13      # 0xc88c
xorl %r15d, %r15d
movslq %r15d, %r15
movq 0x8(%r14), %rax
movq (%rax,%r15,8), %rdi
leaq 0x1bae(%rip), %rsi      # 0xc3a4
movq 0x8(%rsp), %rdx
callq 0x5a60
movq 0x8(%r14), %rax
movq (%rax,%r15,8), %rsi
xorl %r12d, %r12d
movq %rsi, %rax
movzbl (%rax), %ecx
cmpl $0x5c, %ecx
je 0xa81c
testl %ecx, %ecx
jne 0xa82f
jmp 0xa834
xorl %ecx, %ecx
cmpb $0x5c, 0x1(%rax)
sete %dl
jne 0xa82a
incq %rax
movb %dl, %cl
addl %ecx, %r12d
incq %rax
jmp 0xa80e
testl %r12d, %r12d
movq %r13, %rbp
je 0xa859
movq %rsi, %r13
movq %rsi, %rdi
leaq 0x1b6f(%rip), %rsi      # 0xc3b8
movq %rbp, %rdx
callq 0x5a60
movq %r13, %rsi
decl %r12d
jne 0xa83c
leaq 0x80(%rsp), %r12
movq %rbp, %r13
movq -0x8(%r12), %rsi
testq %rsi, %rsi
jne 0xa875
cmpq $0x0, (%r12)
je 0xa895
movl -0x10(%r12), %eax
testl %eax, (%rbx)
je 0xa88f
movq 0x8(%r14), %rax
movq (%rax,%r15,8), %rdi
movq (%r12), %rdx
callq 0x5a60
addq $0x18, %r12
jmp 0xa864
movq 0x8(%r14), %rax
movq (%rax,%r15,8), %rdi
leaq 0x1ad7(%rip), %rsi      # 0xc37b
leaq 0x1b03(%rip), %rdx      # 0xc3ae
callq 0x5a60
leaq 0x20(%rsp), %r12
movq -0x8(%r12), %rsi
testq %rsi, %rsi
jne 0xa8c6
cmpq $0x0, (%r12)
je 0xa8e6
movl -0x10(%r12), %eax
testl %eax, (%rbx)
je 0xa8e0
movq 0x8(%r14), %rax
movq (%rax,%r15,8), %rdi
movq (%r12), %rdx
callq 0x5a60
addq $0x18, %r12
jmp 0xa8b5
movq 0x8(%r14), %rax
movq (%rax,%r15,8), %rdi
leaq 0x1aa4(%rip), %rsi      # 0xc399
leaq 0x1ab5(%rip), %rdx      # 0xc3b1
callq 0x5a60
movq 0x8(%r14), %rax
movq (%rax,%r15,8), %rbp
movq %rbp, %rdi
leaq 0x1aa1(%rip), %rsi      # 0xc3b4
callq 0x2290
testq %rax, %rax
jne 0xa951
testb $0x1, 0x4(%rsp)
jne 0xa93f
movq 0x66c5(%rip), %rax      # 0x10ff0
movq (%rax), %rdi
leaq 0x1fa4(%rip), %rsi      # 0xc8d9
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2450
incq %r15
movslq 0x10(%r14), %rax
cmpq %rax, %r15
jl 0xa7e7
jmp 0xa966
incl %r15d
movl $0x0, 0x4(%rsp)
cmpl 0x10(%r14), %r15d
jl 0xa7e4
xorl %eax, %eax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq