// File: /workspace/github_c_makefile_star2_O2/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
leaq 0x34(%rsp), %rax
andl $0x0, (%rax)
movl %edi, %ebp
andq $0x0, 0x8(%rsp)
andq $0x0, (%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
leaq 0x79d2(%rip), %rsi      # 0x10b30
leaq 0x40(%rsp), %r13
movl $0x260, %edx            # imm = 0x260
movq %r13, %rdi
callq 0x2470
xorl %r12d, %r12d
leaq 0x2076(%rip), %r14      # 0xb1f0
leaq 0x1f93(%rip), %r15      # 0xb114
movl $0x0, 0x2c(%rsp)
movq $0x0, 0x38(%rsp)
movl %ebp, 0x30(%rsp)
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
movq %r13, %rcx
leaq 0x34(%rsp), %r8
callq 0x2370
leal -0x62(%rax), %ecx
cmpl $0x17, %ecx
ja 0x91ce
leaq 0x1f6e(%rip), %rdx      # 0xb128
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
orl $0x8, %r12d
movl %r12d, 0x10(%rsp)
jmp 0x9196
leal 0x1(%rax), %ecx
cmpl $0x4, %ecx
jbe 0x91f2
cmpl $0x52, %eax
je 0x92b8
cmpl $0x54, %eax
je 0x930a
cmpl $0x3f, %eax
jne 0x9196
jmp 0x9400
movslq (%r15,%rcx,4), %rax
addq %r15, %rax
jmpq *%rax
orl $0x4, %r12d
movl %r12d, 0x10(%rsp)
jmp 0x9196
orl $0x20, %r12d
movl %r12d, 0x10(%rsp)
jmp 0x9196
orl $0x200, %r12d           # imm = 0x200
movl %r12d, 0x10(%rsp)
jmp 0x9196
orl $0x800, %r12d           # imm = 0x800
movl %r12d, 0x10(%rsp)
movq 0x7d93(%rip), %rax      # 0x10fc8
movq (%rax), %rax
movq %rax, 0x18(%rsp)
jmp 0x9196
movq 0x7d7f(%rip), %rax      # 0x10fc8
movq (%rax), %rax
movq %rax, 0x38(%rsp)
jmp 0x9196
orl $0x80, %r12d
movl %r12d, 0x10(%rsp)
jmp 0x9196
orl $0x10, %r12d
movl %r12d, 0x10(%rsp)
jmp 0x9196
callq 0x9d64
orl $0x2, %r12d
movl %r12d, 0x10(%rsp)
jmp 0x9196
orl $0x40, %r12d
movl %r12d, 0x10(%rsp)
jmp 0x9196
orl $0x400, %r12d           # imm = 0x400
movl %r12d, 0x10(%rsp)
jmp 0x9196
orl $0x100, %r12d           # imm = 0x100
movl %r12d, 0x10(%rsp)
jmp 0x9196
movq %rbx, %rbp
movq %r15, %rbx
movq %r14, %r15
movq %r13, %r14
orl $0x2000, %r12d          # imm = 0x2000
movl %r12d, 0x10(%rsp)
movq 0x7cf1(%rip), %r13      # 0x10fc8
movq (%r13), %rdi
callq 0x5120
testl %eax, %eax
js 0x9415
movq (%r13), %rdi
callq 0x22f0
movl %eax, 0x2c(%rsp)
movq %r14, %r13
movq %r15, %r14
movq %rbx, %r15
movq %rbp, %rbx
movl 0x30(%rsp), %ebp
jmp 0x9196
orl $0x1000, %r12d          # imm = 0x1000
movl %r12d, 0x10(%rsp)
movq 0x7cab(%rip), %rax      # 0x10fc8
movq (%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x9196
movq 0x38(%rsp), %r14
testq %r14, %r14
jne 0x934e
leaq 0x1eeb(%rip), %rdi      # 0xb226
callq 0x2380
testq %rax, %rax
leaq 0x1eec(%rip), %r14      # 0xb236
cmovneq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x9484
testl %eax, %eax
js 0x9405
leaq 0x8(%rsp), %rdi
movq (%rdi), %rax
movq %r14, %rsi
callq *0x18(%rax)
testl %eax, %eax
js 0x9409
leaq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
testl %eax, %eax
js 0x940d
movq %rsp, %rdi
callq 0x9edc
testl %eax, %eax
js 0x9411
movq %rsp, %rdi
movq (%rdi), %rax
movq 0x7c06(%rip), %rcx      # 0x10fa8
movl (%rcx), %edx
movl %ebp, %esi
movq %rbx, %rcx
callq *0x10(%rax)
testl %eax, %eax
js 0x943a
testb $0x20, 0x11(%rsp)
je 0x93cc
movq %rsp, %rdi
movq (%rdi), %rax
movl 0x2c(%rsp), %esi
callq *0x18(%rax)
testl %eax, %eax
js 0x9442
movq (%rsp), %rdi
callq *0x20(%rdi)
testl %eax, %eax
js 0x943e
movq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq *0x28(%rdi)
movq 0x8(%rsp), %rdi
movq (%rsp), %rsi
callq 0x9467
xorl %ebx, %ebx
jmp 0x9453
callq 0x9d12
callq 0x9ccc
pushq $-0x1
popq %rbx
jmp 0x9453
pushq $0x1
jmp 0x9444
pushq $0x2
jmp 0x9444
pushq $0x3
jmp 0x9444
pushq $0x4
jmp 0x9444
movq 0x7bc4(%rip), %rax      # 0x10fe0
movq (%rax), %rdi
movq (%r13), %rcx
leaq 0x1dd9(%rip), %rsi      # 0xb203
leaq 0x1dec(%rip), %rdx      # 0xb21d
xorl %eax, %eax
callq 0x2450
jmp 0x9400
pushq $0x5
jmp 0x9444
pushq $0x7
jmp 0x9444
pushq $0x6
popq %rbx
movq 0x8(%rsp), %rdi
movq (%rsp), %rsi
callq 0x9467
movl %ebx, %eax
addq $0x2a8, %rsp            # imm = 0x2A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq