// File: /workspace/github_c_makefile_star2_O1/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 $0x248, %rsp            # imm = 0x248
movq %rsp, %r14
movl 0x8a2f(%rip), %eax      # 0xc3b8
incl %eax
movq %rsp, %rbx
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %rbx
movq %rbx, %rsp
movq 0x89d5(%rip), %rdi      # 0xc378
leaq 0x1e39(%rip), %rsi      # 0x57e3
callq 0x1190
movq %rax, -0x48(%rbp)
testq %rax, %rax
je 0x3ea5
movq %r14, -0x68(%rbp)
movq 0x89b9(%rip), %rdi      # 0xc380
xorl %esi, %esi
xorl %eax, %eax
callq 0x1180
cmpl $-0x1, %eax
je 0x3eb1
movl %eax, %r15d
movq 0x89bd(%rip), %rdi      # 0xc3a0
testq %rdi, %rdi
je 0x3a04
callq 0x2e44
movq %rax, -0x50(%rbp)
testq %rax, %rax
jne 0x3a0f
callq 0x12dd
movq -0x48(%rbp), %rbx
jmp 0x3ee2
leaq 0x8945(%rip), %rax      # 0xc350
movq %rax, -0x50(%rbp)
xorl %r13d, %r13d
leaq -0x29(%rbp), %r12
movl $0x1, %edx
movl %r15d, %edi
movq %r12, %rsi
callq 0x10f0
testq %rax, %rax
jle 0x3a4a
cmpl $0x1fe, %r13d           # imm = 0x1FE
jg 0x3a44
movb -0x29(%rbp), %al
movslq %r13d, %rcx
incl %r13d
movb %al, -0x270(%rbp,%rcx)
cmpb $0xa, -0x29(%rbp)
jne 0x3a16
cmpl $0x11, %r13d
jl 0x3b05
movl 0x894d(%rip), %r14d     # 0xc3a8
testl %r14d, %r14d
sete %al
movl 0x8944(%rip), %r12d     # 0xc3ac
testl %r12d, %r12d
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x3b05
movl %r13d, %eax
movb $0x0, -0x270(%rbp,%rax)
leaq 0x2060(%rip), %rsi      # 0x5aeb
leaq -0x270(%rbp), %rdi
callq 0x1210
movl $0x0, %r13d
testq %rax, %rax
je 0x3ab1
addq $0x9, %rax
movq %rax, %rdi
callq 0x11c0
movl %eax, %r13d
leaq 0x203d(%rip), %rsi      # 0x5af5
leaq -0x270(%rbp), %rdi
callq 0x1210
testq %rax, %rax
movl $0x0, %edx
je 0x3adc
addq $0x7, %rax
movq %rax, %rdi
callq 0x11c0
movl %eax, %edx
testl %edx, %edx
setg %al
testl %r13d, %r13d
setg %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x3b05
testl %r12d, %r12d
jg 0x3afa
movl %r13d, 0x88b2(%rip)     # 0xc3ac
testl %r14d, %r14d
jg 0x3b05
movl %edx, 0x88a3(%rip)      # 0xc3a8
cmpl $0x0, 0x88b0(%rip)      # 0xc3bc
je 0x3b50
movl 0x8894(%rip), %ecx      # 0xc3a8
testl %ecx, %ecx
sete %dl
movl 0x888d(%rip), %eax      # 0xc3ac
testl %eax, %eax
sete %sil
orb %dl, %sil
cmpb $0x1, %sil
jne 0x3b50
testl %ecx, %ecx
jg 0x3b3f
movzwl 0x8887(%rip), %ecx      # 0xc3c0
movl %ecx, 0x8869(%rip)      # 0xc3a8
testl %eax, %eax
jg 0x3b50
movzwl 0x8878(%rip), %eax      # 0xc3c2
movl %eax, 0x885c(%rip)      # 0xc3ac
movl 0x8856(%rip), %esi      # 0xc3ac
testl %esi, %esi
jle 0x3ebc
movl 0x8844(%rip), %edi      # 0xc3a8
testl %edi, %edi
jle 0x3ebc
callq 0x16fb
movq %rax, %r12
movq -0x50(%rbp), %rax
movzbl 0x2(%rax), %esi
imull 0x4(%r12), %esi
movzbl 0x3(%rax), %edx
imull (%r12), %edx
movq 0x87f6(%rip), %rdi      # 0xc388
leaq 0x16c(%r12), %rcx
movl 0x87f7(%rip), %r8d      # 0xc398
movl $0xffff, %eax           # imm = 0xFFFF
andl %eax, %esi
andl %eax, %edx
callq 0x2ff0
movq %rax, -0x70(%rbp)
testq %rax, %rax
je 0x3ec3
movslq 0x87f5(%rip), %rdx      # 0xc3b8
testq %rdx, %rdx
je 0x3c35
movb $0x5b, (%rbx)
movw $0x5d, -0x1(%rbx,%rdx)
cmpl $0x3, %edx
jl 0x3be8
leaq 0x1(%rbx), %rdi
addl $-0x2, %edx
movl $0x2d, %esi
callq 0x10c0
leaq 0x1f52(%rip), %rdi      # 0x5b41
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10a0
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
leaq -0x34(%rbp), %r14
movq -0x48(%rbp), %rbx
movq %rbx, %rdi
leaq 0x1f35(%rip), %rsi      # 0x5b46
leaq -0x3c(%rbp), %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x1060
incl %r13d
cmpl $0x2, %eax
je 0x3c07
movl %r13d, -0x5c(%rbp)
movq %rbx, %rdi
callq 0x10b0
jmp 0x3c39
movq -0x48(%rbp), %rbx
leaq 0x1f06(%rip), %rsi      # 0x5b46
xorl %r13d, %r13d
leaq -0x3c(%rbp), %rdx
leaq -0x34(%rbp), %rcx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1060
cmpl $0x2, %eax
jne 0x3dff
movl %r15d, -0x54(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x58(%rbp)
leaq -0x29(%rbp), %r13
xorl %r15d, %r15d
xorps %xmm1, %xmm1
movl $0x0, -0x38(%rbp)
movl %r15d, %ebx
movl 0x8734(%rip), %eax      # 0xc3b8
testl %eax, %eax
je 0x3ce4
decl %eax
imull %ebx, %eax
cltd
idivl -0x5c(%rbp)
xorps %xmm2, %xmm2
cvtsi2ss %eax, %xmm2
ucomiss %xmm1, %xmm2
movl -0x54(%rbp), %r15d
jbe 0x3cef
jbe 0x3cce
movss %xmm2, -0x60(%rbp)
movss %xmm1, -0x30(%rbp)
movl $0x23, %edi
callq 0x1040
movss -0x30(%rbp), %xmm1
movss -0x60(%rbp), %xmm2
addss 0x1d3f(%rip), %xmm1     # 0x5a08
ucomiss %xmm1, %xmm2
ja 0x3ca8
movss %xmm1, -0x30(%rbp)
movq 0x42e6(%rip), %rax      # 0x7fc0
movq (%rax), %rdi
callq 0x1170
jmp 0x3cf4
movss %xmm1, -0x30(%rbp)
movl -0x54(%rbp), %r15d
jmp 0x3cf4
movss %xmm1, -0x30(%rbp)
movss -0x3c(%rbp), %xmm0
minss 0x868f(%rip), %xmm0     # 0xc390
cvtss2sd %xmm0, %xmm0
mulsd 0x1d03(%rip), %xmm0     # 0x5a10
xorps %xmm1, %xmm1
cvtss2sd 0x867c(%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 0x1cda(%rip), %xmm1     # 0x5a18
cvttsd2si %xmm1, %r14d
movl $0xffff, %eax           # imm = 0xFFFF
cmpl %eax, %r14d
cmovgel %eax, %r14d
testl %ebx, %ebx
je 0x3d77
movl %r14d, %eax
andl $0xfffe, %eax           # imm = 0xFFFE
cmpl $0x6, %eax
jb 0x3d77
movzwl %r14w, %ecx
movq %r12, %rdi
movq -0x50(%rbp), %rsi
movq -0x70(%rbp), %rdx
callq 0x38b4
xorps %xmm0, %xmm0
xorpd %xmm1, %xmm1
testl %ebx, %ebx
movl -0x38(%rbp), %eax
cmovel %r14d, %eax
movl %eax, -0x38(%rbp)
je 0x3d8c
movaps %xmm0, %xmm1
movss %xmm1, -0x58(%rbp)
subl $0x1, -0x34(%rbp)
jb 0x3db5
movl $0x1, %edx
movl %r15d, %edi
movq %r13, %rsi
callq 0x10f0
movzbl -0x29(%rbp), %esi
movq %r12, %rdi
callq 0x184c
jmp 0x3d91
cmpl $0x0, 0x85f4(%rip)      # 0xc3b0
jne 0x3dc4
andb $-0x5, 0x19(%r12)
leal 0x1(%rbx), %r15d
movq -0x48(%rbp), %rdi
leaq 0x1d73(%rip), %rsi      # 0x5b46
leaq -0x3c(%rbp), %rdx
leaq -0x34(%rbp), %rcx
xorl %eax, %eax
callq 0x1060
cmpl $0x2, %eax
movss -0x30(%rbp), %xmm1
je 0x3c7b
testl %ebx, %ebx
cmovel %ebx, %r14d
movl -0x38(%rbp), %r13d
addl %r14d, %r13d
jmp 0x3e03
xorpd %xmm1, %xmm1
cmpl $0x0, 0x85ae(%rip)      # 0xc3b8
movq -0x68(%rbp), %r14
je 0x3e5d
movl 0x85a2(%rip), %eax      # 0xc3b8
addl $-0x2, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
ucomiss %xmm1, %xmm0
jbe 0x3e53
movss %xmm1, -0x30(%rbp)
movl $0x23, %edi
callq 0x1040
movss -0x30(%rbp), %xmm1
movl 0x8579(%rip), %eax      # 0xc3b8
addl $-0x2, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
addss 0x1bb7(%rip), %xmm1     # 0x5a08
jmp 0x3e20
movl $0xa, %edi
callq 0x1040
cmpw $0x2, %r13w
movl $0x1, %eax
cmovael %r13d, %eax
movzwl %ax, %ecx
movq %r12, %rdi
movq -0x50(%rbp), %rsi
movq -0x70(%rbp), %rbx
movq %rbx, %rdx
callq 0x38b4
movq %rbx, %rdi
callq 0x35ce
movq %r12, %rdi
callq 0x1030
xorl %eax, %eax
movq %r14, %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x136a
movl $0x1, %eax
jmp 0x3e93
callq 0x134b
movq -0x48(%rbp), %rbx
jmp 0x3eea
callq 0x1329
jmp 0x3ecb
movq %r12, %rdi
callq 0x12fc
cmpq $0x0, 0x84cd(%rip)      # 0xc3a0
movq -0x48(%rbp), %rbx
je 0x3ee2
movq -0x50(%rbp), %rdi
callq 0x1030
movl %r15d, %edi
callq 0x10e0
movq %rbx, %rdi
callq 0x1090
movl $0x1, %eax
movq -0x68(%rbp), %r14
jmp 0x3e93