// File: /workspace/github_c_makefile_star2_O3/akumrao[P]videoAnalyzer/x264.c
// Function: main
int main( int argc, char **argv )
{
    x264_t *h;
    x264_param_t param;
    x264_picture_t *pic;

    FILE    *fyuv;
    FILE    *fh26l;
    FILE    *fout = stdout;

    char    *p;

    int     i_frame, i_frame_total;
    int64_t i_start, i_end;
    int64_t i_file;

    int     b_decompress = 0;

#ifdef _MSC_VER
    _setmode(_fileno(stdin), _O_BINARY);    /* thanks to Marcos Morais <morais at dee.ufcg.edu.br> */
    _setmode(_fileno(stdout), _O_BINARY);
#endif

    x264_param_default( &param );
    param.f_fps = 25.0;

    /* Parse command line options */
    opterr = 0; // no error message
    for( ;; )
    {
        int long_options_index;
        static struct option long_options[] =
        {
            { "help",    no_argument,       NULL, 'h' },
            { "bitrate", required_argument, NULL, 'b' },
            { "bframe",  required_argument, NULL, 'B' },
            { "iframe",  required_argument, NULL, 'i' },
            { "idrframe",  required_argument, NULL, 'I' },
            { "nf",      no_argument,       NULL, 'n' },
            { "cabac",   no_argument,       NULL, 'c' },
            { "qp",      required_argument, NULL, 'q' },
            { "ref",     required_argument, NULL, 'r' },
            { "no-asm",  no_argument,       NULL, 'C' },
            { "sar",     required_argument, NULL, 's' },
            { "output",  required_argument, NULL, 'o' },
            {0, 0, 0, 0}
        };

        int c;

        c = getopt_long( argc, argv, "hi:b:r:cxB:m:q:no:s:",
                         long_options, &long_options_index);

        if( c == -1 )
        {
            break;
        }

        switch( c )
        {
            case 0:
                break;
            case 'h':
                help();
                return 0;
            case 'b':
                param.i_bitrate = atol( optarg );
                break;
            case 'B':
                param.i_bframe = atol( optarg );
                break;
            case 'i':
                param.i_iframe = atol( optarg );
                break;
            case 'I':
                param.i_idrframe = atol( optarg );
                break;
            case 'n':
                param.b_deblocking_filter = 0;
                break;
            case 'q':
                param.i_qp_constant = atoi( optarg );
                break;
            case 'r':
                param.i_frame_reference = atoi( optarg );
                break;
            case 'c':
                param.b_cabac = 1;
                break;
            case 'm':
                param.i_me = atoi( optarg );
                break;
            case 'x':
                b_decompress = 1;
                break;
            case 'C':
                param.cpu = 0;
                break;
            case'o':
                if( ( fout = fopen( optarg, "wb" ) ) == NULL )
                {
                    fprintf( stderr, "cannot open output file `%s'\n", optarg );
                    return -1;
                }
                break;
            case 's':
            {
                char *p = strchr( optarg, ':' );
                if( p )
                {
                    param.vui.i_sar_width = atoi( optarg );
                    param.vui.i_sar_height = atoi( p + 1 );
                }
                break;
            }
            default:
                fprintf( stderr, "unknown option (%c)\n", optopt );
                return -1;
        }
    }

    /* Control-C handler */
    signal( SIGINT, SigIntHandler );

    if( b_decompress )
    {
        x264_nal_t nal;
        int i_data;
        int b_eof;

        if( optind > argc - 1 )
        {
            help();
            return -1;
        }

        if( !strcmp( argv[optind], "-" ) )
        {
            fh26l = stdin;
            optind++;
        }
        else if( ( fh26l = fopen( argv[optind++], "rb" ) ) == NULL )
        {
            fprintf( stderr, "could not open h26l file '%s'\n", argv[optind - 1] );
            return -1;
        }

        //param.cpu = 0;
        if( ( h = x264_decoder_open( &param ) ) == NULL )
        {
            fprintf( stderr, "x264_decoder_open failed\n" );
            return -1;
        }

        i_start = x264_mdate();
        b_eof = 0;
        i_frame = 0;
        i_data  = 0;
        nal.p_payload = (uint8_t*)x264_malloc( DATA_MAX );

        while( !i_ctrl_c )
        {
            uint8_t *p, *p_next, *end;
            int i_size;
            /* fill buffer */
            if( i_data < DATA_MAX && !b_eof )
            {
                int i_read = fread( &data[i_data], 1, DATA_MAX - i_data, fh26l );
                if( i_read <= 0 )
                {
                    b_eof = 1;
                }
                else
                {
                    i_data += i_read;
                }
            }

            if( i_data < 3 )
            {
                break;
            }

            end = &data[i_data];

            /* extract one nal */
            p = &data[0];
            while( p < end - 3 )
            {
                if( p[0] == 0x00 && p[1] == 0x00 && p[2] == 0x01 )
                {
                    break;
                }
                p++;
            }

            if( p >= end - 3 )
            {
                fprintf( stderr, "garbage (i_data = %d)\n", i_data );
                i_data = 0;
                continue;
            }

            p_next = p + 3;
            while( p_next < end - 3 )
            {
                if( p_next[0] == 0x00 && p_next[1] == 0x00 && p_next[2] == 0x01 )
                {
                    break;
                }
                p_next++;
            }

            if( p_next == end - 3 && i_data < DATA_MAX )
            {
                p_next = end;
            }

            /* decode this nal */
            i_size = p_next - p - 3;
            if( i_size <= 0 )
            {
                if( b_eof )
                {
                    break;
                }
                fprintf( stderr, "nal too large (FIXME) ?\n" );
                i_data = 0;
                continue;
            }

            x264_nal_decode( &nal, p +3, i_size );

            /* decode the content of the nal */
            x264_decoder_decode( h, &pic, &nal );

            if( pic != NULL )
            {
                int i;

                i_frame++;

                for( i = 0; i < pic->i_plane;i++ )
                {
                    int i_line;
                    int i_div;

                    i_div = i==0 ? 1 : 2;
                    for( i_line = 0; i_line < pic->i_height/i_div; i_line++ )
                    {
                        fwrite( pic->plane[i]+i_line*pic->i_stride[i], 1, pic->i_width/i_div, fout );
                        dumpByte( pic->plane[i]+i_line*pic->i_stride[i], pic->i_width/i_div, 1    );
                        
                    }
                }
            }

            memmove( &data[0], p_next, end - p_next );
            i_data -= p_next - &data[0];
        }

        i_end = x264_mdate();
        free( nal.p_payload );
        fprintf( stderr, "\n" );

        x264_decoder_close( h );

        fclose( fh26l );
        if( fout != stdout )
        {
            fclose( fout );
        }
        if( i_frame > 0 )
        {
            double fps = (double)i_frame * (double)1000000 /
                         (double)( i_end - i_start );
            fprintf( stderr, "decoded %d frames %ffps\n", i_frame, fps );
        }
    }
    else
    {
        if( optind > argc - 2 )
        {
            help();
            return -1;
        }

        /* init params */
        if( !strcmp( argv[optind], "-" ) )
        {
            fyuv = stdin;
            optind++;
        }
        else if( ( fyuv = fopen( argv[optind++], "rb" ) ) == NULL )
        {
            fprintf( stderr, "could not open yuv input file '%s'\n", argv[optind - 1] );
            return -1;
        }

        param.i_width           = strtol( argv[optind++], &p, 0 );
        param.i_height          = strtol( p+1, &p, 0 );

        i_frame_total = 0;
        if( !fseek( fyuv, 0, SEEK_END ) )
        {
            int64_t i_size = ftell( fyuv );
            fseek( fyuv, 0, SEEK_SET );
            i_frame_total = i_size / ( param.i_width * param.i_height * 3 / 2 );
        }

        if( ( h = x264_encoder_open( &param ) ) == NULL )
        {
            fprintf( stderr, "x264_encoder_open failed\n" );
            return -1;
        }

        pic = x264_picture_new( h );

        i_start = x264_mdate();
        for( i_frame = 0, i_file = 0; i_ctrl_c == 0 ; i_frame++ )
        {
            int         i_nal;
            x264_nal_t  *nal;

            int         i;

           /* i420  =   y = w*h
                      u = w*h/4
                      v = w*h/4  
            */
            
            //fillByte(pic->plane[0],  param.i_width , param.i_height);
            ///* read a frame
            if( fread( pic->plane[0], 1, param.i_width * param.i_height, fyuv ) <= 0 ||
                fread( pic->plane[1], 1, param.i_width * param.i_height / 4, fyuv ) <= 0 ||
                fread( pic->plane[2], 1, param.i_width * param.i_height / 4, fyuv ) <= 0 )
            {
                break;
            }
            
           // if(i_frame == 16 ) break; //arvind
            
            if( x264_encoder_encode( h, &nal, &i_nal, pic ) < 0 )
            {
                fprintf( stderr, "x264_encoder_encode failed\n" );
            }

            for( i = 0; i < i_nal; i++ )
            {
                int i_size;
                int i_data;

                i_data = DATA_MAX;
                if( ( i_size = x264_nal_encode( data, &i_data, 1, &nal[i] ) ) > 0 )
                {
                    i_file += fwrite( data, 1, i_size, fout );
                }
                else if( i_size < 0 )
                {
                    fprintf( stderr,
                             "need to increase buffer size (size=%d)\n", -i_size );
                }
            }
        }
        i_end = x264_mdate();
        x264_picture_delete( pic );
        x264_encoder_close( h );
        fprintf( stderr, "\n" );

        fclose( fyuv );
        if( fout != stdout )
        {
            fclose( fout );
        }

        if( i_frame > 0 )
        {
            double fps = (double)i_frame * (double)1000000 /
                         (double)( i_end - i_start );

            fprintf( stderr, "encoded %d frames %ffps %lld kb/s\n", i_frame, fps, i_file * 8 * 25 / i_frame / 1000 );
        }
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, %r15
movl %edi, %r14d
movq 0x2fef8(%rip), %rax     # 0x32fa0
movq (%rax), %rax
movq %rax, -0x40(%rbp)
leaq -0xa8(%rbp), %rbx
movq %rbx, %rdi
callq 0x2427
movl $0x41c80000, 0x14(%rbx) # imm = 0x41C80000
movq 0x2ff14(%rip), %rax     # 0x32fe0
movl $0x0, (%rax)
movl $0x0, -0x38(%rbp)
leaq 0x1ffc1(%rip), %r12     # 0x230a1
leaq 0x30029(%rip), %r13     # 0x33110
leaq 0x1ff16(%rip), %rbx     # 0x23004
movl %r14d, %edi
movq %r15, %rsi
movq %r12, %rdx
movq %r13, %rcx
leaq -0xe0(%rbp), %r8
callq 0x21d0
cmpl $0x42, %eax
jle 0x3130
leal -0x62(%rax), %ecx
cmpl $0x16, %ecx
ja 0x3154
movslq (%rbx,%rcx,4), %rax
addq %rbx, %rax
jmpq *%rax
movq 0x2fe8d(%rip), %rax     # 0x32fb0
movq (%rax), %rdi
callq 0x2120
movl %eax, -0x70(%rbp)
jmp 0x30ee
testl %eax, %eax
je 0x30ee
cmpl $0x42, %eax
jne 0x328e
movq 0x2fe6c(%rip), %rax     # 0x32fb0
movq (%rax), %rdi
callq 0x2120
movl %eax, -0x84(%rbp)
jmp 0x30ee
cmpl $0x43, %eax
je 0x327f
cmpl $0x49, %eax
jne 0x38dd
movq 0x2fe43(%rip), %rax     # 0x32fb0
movq (%rax), %rdi
callq 0x2120
movl %eax, -0x8c(%rbp)
jmp 0x30ee
movq 0x2fe29(%rip), %rax     # 0x32fb0
movq (%rax), %r13
movq %r13, %rdi
movl $0x3a, %esi
callq 0x2050
testq %rax, %rax
je 0x31be
movq %rax, %r12
movq %r13, %rdi
callq 0x2190
movl %eax, -0x98(%rbp)
incq %r12
movq %r12, %rdi
callq 0x2190
movl %eax, -0x9c(%rbp)
leaq 0x1fedc(%rip), %r12     # 0x230a1
leaq 0x2ff44(%rip), %r13     # 0x33110
jmp 0x30ee
movl $0x1, -0x38(%rbp)
jmp 0x30ee
movl $0x1, -0x7c(%rbp)
jmp 0x30ee
movq 0x2fdc0(%rip), %rax     # 0x32fb0
movq (%rax), %rdi
callq 0x2120
movl %eax, -0x88(%rbp)
jmp 0x30ee
movl $0x0, -0x80(%rbp)
jmp 0x30ee
movq 0x2fd9a(%rip), %rax     # 0x32fb0
movq (%rax), %rdi
callq 0x2190
movl %eax, -0x90(%rbp)
jmp 0x30ee
movq 0x2fd80(%rip), %rax     # 0x32fb0
movq (%rax), %rdi
callq 0x2190
movl %eax, -0x6c(%rbp)
jmp 0x30ee
movq 0x2fd69(%rip), %rax     # 0x32fb0
movq (%rax), %rdi
leaq 0x1fe65(%rip), %rsi     # 0x230b6
callq 0x20f0
movq %rax, -0x40(%rbp)
testq %rax, %rax
jne 0x30ee
jmp 0x391d
movq 0x2fd41(%rip), %rax     # 0x32fb0
movq (%rax), %rdi
callq 0x2190
movl %eax, -0x74(%rbp)
jmp 0x30ee
movl $0x0, -0xa8(%rbp)
jmp 0x30ee
cmpl $-0x1, %eax
jne 0x38dd
leaq 0x6cc(%rip), %rsi       # 0x396a
movl $0x2, %edi
callq 0x2100
cmpl $0x0, -0x38(%rbp)
je 0x3396
movq 0x2fd1f(%rip), %rax     # 0x32fd8
movslq (%rax), %rcx
cmpl %r14d, %ecx
jge 0x38e4
movq (%r15,%rcx,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x32d8
cmpb $0x0, 0x1(%rdi)
je 0x38b9
incl %ecx
movl %ecx, (%rax)
leaq 0x1fe09(%rip), %rsi     # 0x230ec
callq 0x20f0
movq %rax, %r14
testq %rax, %rax
je 0x3909
leaq -0xa8(%rbp), %rdi
callq 0xb778
testq %rax, %rax
je 0x38eb
movq %rax, %r15
callq 0x9d14
movq %rax, -0xb8(%rbp)
movl $0x2dc6c0, %edi         # imm = 0x2DC6C0
callq 0x467e
movq %rax, -0xd0(%rbp)
xorl %r12d, %r12d
cmpb $0x0, 0x30c64d(%rip)    # 0x30f980
je 0x34eb
callq 0x9d14
movq %rax, %rbx
movq -0xd0(%rbp), %rdi
callq 0x2110
movq 0x2fc7c(%rip), %rax     # 0x32fd0
movq (%rax), %rsi
movl $0xa, %edi
callq 0x2130
movq %r15, %rdi
callq 0xdab7
movq %r14, %rdi
callq 0x20b0
movq -0x40(%rbp), %rdi
movq 0x2fc24(%rip), %rax     # 0x32fa0
cmpq (%rax), %rdi
je 0x3386
callq 0x20b0
testl %r12d, %r12d
jg 0x38f2
xorl %ebx, %ebx
jmp 0x3956
movq 0x2fc3b(%rip), %rbx     # 0x32fd8
movslq (%rbx), %rax
addl $-0x2, %r14d
cmpl %r14d, %eax
jg 0x3924
movq (%r15,%rax,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x33c0
cmpb $0x0, 0x1(%rdi)
je 0x38cc
incl %eax
movl %eax, (%rbx)
leaq 0x1fd21(%rip), %rsi     # 0x230ec
callq 0x20f0
movq %rax, %r14
movl (%rbx), %eax
testq %r14, %r14
je 0x3932
leal 0x1(%rax), %ecx
movl %ecx, (%rbx)
cltq
movq (%r15,%rax,8), %rdi
leaq -0xe0(%rbp), %rbx
movq %rbx, %rsi
xorl %edx, %edx
callq 0x2160
movl %eax, -0xa4(%rbp)
movq (%rbx), %rdi
incq %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x2160
movl %eax, -0xa0(%rbp)
movq %r14, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x20c0
testl %eax, %eax
jne 0x343d
movq %r14, %rdi
callq 0x2030
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x20c0
leaq -0xa8(%rbp), %rdi
callq 0x14518
testq %rax, %rax
je 0x392b
movq %rax, -0x50(%rbp)
movq %rax, %rdi
callq 0x4520
movq %rax, -0x30(%rbp)
callq 0x9d14
movq %rax, -0x58(%rbp)
cmpb $0x0, 0x30c50e(%rip)    # 0x30f980
je 0x3751
xorl %r13d, %r13d
xorl %r12d, %r12d
callq 0x9d14
movq %rax, %r15
movq -0x30(%rbp), %rdi
callq 0x4630
movq -0x50(%rbp), %rdi
callq 0x2af5
movq 0x2fb31(%rip), %rax     # 0x32fd0
movq (%rax), %rsi
movl $0xa, %edi
callq 0x2130
movq %r14, %rdi
callq 0x20b0
movq -0x40(%rbp), %rdi
movq 0x2fae1(%rip), %rax     # 0x32fa0
cmpq (%rax), %rdi
je 0x34c9
callq 0x20b0
xorl %ebx, %ebx
testl %r12d, %r12d
je 0x3956
movl %r12d, %edi
movq %r15, %rsi
movq -0x58(%rbp), %rdx
movq %r13, %rcx
callq 0x2362
jmp 0x3956
leaq 0x2fdce(%rip), %rax     # 0x332c0
negl %eax
movq %rax, -0x58(%rbp)
xorl %r12d, %r12d
xorl %edi, %edi
xorl %ebx, %ebx
movq %r14, -0xb0(%rbp)
movq %r15, -0xc0(%rbp)
cmpl $0x2dc6bf, %ebx         # imm = 0x2DC6BF
jg 0x354e
testl %edi, %edi
jne 0x354e
movslq %ebx, %rdi
leaq 0x2fd9d(%rip), %rax     # 0x332c0
addq %rax, %rdi
movl $0x2dc6c0, %edx         # imm = 0x2DC6C0
subl %ebx, %edx
movl $0x1, %esi
movq %r14, %rcx
callq 0x2180
xorl %edi, %edi
testl %eax, %eax
setle %dil
movl $0x0, %ecx
cmovlel %ecx, %eax
addl %ebx, %eax
movl %eax, %ebx
cmpl $0x3, %ebx
jl 0x3339
movl %ebx, %r13d
leaq 0x2fd5f(%rip), %rax     # 0x332c0
leaq (%rax,%r13), %rcx
addq $-0x3, %rcx
cmpq %rax, %rcx
movl %edi, -0x38(%rbp)
jbe 0x35a5
leaq 0x2fd48(%rip), %rax     # 0x332c0
leaq (%rax,%r13), %r8
movl $0x3, %eax
leaq 0x2fd3b(%rip), %rsi     # 0x332c3
cmpb $0x0, -0x3(%rsi)
jne 0x359a
cmpb $0x0, -0x2(%rsi)
jne 0x359a
cmpb $0x1, -0x1(%rsi)
je 0x35c7
incq %rsi
incq %rax
cmpq %rax, %r13
jne 0x3588
movq 0x2fa24(%rip), %rax     # 0x32fd0
movq (%rax), %rdi
xorl %ebx, %ebx
leaq 0x1fb70(%rip), %rsi     # 0x23128
movl %r13d, %edx
xorl %eax, %eax
callq 0x2170
jmp 0x373c
movq %rsi, %rdx
cmpq %rcx, %rsi
jae 0x35ee
movq %rsi, %rdx
cmpb $0x0, (%rdx)
jne 0x35e3
cmpb $0x0, 0x1(%rdx)
jne 0x35e3
cmpb $0x1, 0x2(%rdx)
je 0x35ee
incq %rdx
cmpq %rcx, %rdx
jb 0x35d2
movq %rcx, %rdx
cmpq %rcx, %rdx
movq %rdx, %r9
cmoveq %r8, %r9
cmpl $0x2dc6c0, %r13d        # imm = 0x2DC6C0
cmovgeq %rdx, %r9
movq -0x58(%rbp), %rcx
movq %r9, -0x50(%rbp)
leaq (%rcx,%r9), %rdx
subq %rax, %rdx
testl %edx, %edx
jle 0x372d
movq %r8, -0x60(%rbp)
leaq -0xe0(%rbp), %rbx
movq %rbx, %rdi
callq 0xb6bc
movq %r15, %rdi
leaq -0x30(%rbp), %rsi
movq %rbx, %rdx
callq 0xb990
movq -0x30(%rbp), %rcx
testq %rcx, %rcx
je 0x36f5
incl %r12d
cmpl $0x0, 0x8(%rcx)
jle 0x36f5
movl %r12d, -0x64(%rbp)
xorl %r15d, %r15d
cmpq $0x1, %r15
movl $0x2, %r14d
sbbl $0x0, %r14d
movl 0x4(%rcx), %eax
cltd
idivl %r14d
testl %eax, %eax
jle 0x36d8
xorl %ebx, %ebx
movq -0x40(%rbp), %r12
movslq 0xc(%rcx,%r15,4), %rdi
movslq %ebx, %rbx
imulq %rbx, %rdi
addq 0x20(%rcx,%r15,8), %rdi
movl (%rcx), %eax
cltd
idivl %r14d
movslq %eax, %rdx
movl $0x1, %esi
movq %r12, %rcx
callq 0x21e0
movq -0x30(%rbp), %rax
movslq 0xc(%rax,%r15,4), %rdi
imulq %rbx, %rdi
addq 0x20(%rax,%r15,8), %rdi
movl (%rax), %eax
cltd
idivl %r14d
movl %eax, %esi
movl $0x1, %edx
callq 0x4bf5
incl %ebx
movq -0x30(%rbp), %rcx
movl 0x4(%rcx), %eax
cltd
idivl %r14d
cmpl %eax, %ebx
jl 0x367c
incq %r15
movslq 0x8(%rcx), %rax
cmpq %rax, %r15
jl 0x365d
movq -0xb0(%rbp), %r12
movl -0x64(%rbp), %r15d
jmp 0x36fb
movl %r12d, %r15d
movq %r14, %r12
movq -0x60(%rbp), %rdx
movq -0x50(%rbp), %r14
subq %r14, %rdx
leaq 0x2fbb3(%rip), %rbx     # 0x332c0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x21b0
addl %r13d, %ebx
subl %r14d, %ebx
movq %r12, %r14
movl %r15d, %r12d
movq -0xc0(%rbp), %r15
jmp 0x373c
testl %edi, %edi
jne 0x3339
callq 0x22a0
xorl %ebx, %ebx
cmpb $0x1, 0x30c23d(%rip)    # 0x30f980
movl -0x38(%rbp), %edi
jne 0x350d
jmp 0x3339
xorl %r12d, %r12d
leaq 0x2fb65(%rip), %rbx     # 0x332c0
leaq -0x68(%rbp), %r15
xorl %r13d, %r13d
movq %r14, -0x60(%rbp)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rdi
movslq -0xa4(%rbp), %rax
movslq -0xa0(%rbp), %rdx
imulq %rax, %rdx
movl $0x1, %esi
movq %r14, %rcx
callq 0x2180
testq %rax, %rax
je 0x347e
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rdi
movl -0xa0(%rbp), %eax
imull -0xa4(%rbp), %eax
leal 0x3(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x2, %ecx
movslq %ecx, %rdx
movl $0x1, %esi
movq %r14, %rcx
callq 0x2180
testq %rax, %rax
je 0x347e
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rdi
movl -0xa0(%rbp), %eax
imull -0xa4(%rbp), %eax
leal 0x3(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x2, %ecx
movslq %ecx, %rdx
movl $0x1, %esi
movq %r14, %rcx
callq 0x2180
testq %rax, %rax
je 0x347e
movq -0x30(%rbp), %rcx
movq -0x50(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
leaq -0x44(%rbp), %rdx
callq 0x14c02
testl %eax, %eax
js 0x38af
movq %r12, -0x38(%rbp)
cmpl $0x0, -0x44(%rbp)
jle 0x3892
xorl %r14d, %r14d
xorl %r12d, %r12d
movl $0x2dc6c0, -0x68(%rbp)  # imm = 0x2DC6C0
movq -0xc8(%rbp), %rcx
addq %r14, %rcx
movq %rbx, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x1485e
testl %eax, %eax
jle 0x3875
movl %eax, %edx
movl $0x1, %esi
movq %rbx, %rdi
movq -0x40(%rbp), %rcx
callq 0x21e0
addq %rax, %r13
jmp 0x3877
js 0x3889
incq %r12
movslq -0x44(%rbp), %rax
addq $0x18, %r14
cmpq %rax, %r12
jl 0x3838
jmp 0x3892
movl %eax, %edi
callq 0x2340
jmp 0x3877
movq -0x38(%rbp), %r12
incl %r12d
cmpb $0x1, 0x30c0e0(%rip)    # 0x30f980
movq -0x60(%rbp), %r14
jne 0x3766
jmp 0x347e
callq 0x231e
jmp 0x3828
movq 0x2f700(%rip), %rdx     # 0x32fc0
movq (%rdx), %r14
incl %ecx
movl %ecx, (%rax)
jmp 0x32f4
movq 0x2f6ed(%rip), %rcx     # 0x32fc0
movq (%rcx), %r14
incl %eax
jmp 0x33de
callq 0x2400
jmp 0x3951
callq 0x224c
jmp 0x3951
callq 0x22fc
jmp 0x3951
movl %r12d, %edi
movq %rbx, %rsi
movq -0xb8(%rbp), %rdx
callq 0x22c2
jmp 0x338f
movq %r15, %rdi
callq 0x2270
jmp 0x3951
callq 0x2228
jmp 0x338f
callq 0x2200
jmp 0x3951
callq 0x23dc
jmp 0x3951
callq 0x23ba
jmp 0x3951
cltq
movq 0x2f695(%rip), %rcx     # 0x32fd0
movq (%rcx), %rdi
movq -0x8(%r15,%rax,8), %rdx
leaq 0x1f827(%rip), %rsi     # 0x23171
xorl %eax, %eax
callq 0x2170
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq