// File: /workspace/github_c_makefile_star2_O3/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 $0x2a8, %rsp            # imm = 0x2A8
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x34(%rsp), %rax
movl $0x0, (%rax)
xorl %r14d, %r14d
movq %r14, 0x8(%rsp)
movq %r14, (%rsp)
movq %r14, 0x20(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
leaq 0x6bff(%rip), %rsi      # 0x10b30
leaq 0x40(%rsp), %r13
movl $0x260, %edx            # imm = 0x260
movq %r13, %rdi
callq 0x2470
leaq 0x22e2(%rip), %r12      # 0xc22c
leaq 0x21ff(%rip), %r15      # 0xc150
movl $0x0, 0x2c(%rsp)
movq $0x0, 0x38(%rsp)
movl %ebp, 0x30(%rsp)
movl %ebp, %edi
movq %rbx, %rsi
movq %r12, %rdx
movq %r13, %rcx
leaq 0x34(%rsp), %r8
callq 0x2370
cmpl $0x53, %eax
jle 0x9fa7
leal -0x62(%rax), %ecx
cmpl $0x17, %ecx
ja 0xa01e
leaq 0x21d1(%rip), %rdx      # 0xc164
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
orl $0x8, %r14d
movl %r14d, 0x10(%rsp)
jmp 0x9f66
leal 0x1(%rax), %ecx
cmpl $0x4, %ecx
ja 0x9fc3
movslq (%r15,%rcx,4), %rax
addq %r15, %rax
jmpq *%rax
orl $0x4, %r14d
movl %r14d, 0x10(%rsp)
jmp 0x9f66
cmpl $0x52, %eax
jne 0xa0fc
movq %rbx, %rbp
movq %r15, %rbx
movq %r12, %r15
movq %r13, %r12
orl $0x2000, %r14d          # imm = 0x2000
movl %r14d, 0x10(%rsp)
movq 0x6fdd(%rip), %r13      # 0x10fc8
movq (%r13), %rdi
callq 0x5a20
testl %eax, %eax
js 0xa220
movq (%r13), %rdi
callq 0x22f0
movl %eax, 0x2c(%rsp)
movq %r12, %r13
movq %r15, %r12
movq %rbx, %r15
movq %rbp, %rbx
movl 0x30(%rsp), %ebp
jmp 0x9f66
cmpl $0x54, %eax
jne 0x9f66
orl $0x1000, %r14d          # imm = 0x1000
movl %r14d, 0x10(%rsp)
movq 0x6f8e(%rip), %rax      # 0x10fc8
movq (%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x9f66
orl $0x20, %r14d
movl %r14d, 0x10(%rsp)
jmp 0x9f66
orl $0x200, %r14d           # imm = 0x200
movl %r14d, 0x10(%rsp)
jmp 0x9f66
orl $0x800, %r14d           # imm = 0x800
movl %r14d, 0x10(%rsp)
movq 0x6f4f(%rip), %rax      # 0x10fc8
movq (%rax), %rax
movq %rax, 0x18(%rsp)
jmp 0x9f66
movq 0x6f3b(%rip), %rax      # 0x10fc8
movq (%rax), %rax
movq %rax, 0x38(%rsp)
jmp 0x9f66
orl $0x80, %r14d
movl %r14d, 0x10(%rsp)
jmp 0x9f66
orl $0x10, %r14d
movl %r14d, 0x10(%rsp)
jmp 0x9f66
callq 0xaab0
orl $0x2, %r14d
movl %r14d, 0x10(%rsp)
jmp 0x9f66
orl $0x40, %r14d
movl %r14d, 0x10(%rsp)
jmp 0x9f66
orl $0x400, %r14d           # imm = 0x400
movl %r14d, 0x10(%rsp)
jmp 0x9f66
orl $0x100, %r14d           # imm = 0x100
movl %r14d, 0x10(%rsp)
jmp 0x9f66
cmpl $0x3f, %eax
jne 0x9f66
jmp 0xa1eb
movq 0x38(%rsp), %r14
testq %r14, %r14
jne 0xa12e
leaq 0x2147(%rip), %rdi      # 0xc262
callq 0x2380
testq %rax, %rax
leaq 0x2148(%rip), %r14      # 0xc272
cmovneq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0xa25c
testl %eax, %eax
js 0xa204
leaq 0x8(%rsp), %rdi
movq (%rdi), %rax
movq %r14, %rsi
callq *0x18(%rax)
testl %eax, %eax
js 0xa20b
leaq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
testl %eax, %eax
js 0xa212
movq %rsp, %rdi
callq 0xac1c
testl %eax, %eax
js 0xa219
movq %rsp, %rdi
movq (%rdi), %rax
movq 0x6e22(%rip), %rcx      # 0x10fa8
movl (%rcx), %edx
movl %ebp, %esi
movq %rbx, %rcx
callq *0x10(%rax)
testl %eax, %eax
js 0xa227
testb $0x20, 0x11(%rsp)
je 0xa1b4
movq %rsp, %rdi
movq (%rdi), %rax
movl 0x2c(%rsp), %esi
callq *0x18(%rax)
testl %eax, %eax
js 0xa235
movq (%rsp), %rdi
callq *0x20(%rdi)
testl %eax, %eax
js 0xa22e
movq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq *0x28(%rdi)
movq 0x8(%rsp), %rdi
movq (%rsp), %r14
testq %rdi, %rdi
je 0xa1dd
callq *0x30(%rdi)
xorl %ebx, %ebx
jmp 0xa24b
callq 0xaa56
callq 0xaa08
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x2a8, %rsp            # imm = 0x2A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %ebx
jmp 0xa23a
movl $0x2, %ebx
jmp 0xa23a
movl $0x3, %ebx
jmp 0xa23a
movl $0x4, %ebx
jmp 0xa23a
callq 0x2634
jmp 0xa1eb
movl $0x5, %ebx
jmp 0xa23a
movl $0x7, %ebx
jmp 0xa23a
movl $0x6, %ebx
movq 0x8(%rsp), %rdi
movq (%rsp), %r14
testq %rdi, %rdi
je 0xa24b
callq *0x30(%rdi)
testq %r14, %r14
je 0xa1f0
movq %r14, %rdi
callq *0x28(%r14)
jmp 0xa1f0
nopl (%rax)