// File: /workspace/github_c_makefile_star2_O2/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, %rbx
movl 0x7d51(%rip), %eax      # 0xb3b8
incl %eax
movq %rsp, %r13
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %r13
movq %r13, %rsp
movq 0x7cf7(%rip), %rdi      # 0xb378
leaq 0x115b(%rip), %rsi      # 0x47e3
callq 0x1190
testq %rax, %rax
je 0x3b19
movq %rax, %r14
movq 0x7ce0(%rip), %rdi      # 0xb380
xorl %esi, %esi
xorl %eax, %eax
callq 0x1180
cmpl $-0x1, %eax
je 0x3b3d
movl %eax, %r15d
movq 0x7ce4(%rip), %rdi      # 0xb3a0
testq %rdi, %rdi
je 0x36f3
callq 0x2c1c
movq %rax, -0x48(%rbp)
testq %rax, %rax
jne 0x36fe
movq 0x391a(%rip), %rax      # 0x6ff0
movq (%rax), %rdi
movq 0x7cc0(%rip), %rdx      # 0xb3a0
leaq 0x13f4(%rip), %rsi      # 0x4adb
xorl %eax, %eax
callq 0x1130
jmp 0x3bbe
leaq 0x7c56(%rip), %rax      # 0xb350
movq %rax, -0x48(%rbp)
movq %r14, -0x68(%rbp)
movq %rbx, -0x60(%rbp)
xorl %r12d, %r12d
leaq -0x29(%rbp), %rbx
pushq $0x1
popq %r14
movl %r15d, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x10f0
testq %rax, %rax
jle 0x3741
movb -0x29(%rbp), %al
cmpl $0x1fe, %r12d           # imm = 0x1FE
jg 0x373d
movslq %r12d, %rcx
incl %r12d
movb %al, -0x280(%rbp,%rcx)
cmpb $0xa, %al
jne 0x3711
movl 0x7c65(%rip), %esi      # 0xb3ac
movl 0x7c5b(%rip), %ebx      # 0xb3a8
cmpl $0x11, %r12d
jl 0x37fe
testl %ebx, %ebx
sete %al
testl %esi, %esi
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x37fe
movl %esi, -0x30(%rbp)
movl %r12d, %eax
movb $0x0, -0x280(%rbp,%rax)
leaq 0x137a(%rip), %rsi      # 0x4afb
leaq -0x280(%rbp), %rdi
callq 0x1210
testq %rax, %rax
je 0x37a3
addq $0x9, %rax
movq %rax, %rdi
callq 0x11c0
movl %eax, %r12d
jmp 0x37a6
xorl %r12d, %r12d
leaq 0x1358(%rip), %rsi      # 0x4b05
leaq -0x280(%rbp), %rdi
callq 0x1210
testq %rax, %rax
je 0x37fb
addq $0x7, %rax
movq %rax, %rdi
callq 0x11c0
testl %eax, %eax
setg %cl
testl %r12d, %r12d
setg %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x37fb
movl -0x30(%rbp), %esi
testl %esi, %esi
jg 0x37ed
movl %r12d, 0x7bc2(%rip)     # 0xb3ac
movl %r12d, %esi
testl %ebx, %ebx
jg 0x37fe
movl %eax, 0x7bb1(%rip)      # 0xb3a8
movl %eax, %ebx
jmp 0x37fe
movl -0x30(%rbp), %esi
cmpl $0x0, 0x7bb7(%rip)      # 0xb3bc
je 0x3831
testl %ebx, %ebx
je 0x380f
testl %esi, %esi
jne 0x3831
testl %ebx, %ebx
jg 0x3820
movzwl 0x7ba6(%rip), %ebx      # 0xb3c0
movl %ebx, 0x7b88(%rip)      # 0xb3a8
testl %esi, %esi
jg 0x3831
movzwl 0x7b97(%rip), %esi      # 0xb3c2
movl %esi, 0x7b7b(%rip)      # 0xb3ac
testl %esi, %esi
jle 0x3b5e
testl %ebx, %ebx
jle 0x3b5e
movl %ebx, %edi
callq 0x158c
movq %rax, %r12
movq -0x48(%rbp), %rax
movzbl 0x2(%rax), %esi
imull 0x4(%r12), %esi
movzbl 0x3(%rax), %edx
imull (%r12), %edx
movq 0x7b1f(%rip), %rdi      # 0xb388
leaq 0x16c(%r12), %rcx
movl 0x7b20(%rip), %r8d      # 0xb398
movl $0xffff, %eax           # imm = 0xFFFF
andl %eax, %esi
andl %eax, %edx
callq 0x2dac
movq %rax, -0x78(%rbp)
testq %rax, %rax
je 0x3b7c
movslq 0x7b1e(%rip), %rax      # 0xb3b8
testq %rax, %rax
je 0x390b
movb $0x5b, (%r13)
movw $0x5d, -0x1(%r13,%rax)
decl %eax
cltq
cmpq %rax, %r14
jge 0x38c0
movb $0x2d, (%r13,%r14)
incq %r14
jmp 0x38b0
leaq 0x128a(%rip), %rdi      # 0x4b51
movq %r13, %rsi
xorl %eax, %eax
callq 0x10a0
pushq $-0x1
popq %r14
leaq -0x50(%rbp), %r13
movq -0x68(%rbp), %rbx
movq %rbx, %rdi
leaq 0x126f(%rip), %rsi      # 0x4b56
leaq -0x54(%rbp), %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x1060
incl %r14d
cmpl $0x2, %eax
je 0x38dd
movl %r14d, -0x6c(%rbp)
movq %rbx, %rdi
callq 0x10b0
jmp 0x390b
xorps %xmm0, %xmm0
movss %xmm0, -0x30(%rbp)
leaq -0x29(%rbp), %r13
pushq $0x1
popq %r14
xorl %ebx, %ebx
movl $0x0, -0x3c(%rbp)
movss %xmm0, -0x4c(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x68(%rbp), %rdi
leaq 0x121b(%rip), %rsi      # 0x4b56
leaq -0x54(%rbp), %rdx
leaq -0x50(%rbp), %rcx
xorl %eax, %eax
callq 0x1060
cmpl $0x2, %eax
jne 0x3a8e
movl 0x7a5f(%rip), %eax      # 0xb3b8
testl %eax, %eax
je 0x39b1
decl %eax
imull -0x34(%rbp), %eax
cltd
idivl -0x6c(%rbp)
cvtsi2ss %eax, %xmm1
movss -0x30(%rbp), %xmm0
movss %xmm1, -0x38(%rbp)
ucomiss %xmm0, %xmm1
jbe 0x39b1
pushq $0x23
popq %rbx
movss -0x38(%rbp), %xmm1
ucomiss %xmm0, %xmm1
movss %xmm0, -0x30(%rbp)
jbe 0x39a2
movl %ebx, %edi
callq 0x1040
movss -0x30(%rbp), %xmm0
addss 0x1068(%rip), %xmm0     # 0x4a08
jmp 0x397d
movq 0x3617(%rip), %rax      # 0x6fc0
movq (%rax), %rdi
callq 0x1170
movss -0x54(%rbp), %xmm0
minss 0x79d2(%rip), %xmm0     # 0xb390
cvtss2sd %xmm0, %xmm0
mulsd 0x1046(%rip), %xmm0     # 0x4a10
cvtss2sd 0x79c2(%rip), %xmm1     # 0xb394
divsd %xmm1, %xmm0
cvtss2sd -0x4c(%rbp), %xmm1
addsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
movss %xmm0, -0x38(%rbp)
cvtss2sd %xmm0, %xmm0
addsd 0x1024(%rip), %xmm0     # 0x4a18
cvttsd2si %xmm0, %ebx
movl $0xffff, %eax           # imm = 0xFFFF
cmpl %eax, %ebx
cmovgel %eax, %ebx
cmpl $0x0, -0x34(%rbp)
je 0x3a30
movl %ebx, %eax
andl $0xfffe, %eax           # imm = 0xFFFE
cmpl $0x6, %eax
jb 0x3a30
movzwl %bx, %ecx
movq %r12, %rdi
movq -0x48(%rbp), %rsi
movq -0x78(%rbp), %rdx
callq 0x359a
xorpd %xmm0, %xmm0
movss %xmm0, -0x38(%rbp)
cmpl $0x0, -0x34(%rbp)
movl -0x3c(%rbp), %eax
cmovel %ebx, %eax
movl %eax, -0x3c(%rbp)
subl $0x1, -0x50(%rbp)
jb 0x3a5f
movl %r15d, %edi
movq %r13, %rsi
movq %r14, %rdx
callq 0x10f0
movzbl -0x29(%rbp), %esi
movq %r12, %rdi
callq 0x16ba
jmp 0x3a3d
xorpd %xmm0, %xmm0
movl -0x34(%rbp), %eax
testl %eax, %eax
cmovel %eax, %ebx
je 0x3a72
movss -0x38(%rbp), %xmm0
cmpl $0x0, 0x7937(%rip)      # 0xb3b0
jne 0x3a81
andb $-0x5, 0x19(%r12)
movss %xmm0, -0x4c(%rbp)
incl -0x34(%rbp)
jmp 0x3930
movl -0x3c(%rbp), %r14d
addl %ebx, %r14d
movl 0x791d(%rip), %eax      # 0xb3b8
testl %eax, %eax
je 0x3adc
pushq $0x23
popq %rbx
movss -0x30(%rbp), %xmm1
addl $-0x2, %eax
cvtsi2ss %eax, %xmm0
ucomiss %xmm1, %xmm0
jbe 0x3ad4
movl %ebx, %edi
movss %xmm1, -0x30(%rbp)
callq 0x1040
movss -0x30(%rbp), %xmm1
addss 0xf3c(%rip), %xmm1      # 0x4a08
movl 0x78e6(%rip), %eax      # 0xb3b8
jmp 0x3aa7
pushq $0xa
popq %rdi
callq 0x1040
cmpw $0x2, %r14w
pushq $0x1
popq %rax
cmovael %r14d, %eax
movzwl %ax, %ecx
movq %r12, %rdi
movq -0x48(%rbp), %rsi
movq -0x78(%rbp), %rbx
movq %rbx, %rdx
callq 0x359a
movq %rbx, %rdi
callq 0x32d7
movq %r12, %rdi
callq 0x1030
xorl %eax, %eax
movq -0x60(%rbp), %rbx
jmp 0x3bd1
movq 0x34d0(%rip), %rax      # 0x6ff0
movq (%rax), %rdi
movq 0x784e(%rip), %rdx      # 0xb378
leaq 0xf63(%rip), %rsi       # 0x4a94
xorl %eax, %eax
callq 0x1130
jmp 0x3bce
movq 0x34ac(%rip), %rax      # 0x6ff0
movq (%rax), %rdi
movq 0x7832(%rip), %rdx      # 0xb380
leaq 0xf62(%rip), %rsi       # 0x4ab7
xorl %eax, %eax
callq 0x1130
jmp 0x3bc6
movq 0x348b(%rip), %rax      # 0x6ff0
movq (%rax), %rcx
leaq 0xf9e(%rip), %rdi       # 0x4b0d
pushq $0x22
popq %rsi
pushq $0x1
popq %rdx
callq 0x1200
jmp 0x3ba3
movq 0x346d(%rip), %rax      # 0x6ff0
movq (%rax), %rdi
movq 0x77fb(%rip), %rdx      # 0xb388
leaq 0xf9c(%rip), %rsi       # 0x4b30
xorl %eax, %eax
callq 0x1130
movq %r12, %rdi
callq 0x1030
movq -0x60(%rbp), %rbx
cmpq $0x0, 0x77f1(%rip)      # 0xb3a0
movq -0x68(%rbp), %r14
je 0x3bbe
movq -0x48(%rbp), %rdi
callq 0x1030
movl %r15d, %edi
callq 0x10e0
movq %r14, %rdi
callq 0x1090
pushq $0x1
popq %rax
movq %rbx, %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq