// File: /workspace/github_c_makefile_star2_O2/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
leaq 0x80(%rsp), %rsi
movl $0x800, -0x10(%rsi)     # imm = 0x800
leaq 0x19d5(%rip), %r8       # 0xb33f
movq %r8, -0x8(%rsi)
movq 0x8(%rbx), %rax
movq %rax, (%rsi)
movl $0x8, 0x8(%rsi)
movq %r8, 0x10(%rsi)
leaq 0x19be(%rip), %rax      # 0xb345
movq %rax, 0x18(%rsi)
pushq $0x10
popq %rax
movl %eax, 0x20(%rsi)
movq %r8, 0x28(%rsi)
leaq 0x19ac(%rip), %rcx      # 0xb348
movq %rcx, 0x30(%rsi)
movl $0x20, 0x38(%rsi)
movq %r8, 0x40(%rsi)
leaq 0x1999(%rip), %rcx      # 0xb34b
movq %rcx, 0x48(%rsi)
movl $0x40, 0x50(%rsi)
movq %r8, 0x58(%rsi)
leaq 0x1986(%rip), %rcx      # 0xb34e
movq %rcx, 0x60(%rsi)
movl $0x80, %ecx
movl %ecx, 0x68(%rsi)
movq %r8, 0x70(%rsi)
leaq 0x1972(%rip), %rdx      # 0xb351
movq %rdx, 0x78(%rsi)
movl $0x100, 0x80(%rsi)      # imm = 0x100
movq %r8, 0x88(%rsi)
leaq 0x1959(%rip), %rdx      # 0xb354
movq %rdx, 0x90(%rsi)
movl $0x200, 0x98(%rsi)      # imm = 0x200
movq %r8, 0xa0(%rsi)
leaq 0x193d(%rip), %rdx      # 0xb357
movq %rdx, 0xa8(%rsi)
movl $0x400, 0xb0(%rsi)      # imm = 0x400
movq %r8, 0xb8(%rsi)
leaq 0x1921(%rip), %rdx      # 0xb35a
movq %rdx, 0xc0(%rsi)
xorps %xmm0, %xmm0
movups %xmm0, 0xc8(%rsi)
andq $0x0, 0xd8(%rsi)
leaq 0x20(%rsp), %rsi
movl $0x1000, -0x10(%rsi)    # imm = 0x1000
leaq 0x18f8(%rip), %r8       # 0xb35d
movq %r8, -0x8(%rsi)
movq 0x10(%rbx), %rdx
movq %rdx, (%rsi)
movl %eax, 0x8(%rsi)
movq %r8, 0x10(%rsi)
leaq 0x18e7(%rip), %rax      # 0xb365
movq %rax, 0x18(%rsi)
movl %ecx, 0x20(%rsi)
movq %r8, 0x28(%rsi)
movq %rax, 0x30(%rsi)
andq $0x0, 0x48(%rsi)
movq %rdi, %r12
movups %xmm0, 0x38(%rsi)
movl (%rbx), %eax
xorl %ecx, %ecx
testb $0x4, %al
leaq 0x18cd(%rip), %rdx      # 0xb373
cmoveq %rcx, %rdx
testb $0x2, %al
leaq 0x1d9d(%rip), %rcx      # 0xb850
cmovneq %rcx, %rdx
testb $0x6, %al
cmoveq %rcx, %rdx
movq %rdx, 0x8(%rsp)
movb $0x1, %al
movl %eax, 0x4(%rsp)
leaq 0x18ad(%rip), %r15      # 0xb37c
xorl %r13d, %r13d
movslq %r13d, %r13
movslq 0x10(%r12), %rax
cmpq %rax, %r13
jge 0x9c3f
movq 0x8(%r12), %rax
movq (%rax,%r13,8), %rdi
leaq 0x1875(%rip), %rsi      # 0xb368
movq 0x8(%rsp), %rdx
callq 0x5153
movq 0x8(%r12), %rax
movq (%rax,%r13,8), %r14
xorl %ebp, %ebp
movq %r14, %rax
movzbl (%rax), %ecx
cmpl $0x5c, %ecx
je 0x9b19
testl %ecx, %ecx
jne 0x9b2b
jmp 0x9b42
xorl %ecx, %ecx
cmpb $0x5c, 0x1(%rax)
sete %dl
jne 0x9b27
incq %rax
movb %dl, %cl
addl %ecx, %ebp
incq %rax
jmp 0x9b0b
movq %r14, %rdi
movq %r15, %rsi
leaq 0x1d13(%rip), %rdx      # 0xb850
callq 0x5153
subl $0x1, %ebp
jae 0x9b30
leaq 0x80(%rsp), %r14
movq -0x8(%r14), %rsi
testq %rsi, %rsi
jne 0x9b5e
cmpq $0x0, (%r14)
je 0x9b7d
movl -0x10(%r14), %eax
testl %eax, (%rbx)
je 0x9b77
movq 0x8(%r12), %rax
movq (%rax,%r13,8), %rdi
movq (%r14), %rdx
callq 0x5153
addq $0x18, %r14
jmp 0x9b4f
movq 0x8(%r12), %rax
movq (%rax,%r13,8), %rdi
leaq 0x17b2(%rip), %rsi      # 0xb33f
leaq 0x17de(%rip), %rdx      # 0xb372
callq 0x5153
leaq 0x20(%rsp), %r14
movq -0x8(%r14), %rsi
testq %rsi, %rsi
jne 0x9bad
cmpq $0x0, (%r14)
je 0x9bcc
movl -0x10(%r14), %eax
testl %eax, (%rbx)
je 0x9bc6
movq 0x8(%r12), %rax
movq (%rax,%r13,8), %rdi
movq (%r14), %rdx
callq 0x5153
addq $0x18, %r14
jmp 0x9b9e
movq 0x8(%r12), %rax
movq (%rax,%r13,8), %rdi
leaq 0x1781(%rip), %rsi      # 0xb35d
leaq 0x1792(%rip), %rdx      # 0xb375
callq 0x5153
movq 0x8(%r12), %rax
movq (%rax,%r13,8), %r14
movq %r14, %rdi
leaq 0x177d(%rip), %rsi      # 0xb378
callq 0x2290
testq %rax, %rax
jne 0x9c2f
testb $0x1, 0x4(%rsp)
jne 0x9c27
movq 0x73dd(%rip), %rax      # 0x10ff0
movq (%rax), %rdi
leaq 0x1c80(%rip), %rsi      # 0xb89d
movq %r14, %rdx
xorl %eax, %eax
callq 0x2450
incq %r13
jmp 0x9ad5
incq %r13
movl $0x0, 0x4(%rsp)
jmp 0x9ad2
xorl %eax, %eax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq