// File: /workspace/github_c_makefile_star2_O1/sasairc[P]clangsay/src/clangsay.c
// Function: main
int main(int argc, char* argv[])
{
    int     res     = 0,
            index   = 0,
            rarg    = 0,
            status  = 0;

    char*   cowfile = NULL;

    COW*    cow     = NULL;

    MSG*    msg     = NULL;

    COWOPT  opt     = {
        COWOPT_ALLNO_FLAGS,
    };

    /* option for getopt_long() */
    struct  option opts[] = {
        {"eye",       required_argument, NULL, 'e'},
        {"tongue",    required_argument, NULL, 'T'},
        {"file",      required_argument, NULL, 'f'},
        {"recursive", required_argument, NULL, 'R'},
        {"nowrap",    no_argument,       NULL, 'n'},
        {"borg",      no_argument,       NULL, 'b'},
        {"dead",      no_argument,       NULL, 'd'},
        {"greedy",    no_argument,       NULL, 'g'},
        {"paranoid",  no_argument,       NULL, 'p'},
        {"stoned",    no_argument,       NULL, 's'},
        {"tired",     no_argument,       NULL, 't'},
        {"wired",     no_argument,       NULL, 'w'},
        {"youthful",  no_argument,       NULL, 'y'},
        {"list",      no_argument,       NULL, 'l'},
        {"say",       no_argument,       NULL,  0 },
        {"think",     no_argument,       NULL,  1 },
        {"help",      no_argument,       NULL,  2 },
        {"version",   no_argument,       NULL,  3 },
        {0, 0, 0, 0},
    };

    /* processing of arguments */
    while ((res = getopt_long(argc, argv, "nbdgpstwye:T:f:R:l", opts, &index)) != -1) {
        switch (res) {
            case    'e':
                opt.mode |= MODE_M_EYE;
                opt.eye= optarg;
                break;
            case    'T':
                opt.mode |= MODE_M_TONGUE;
                opt.tongue = optarg;
                break;
            case    'f':
                cowfile = optarg;
                break;
            case    'R':
                opt.mode |= MODE_MSG_RECURSIVE;
                if (strisdigit(optarg) < 0) {
                    fprintf(stderr, "%s: %s: invalid argument\n",
                            PROGNAME, optarg);
                    return -1;
                }
                rarg = atoi(optarg);
                break;
            case    'b':
                opt.mode |= MODE_BORG;
                break;
            case    'd':
                opt.mode |= MODE_DEAD;
                break;
            case    'g':
                opt.mode |= MODE_GREEDY;
                break;
            case    'p':
                opt.mode |= MODE_PARANOID;
                break;
            case    's':
                opt.mode |= MODE_STONED;
                break;
            case    't':
                opt.mode |= MODE_TIRED;
                break;
            case    'w':
                opt.mode |= MODE_WIRED;
                break;
            case    'y':
                opt.mode |= MODE_YOUTHFUL;
                break;
            case    'l':
                list_cowfiles();
            case    0:
                opt.mode |= MODE_SAY;
                break;
            case    1:
                opt.mode |= MODE_THINK;
                break;
            case    2:
                print_usage();
            case    3:
                print_version();
            case    '?':
                return -1;
        }
    }

    /* check env $DEFAULT_COWFILE */
    if (cowfile == NULL) {
        if ((cowfile = getenv("DEFAULT_COWFILE")) == NULL)
            cowfile = DEFAULT_COWFILE;
    }

    /* initialize cow */
    if (init_cow(&cow) < 0) {
        status = 1; goto ERR;
    }

    /* open cow file */
    if (cow->open(&cow, cowfile) < 0) {
        status = 2; goto ERR;
    }

    /* reading cow file to array */
    if (cow->read(&cow) < 0) {
        status = 3; goto ERR;
    }

    /* initialize msg */
    if (init_msg(&msg) < 0) {
        status = 4; goto ERR;
    }

    /* read argv or stdin */
    if (msg->read(&msg, argc, optind, argv) < 0) {
        status = 5; goto ERR;
    }

    /* <<<< recursive message box >>>> */
    if (opt.mode & MODE_MSG_RECURSIVE) {
        if (msg->recursive(&msg, rarg) < 0) {
            status = 6; goto ERR;
        }
    }

    /* print string */
    if (msg->print(msg) < 0) {
        status = 7; goto ERR;
    }

    /* print cow */
    cow->print(cow, &opt);

    /* release memory */
    release(cow, msg);

    return 0;

ERR:
    release(cow, msg);

    return status;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2b8, %rsp            # imm = 0x2B8
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x4c(%rsp), %r15
movl $0x0, (%r15)
xorl %eax, %eax
movq %rax, 0x8(%rsp)
movq %rax, (%rsp)
movq $0x0, 0x40(%rsp)
movq %rax, 0x20(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
leaq 0x6a52(%rip), %rsi      # 0x10b30
leaq 0x50(%rsp), %r13
movl $0x260, %edx            # imm = 0x260
movq %r13, %rdi
callq 0x2460
leaq 0x2115(%rip), %r12      # 0xc20c
leaq 0x2032(%rip), %r14      # 0xc130
movq $0x0, 0x38(%rsp)
movl %ebp, 0x34(%rsp)
movl %ebp, %edi
movq %rbx, %rsi
movq %r12, %rdx
movq %r13, %rcx
movq %r15, %r8
callq 0x2370
cmpl $0x53, %eax
jle 0xa146
leal -0x62(%rax), %ecx
cmpl $0x17, %ecx
ja 0xa1b7
leaq 0x200e(%rip), %rdx      # 0xc144
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
orb $0x8, 0x10(%rsp)
jmp 0xa10b
leal 0x1(%rax), %ecx
cmpl $0x4, %ecx
ja 0xa15e
movslq (%r14,%rcx,4), %rax
addq %r14, %rax
jmpq *%rax
orb $0x4, 0x10(%rsp)
jmp 0xa10b
cmpl $0x52, %eax
jne 0xa25b
movq %rbx, %rbp
movq %r14, %rbx
movq %r12, %r14
movq %r13, %r12
movq %r15, %r13
orb $0x20, 0x11(%rsp)
movq 0x6e46(%rip), %r15      # 0x10fc8
movq (%r15), %rdi
callq 0x5bfc
testl %eax, %eax
js 0xa380
movq (%r15), %rdi
callq 0x22f0
movq %rax, 0x40(%rsp)
movq %r13, %r15
movq %r12, %r13
movq %r14, %r12
movq %rbx, %r14
movq %rbp, %rbx
movl 0x34(%rsp), %ebp
jmp 0xa10b
cmpl $0x54, %eax
jne 0xa10b
orb $0x10, 0x11(%rsp)
movq 0x6dfc(%rip), %rax      # 0x10fc8
movq (%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0xa10b
orb $0x20, 0x10(%rsp)
jmp 0xa10b
orb $0x2, 0x11(%rsp)
jmp 0xa10b
orb $0x8, 0x11(%rsp)
movq 0x6dcf(%rip), %rax      # 0x10fc8
movq (%rax), %rax
movq %rax, 0x18(%rsp)
jmp 0xa10b
movq 0x6dbb(%rip), %rax      # 0x10fc8
movq (%rax), %rax
movq %rax, 0x38(%rsp)
jmp 0xa10b
orb $-0x80, 0x10(%rsp)
jmp 0xa10b
orb $0x10, 0x10(%rsp)
jmp 0xa10b
callq 0xacd0
orb $0x2, 0x10(%rsp)
jmp 0xa10b
orb $0x40, 0x10(%rsp)
jmp 0xa10b
orb $0x4, 0x11(%rsp)
jmp 0xa10b
orb $0x1, 0x11(%rsp)
jmp 0xa10b
cmpl $0x3f, %eax
jne 0xa10b
jmp 0xa34b
movq 0x38(%rsp), %r14
testq %r14, %r14
jne 0xa28d
leaq 0x1fc8(%rip), %rdi      # 0xc242
callq 0x2380
testq %rax, %rax
leaq 0x1fc9(%rip), %r14      # 0xc252
cmovneq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0xa3bc
testl %eax, %eax
js 0xa364
leaq 0x8(%rsp), %rdi
movq (%rdi), %rax
movq %r14, %rsi
callq *0x18(%rax)
testl %eax, %eax
js 0xa36b
leaq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
testl %eax, %eax
js 0xa372
movq %rsp, %rdi
callq 0xae3c
testl %eax, %eax
js 0xa379
movq %rsp, %rdi
movq (%rdi), %rax
movq 0x6cc3(%rip), %rcx      # 0x10fa8
movl (%rcx), %edx
movl %ebp, %esi
movq %rbx, %rcx
callq *0x10(%rax)
testl %eax, %eax
js 0xa387
testb $0x20, 0x11(%rsp)
je 0xa314
movq %rsp, %rdi
movq (%rdi), %rax
movq 0x40(%rsp), %rsi
callq *0x18(%rax)
testl %eax, %eax
js 0xa395
movq (%rsp), %rdi
callq *0x20(%rdi)
testl %eax, %eax
js 0xa38e
movq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq *0x28(%rdi)
movq 0x8(%rsp), %rdi
movq (%rsp), %r14
testq %rdi, %rdi
je 0xa33d
callq *0x30(%rdi)
xorl %ebx, %ebx
jmp 0xa3ab
callq 0xac76
callq 0xac28
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x2b8, %rsp            # imm = 0x2B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %ebx
jmp 0xa39a
movl $0x2, %ebx
jmp 0xa39a
movl $0x3, %ebx
jmp 0xa39a
movl $0x4, %ebx
jmp 0xa39a
callq 0x26cf
jmp 0xa34b
movl $0x5, %ebx
jmp 0xa39a
movl $0x7, %ebx
jmp 0xa39a
movl $0x6, %ebx
movq 0x8(%rsp), %rdi
movq (%rsp), %r14
testq %rdi, %rdi
je 0xa3ab
callq *0x30(%rdi)
testq %r14, %r14
je 0xa350
movq %r14, %rdi
callq *0x28(%r14)
jmp 0xa350
nopl (%rax)