// File: /workspace/github_c_makefile_star2_O1/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 0x1b31(%rip), %rcx      # 0xc36d
movq %rcx, 0x78(%rsp)
movq 0x8(%rsi), %rax
movq %rax, 0x80(%rsp)
movl $0x8, 0x88(%rsp)
movq %rcx, 0x90(%rsp)
leaq 0x1b0c(%rip), %rax      # 0xc373
movq %rax, 0x98(%rsp)
movl $0x10, %eax
movl %eax, 0xa0(%rsp)
movq %rcx, 0xa8(%rsp)
leaq 0x1aec(%rip), %rdx      # 0xc376
movq %rdx, 0xb0(%rsp)
movl $0x20, 0xb8(%rsp)
movq %rcx, 0xc0(%rsp)
leaq 0x1acd(%rip), %rdx      # 0xc379
movq %rdx, 0xc8(%rsp)
movl $0x40, 0xd0(%rsp)
movq %rcx, 0xd8(%rsp)
leaq 0x1aae(%rip), %rdx      # 0xc37c
movq %rdx, 0xe0(%rsp)
movl $0x80, %edx
movl %edx, 0xe8(%rsp)
movq %rcx, 0xf0(%rsp)
leaq 0x1a8e(%rip), %rsi      # 0xc37f
movq %rsi, 0xf8(%rsp)
movl $0x100, 0x100(%rsp) # imm = 0x100
movq %rcx, 0x108(%rsp)
leaq 0x1a6f(%rip), %rsi      # 0xc382
movq %rsi, 0x110(%rsp)
movl $0x200, 0x118(%rsp) # imm = 0x200
movq %rcx, 0x120(%rsp)
leaq 0x1a50(%rip), %rsi      # 0xc385
movq %rsi, 0x128(%rsp)
movl $0x400, 0x130(%rsp) # imm = 0x400
movq %rcx, 0x138(%rsp)
leaq 0x1a31(%rip), %rcx      # 0xc388
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 0x1a08(%rip), %rsi      # 0xc38b
movq %rsi, 0x18(%rsp)
movq 0x10(%rbx), %rdi
movq %rdi, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movq %rsi, 0x30(%rsp)
leaq 0x19f2(%rip), %rax      # 0xc393
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 0x19d8(%rip), %rdx      # 0xc3a1
cmoveq %rcx, %rdx
testb $0x2, %al
leaq 0x1ea8(%rip), %rcx      # 0xc87e
cmovneq %rcx, %rdx
testb $0x6, %al
cmoveq %rcx, %rdx
movq %rdx, 0x8(%rsp)
cmpl $0x0, 0x10(%r14)
jle 0xab82
movb $0x1, %al
movl %eax, 0x4(%rsp)
leaq 0x1e81(%rip), %r13      # 0xc87e
xorl %r15d, %r15d
movslq %r15d, %r15
movq 0x8(%r14), %rax
movq (%rax,%r15,8), %rdi
leaq 0x1984(%rip), %rsi      # 0xc396
movq 0x8(%rsp), %rdx
callq 0x5c3c
movq 0x8(%r14), %rax
movq (%rax,%r15,8), %rsi
xorl %r12d, %r12d
movq %rsi, %rax
movzbl (%rax), %ecx
cmpl $0x5c, %ecx
je 0xaa38
testl %ecx, %ecx
jne 0xaa4b
jmp 0xaa50
xorl %ecx, %ecx
cmpb $0x5c, 0x1(%rax)
sete %dl
jne 0xaa46
incq %rax
movb %dl, %cl
addl %ecx, %r12d
incq %rax
jmp 0xaa2a
testl %r12d, %r12d
movq %r13, %rbp
je 0xaa75
movq %rsi, %r13
movq %rsi, %rdi
leaq 0x1945(%rip), %rsi      # 0xc3aa
movq %rbp, %rdx
callq 0x5c3c
movq %r13, %rsi
decl %r12d
jne 0xaa58
leaq 0x80(%rsp), %r12
movq %rbp, %r13
movq -0x8(%r12), %rsi
testq %rsi, %rsi
jne 0xaa91
cmpq $0x0, (%r12)
je 0xaab1
movl -0x10(%r12), %eax
testl %eax, (%rbx)
je 0xaaab
movq 0x8(%r14), %rax
movq (%rax,%r15,8), %rdi
movq (%r12), %rdx
callq 0x5c3c
addq $0x18, %r12
jmp 0xaa80
movq 0x8(%r14), %rax
movq (%rax,%r15,8), %rdi
leaq 0x18ad(%rip), %rsi      # 0xc36d
leaq 0x18d9(%rip), %rdx      # 0xc3a0
callq 0x5c3c
leaq 0x20(%rsp), %r12
movq -0x8(%r12), %rsi
testq %rsi, %rsi
jne 0xaae2
cmpq $0x0, (%r12)
je 0xab02
movl -0x10(%r12), %eax
testl %eax, (%rbx)
je 0xaafc
movq 0x8(%r14), %rax
movq (%rax,%r15,8), %rdi
movq (%r12), %rdx
callq 0x5c3c
addq $0x18, %r12
jmp 0xaad1
movq 0x8(%r14), %rax
movq (%rax,%r15,8), %rdi
leaq 0x187a(%rip), %rsi      # 0xc38b
leaq 0x188b(%rip), %rdx      # 0xc3a3
callq 0x5c3c
movq 0x8(%r14), %rax
movq (%rax,%r15,8), %rbp
movq %rbp, %rdi
leaq 0x1877(%rip), %rsi      # 0xc3a6
callq 0x2290
testq %rax, %rax
jne 0xab6d
testb $0x1, 0x4(%rsp)
jne 0xab5b
movq 0x64a9(%rip), %rax      # 0x10ff0
movq (%rax), %rdi
leaq 0x1d7a(%rip), %rsi      # 0xc8cb
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2440
incq %r15
movslq 0x10(%r14), %rax
cmpq %rax, %r15
jl 0xaa03
jmp 0xab82
incl %r15d
movl $0x0, 0x4(%rsp)
cmpl 0x10(%r14), %r15d
jl 0xaa00
xorl %eax, %eax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq