// File: /workspace/github_c_makefile_star2_O3/lecram[P]congif/main.c
// Function: convert_script
int
convert_script()
{
    FILE *ft;
    int fd;
    float t;
    int n;
    uint8_t ch;
    Font *font;
    int w, h;
    int i, c;
    float d;
    uint16_t rd, id = 0;
    float lastdone, done;
    char pb[options.barsize+1];
    char fl[512];
    int fln = 0;
    GIF *gif;
    Term *term;

    ft = fopen(options.timings, "r");
    if (!ft) {
        fprintf(stderr, "error: could not load timings: %s\n", options.timings);
        goto no_ft;
    }
    fd = open(options.dialogue, O_RDONLY);
    if (fd == -1) {
        fprintf(stderr, "error: could not load dialogue: %s\n", options.dialogue);
        goto no_fd;
    }
    if (options.font == 0) {
	font = default_font;
    } else {
	font = load_font(options.font);
	if (!font) {
	    fprintf(stderr, "error: could not load font: %s\n", options.font);
	    goto no_font;
	}
    }

    /* Save first line of dialogue */
    do {
        if (read(fd, &ch, 1) <= 0) break;
        if (fln<(int)sizeof(fl)-1) fl[fln++]=ch;
    } while (ch != '\n');
    /* Inspect it for the terminal size if needed */
    if (fln > 16 && (options.height == 0 || options.width == 0)) {
        int col=0, ln=0;
        char * s;
        fl[fln] = 0;
        s = strstr(fl, "COLUMNS=\"");
        if (s) col = atoi(s+9);
        s = strstr(fl, "LINES=\"");
        if (s) ln = atoi(s+7);

        if (ln>0 && col>0) {
            if (options.width <= 0)
                options.width = col;
            if (options.height <= 0)
                options.height = ln;
        }
    }

    /* Default the VT to our real terminal */
    if (options.has_winsize && (options.height == 0 || options.width == 0)) {
        if (options.height <= 0)
            options.height = options.size.ws_row;
        if (options.width <= 0)
            options.width = options.size.ws_col;
    }

    if (options.width <= 0 || options.height <= 0) {
        fprintf(stderr, "error: no terminal size specified\n");
        goto no_termsize;
    }

    term = new_term(options.height, options.width);
    w = term->cols * font->header.w;
    h = term->rows * font->header.h;
    gif = new_gif(options.output, w, h, term->plt, options.loop);
    if (!gif) {
        fprintf(stderr, "error: could not create GIF: %s\n", options.output);
        goto no_gif;
    }
    if (options.barsize) {
        pb[0] = '[';
        pb[options.barsize-1] = ']';
        pb[options.barsize] = '\0';
        for (i = 1; i < options.barsize-1; i++)
            pb[i] = '-';
        lastdone = 0;
        printf("%s\r[", pb);
        /* get number of chunks */
        for (c = 0; fscanf(ft, "%f %d\n", &t, &n) == 2; c++);
        rewind(ft);
    }
    i = 0;
    d = rd = 0;
    while (fscanf(ft, "%f %d\n", &t, &n) == 2) {
        if (options.barsize) {
            done = i * (options.barsize-1) / c;
            if (done > lastdone) {
                while (done > lastdone) {
                    putchar('#');
                    lastdone++;
                }
                fflush(stdout);
            }
        }
        d += (MIN(t, options.maxdelay) * 100.0 / options.divisor);
        rd = (uint16_t) MIN((int)(d + 0.5), 65535);
        if (i && rd >= MIN_DELAY) {
            render(term, font, gif, rd);
            d = 0;
        }
        if (i == 0) { id = rd; rd = 0; d = 0; }
        while (n--) {
            read(fd, &ch, 1);
            parse(term, ch);
        }
        if (!options.cursor)
            term->mode &= ~M_CURSORVIS;
        i++;
    }
    rd += id;
    if (options.barsize) {
        while (lastdone < options.barsize-2) {
            putchar('#');
            lastdone++;
        }
        putchar('\n');
    }
    render(term, font, gif, MAX(rd, 1));
    close_gif(gif);
    free(term);
    return 0;
no_gif:
    free(term);
no_termsize:
    if (options.font) free(font);
no_font:
    close(fd);
no_fd:
    fclose(ft);
no_ft:
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movq %rsp, %r15
movl 0x8a1c(%rip), %eax      # 0xc3b8
incl %eax
movq %rsp, %rbx
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %rbx
movq %rbx, %rsp
movq 0x89c2(%rip), %rdi      # 0xc378
leaq 0x1e36(%rip), %rsi      # 0x57f3
callq 0x1190
testq %rax, %rax
je 0x3ec9
movq %rax, %r14
movq %r15, -0x60(%rbp)
movq 0x89a7(%rip), %rdi      # 0xc380
xorl %esi, %esi
xorl %eax, %eax
callq 0x1180
cmpl $-0x1, %eax
je 0x3ed8
movl %eax, %r15d
movq 0x89ab(%rip), %rdi      # 0xc3a0
testq %rdi, %rdi
je 0x3a12
callq 0x2e70
movq %rax, -0x48(%rbp)
testq %rax, %rax
jne 0x3a1d
callq 0x12dd
jmp 0x3f01
leaq 0x8937(%rip), %rax      # 0xc350
movq %rax, -0x48(%rbp)
movq %r14, -0x50(%rbp)
xorl %r14d, %r14d
leaq -0x29(%rbp), %r12
movl $0x1, %edx
movl %r15d, %edi
movq %r12, %rsi
callq 0x10f0
testq %rax, %rax
jle 0x3a5a
movb -0x29(%rbp), %al
cmpl $0x1fe, %r14d           # imm = 0x1FE
jg 0x3a56
movslq %r14d, %rcx
incl %r14d
movb %al, -0x280(%rbp,%rcx)
cmpb $0xa, %al
jne 0x3a28
movl 0x894b(%rip), %r12d     # 0xc3ac
movl 0x8940(%rip), %r13d     # 0xc3a8
cmpl $0x11, %r14d
jl 0x3abc
testl %r13d, %r13d
sete %al
testl %r12d, %r12d
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x3abc
movl %r14d, %eax
movb $0x0, -0x280(%rbp,%rax)
leaq 0x2078(%rip), %rsi      # 0x5b0b
leaq -0x280(%rbp), %rdi
callq 0x1210
testq %rax, %rax
je 0x3e59
addq $0x9, %rax
movq %rax, %rdi
callq 0x11c0
movl %eax, -0x30(%rbp)
jmp 0x3e60
movq -0x50(%rbp), %r14
cmpl $0x0, 0x88f5(%rip)      # 0xc3bc
je 0x3afb
testl %r13d, %r13d
je 0x3ad3
testl %r12d, %r12d
jne 0x3afb
testl %r13d, %r13d
jg 0x3ae7
movzwl 0x88e0(%rip), %r13d     # 0xc3c0
movl %r13d, 0x88c1(%rip)     # 0xc3a8
testl %r12d, %r12d
jg 0x3afb
movzwl 0x88ce(%rip), %r12d     # 0xc3c2
movl %r12d, 0x88b1(%rip)     # 0xc3ac
testl %r12d, %r12d
jle 0x3edf
testl %r13d, %r13d
jle 0x3edf
movl %r13d, %edi
movl %r12d, %esi
callq 0x16fb
movq %rax, %r12
movq -0x48(%rbp), %rax
movzbl 0x2(%rax), %esi
imull 0x4(%r12), %esi
movzbl 0x3(%rax), %edx
imull (%r12), %edx
movq 0x884f(%rip), %rdi      # 0xc388
leaq 0x16c(%r12), %rcx
movl 0x8850(%rip), %r8d      # 0xc398
movl $0xffff, %eax           # imm = 0xFFFF
andl %eax, %esi
andl %eax, %edx
callq 0x3014
movq %rax, -0x78(%rbp)
testq %rax, %rax
je 0x3ee6
movslq 0x884e(%rip), %rdx      # 0xc3b8
testq %rdx, %rdx
movl %r15d, -0x54(%rbp)
je 0x3bdd
movb $0x5b, (%rbx)
movw $0x5d, -0x1(%rbx,%rdx)
cmpl $0x3, %edx
jl 0x3b93
leaq 0x1(%rbx), %rdi
addl $-0x2, %edx
movl $0x2d, %esi
callq 0x10c0
leaq 0x1fc7(%rip), %rdi      # 0x5b61
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10a0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
leaq -0x3c(%rbp), %r13
leaq -0x34(%rbp), %r15
movq -0x50(%rbp), %r14
movq %r14, %rdi
leaq 0x1fa7(%rip), %rsi      # 0x5b66
movq %r13, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x1060
incl %ebx
cmpl $0x2, %eax
je 0x3bb5
movq %r14, %rdi
callq 0x10b0
jmp 0x3bdd
leaq 0x1f82(%rip), %rsi      # 0x5b66
xorl %r13d, %r13d
leaq -0x3c(%rbp), %rdx
leaq -0x34(%rbp), %rcx
movq %r14, %rdi
xorl %eax, %eax
callq 0x1060
cmpl $0x2, %eax
movq -0x60(%rbp), %r15
jne 0x3dbc
movl %ebx, -0x6c(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x58(%rbp)
leaq -0x29(%rbp), %r13
xorl %r15d, %r15d
xorps %xmm1, %xmm1
movl $0x0, -0x38(%rbp)
movl %r15d, %ecx
movl 0x878d(%rip), %eax      # 0xc3b8
testl %eax, %eax
je 0x3c8f
decl %eax
imull %ecx, %eax
cltd
idivl -0x6c(%rbp)
xorps %xmm2, %xmm2
cvtsi2ss %eax, %xmm2
ucomiss %xmm1, %xmm2
movl -0x54(%rbp), %r15d
jbe 0x3c9a
movq %rcx, %rbx
movss %xmm2, -0x68(%rbp)
movss %xmm1, -0x30(%rbp)
movl $0x23, %edi
callq 0x1040
movss -0x30(%rbp), %xmm1
movss -0x68(%rbp), %xmm2
addss 0x1da7(%rip), %xmm1     # 0x5a18
ucomiss %xmm1, %xmm2
ja 0x3c50
movss %xmm1, -0x30(%rbp)
movq 0x433e(%rip), %rax      # 0x7fc0
movq (%rax), %rdi
callq 0x1170
movq %rbx, %rcx
jmp 0x3c9f
movss %xmm1, -0x30(%rbp)
movl -0x54(%rbp), %r15d
jmp 0x3c9f
movss %xmm1, -0x30(%rbp)
movss -0x3c(%rbp), %xmm0
minss 0x86e4(%rip), %xmm0     # 0xc390
cvtss2sd %xmm0, %xmm0
mulsd 0x1d68(%rip), %xmm0     # 0x5a20
xorps %xmm1, %xmm1
cvtss2sd 0x86d1(%rip), %xmm1     # 0xc394
divsd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtss2sd -0x58(%rbp), %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
addsd 0x1d3f(%rip), %xmm1     # 0x5a28
cvttsd2si %xmm1, %r14d
movl $0xffff, %eax           # imm = 0xFFFF
cmpl %eax, %r14d
cmovgel %eax, %r14d
testl %ecx, %ecx
je 0x3d28
movl %r14d, %eax
andl $0xfffe, %eax           # imm = 0xFFFE
cmpl $0x6, %eax
jb 0x3d28
movq %rcx, %rbx
movzwl %r14w, %ecx
movq %r12, %rdi
movq -0x48(%rbp), %rsi
movq -0x78(%rbp), %rdx
callq 0x38c2
movq %rbx, %rcx
xorps %xmm0, %xmm0
xorpd %xmm1, %xmm1
movq %rcx, -0x68(%rbp)
testl %ecx, %ecx
movl -0x38(%rbp), %eax
cmovel %r14d, %eax
movl %eax, -0x38(%rbp)
je 0x3d41
movaps %xmm0, %xmm1
movss %xmm1, -0x58(%rbp)
subl $0x1, -0x34(%rbp)
jb 0x3d6a
movl $0x1, %edx
movl %r15d, %edi
movq %r13, %rsi
callq 0x10f0
movzbl -0x29(%rbp), %esi
movq %r12, %rdi
callq 0x1867
jmp 0x3d46
cmpl $0x0, 0x863f(%rip)      # 0xc3b0
jne 0x3d79
andb $-0x5, 0x19(%r12)
movq -0x68(%rbp), %rbx
leal 0x1(%rbx), %r15d
movq -0x50(%rbp), %rdi
leaq 0x1dda(%rip), %rsi      # 0x5b66
leaq -0x3c(%rbp), %rdx
leaq -0x34(%rbp), %rcx
xorl %eax, %eax
callq 0x1060
cmpl $0x2, %eax
movss -0x30(%rbp), %xmm1
je 0x3c22
testl %ebx, %ebx
cmovnel %r14d, %ebx
movl -0x38(%rbp), %r13d
addl %ebx, %r13d
movq -0x60(%rbp), %r15
jmp 0x3dc0
xorpd %xmm1, %xmm1
movl 0x85f2(%rip), %eax      # 0xc3b8
testl %eax, %eax
je 0x3e11
addl $-0x2, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
ucomiss %xmm1, %xmm0
jbe 0x3e07
movss %xmm1, -0x30(%rbp)
movl $0x23, %edi
callq 0x1040
movss -0x30(%rbp), %xmm1
movl 0x85c5(%rip), %eax      # 0xc3b8
addl $-0x2, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
addss 0x1c13(%rip), %xmm1     # 0x5a18
jmp 0x3dd4
movl $0xa, %edi
callq 0x1040
cmpw $0x2, %r13w
movl $0x1, %eax
cmovael %r13d, %eax
movzwl %ax, %ecx
movq %r12, %rdi
movq -0x48(%rbp), %rsi
movq -0x78(%rbp), %rbx
movq %rbx, %rdx
callq 0x38c2
movq %rbx, %rdi
callq 0x35ca
movq %r12, %rdi
callq 0x1030
xorl %eax, %eax
movq %r15, %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x0, -0x30(%rbp)
leaq 0x1cae(%rip), %rsi      # 0x5b15
leaq -0x280(%rbp), %rdi
callq 0x1210
testq %rax, %rax
movq -0x50(%rbp), %r14
je 0x3ac0
addq $0x7, %rax
movq %rax, %rdi
callq 0x11c0
testl %eax, %eax
setg %cl
movl -0x30(%rbp), %esi
testl %esi, %esi
setg %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x3ac0
testl %r12d, %r12d
jg 0x3eb2
movl %esi, 0x84fd(%rip)      # 0xc3ac
movl %esi, %r12d
testl %r13d, %r13d
jg 0x3ac0
movl %eax, 0x84e7(%rip)      # 0xc3a8
movl %eax, %r13d
jmp 0x3ac0
callq 0x136a
movl $0x1, %eax
jmp 0x3e47
callq 0x134b
jmp 0x3f09
callq 0x1329
jmp 0x3eee
movq %r12, %rdi
callq 0x12fc
cmpq $0x0, 0x84aa(%rip)      # 0xc3a0
je 0x3f01
movq -0x48(%rbp), %rdi
callq 0x1030
movl %r15d, %edi
callq 0x10e0
movq %r14, %rdi
callq 0x1090
movl $0x1, %eax
movq -0x60(%rbp), %r15
jmp 0x3e47