// File: /workspace/github_c_makefile_star2_O2/beejjorgensen[P]conquest/conq4.c
// Function: tf_battle
void tf_battle(int starnum)
{
    int ennum, plnum;
    float enodds, plodds;
    boolean battle;
    int count, new_tf, i;
    char ch;
    boolean pla_loss, ene_loss;
    int size;
    tteam team;
    int dstar;
    float slist[nstars + 1];
    boolean fin, first;
    board[stars[starnum].x][stars[starnum].y].enemy = '!';
    update_board(stars[starnum].x, stars[starnum].y, left);
    ennum = 1;
    while ((tf[ENEMY][ennum].dest != starnum)
           || (tf[ENEMY][ennum].eta != 0)
        )
        ennum = ennum + 1;
    plnum = 1;
    if (tf_stars[starnum][player] > 1) {
        get_tf(player, &new_tf, starnum);
        for (i = 1; i <= 26; i++) {
            if ((tf[player][i].dest == starnum) && (tf[player][i].eta == 0)
                && (i != new_tf))
                joinsilent(player, &tf[player][new_tf], &tf[player][i]);
        };
        tf_stars[starnum][player] = 1;
        plnum = new_tf;
    } else {
        while ((tf[player][plnum].dest != starnum)
               || (tf[player][plnum].eta != 0)
            )
            plnum = plnum + 1;
    };
    display_forces(ennum, plnum, &enodds, &plodds, &battle);
    pause();
    first = true;
    while (battle) {
        if (left_line[24]) {
            point(1, 24);
            printw(blank_line);
            left_line[24] = false;
        };
        pla_loss = true;
        ene_loss = true;
        point(1, 21);
        printw(" Enemy losses:                ");
        point(1, 22);
        printw("Player losses:                ");
        do {
            point(15, 21);
            lose(&tf[ENEMY][ennum].t, &ene_loss, 't', enodds);
            lose(&tf[ENEMY][ennum].s, &ene_loss, 's', enodds);
            lose(&tf[ENEMY][ennum].c, &ene_loss, 'c', enodds);
            lose(&tf[ENEMY][ennum].b, &ene_loss, 'b', enodds);
            point(15, 22);
            lose(&tf[player][plnum].t, &pla_loss, 't', plodds);
            lose(&tf[player][plnum].s, &pla_loss, 's', plodds);
            lose(&tf[player][plnum].c, &pla_loss, 'c', plodds);
            lose(&tf[player][plnum].b, &pla_loss, 'b', plodds);
        }
        while (!first && ene_loss && pla_loss);
        if (ene_loss) {
            point(15, 21);
            printw("(none)");
        };
        if (pla_loss) {
            point(15, 22);
            printw("(none)");
        };
        first = false;
        display_forces(ennum, plnum, &enodds, &plodds, &battle);
        if (battle) {
            /*withdraw the bad guys */
            get_tf(ENEMY, &new_tf, starnum);
            if ((tf[player][plnum].c > 0) || (tf[player][plnum].b > 0)
                ) {
                tf[ENEMY][new_tf].t = tf[ENEMY][ennum].t;
                tf[ENEMY][new_tf].s = tf[ENEMY][ennum].s;
                best_plan(&starnum, &size, &team);
                if (((enodds < 0.7) && (size < 30)) || ((enodds < 0.50)
                                                        && (team ==
                                                            player))
                    || ((enodds < 0.30) && (size < 60))
                    || (enodds < 0.20)) {
                    tf[ENEMY][new_tf].c = tf[ENEMY][ennum].c;
                    tf[ENEMY][new_tf].b = tf[ENEMY][ennum].b;
                };
            };
            if ((tf[ENEMY][new_tf].t + tf[ENEMY][new_tf].s +
                 tf[ENEMY][new_tf].c + tf[ENEMY][new_tf].b) > 0) {
                get_stars(starnum, slist, &count);
                do {
                    dstar = rnd(nstars);
                }
                while (slist[dstar] <= 0);
                tf[ENEMY][new_tf].dest = dstar;
                tf[ENEMY][new_tf].eta =
                    (int) ((slist[dstar] - 0.01) / vel[ENEMY]) + 1;
                tf[ENEMY][new_tf].xf = stars[starnum].x;
                tf[ENEMY][new_tf].yf = stars[starnum].y;
            } else
                tf[ENEMY][new_tf].dest = 0;

            fin = false;
            do {
                point(1, 18);
                printw("B?                            ");
                point(3, 18);
                get_char(&ch);
                switch (ch) {
                case 'M':
                    printmap();
                    break;
                case 'H':
                    help(2);
                    break;
                case 'S':
                    starsum();
                    break;
                case 'T':
                    tfsum();
                    break;
                case 'C':
                    print_col();
                    break;
                case '?':
                    break;
                case 'R':
                    ressum();
                    break;
                case 'O':
                    display_forces(ennum, plnum, &enodds, &plodds,
                                   &battle);
                    break;
                case 'W':
                    withdraw(starnum, plnum);
                    display_forces(ennum, plnum, &enodds, &plodds,
                                   &battle);
                    break;
                case ' ':
                case 'G':
                    fin = true;
                    break;
                default:
                    printw("!illegal command");
                };              /*switch ( */
            }
            while (!fin && battle);
            zero_tf(ENEMY, new_tf);
            zero_tf(player, plnum);
            if (tf[ENEMY][new_tf].dest != 0) {
                point(1, 23);
                printw("en withdraws");
                point(14, 23);
                disp_tf(&tf[ENEMY][new_tf]);
                tf[ENEMY][ennum].t =
                    tf[ENEMY][ennum].t - tf[ENEMY][new_tf].t;
                tf[ENEMY][ennum].s =
                    tf[ENEMY][ennum].s - tf[ENEMY][new_tf].s;
                tf[ENEMY][ennum].c =
                    tf[ENEMY][ennum].c - tf[ENEMY][new_tf].c;
                tf[ENEMY][ennum].b =
                    tf[ENEMY][ennum].b - tf[ENEMY][new_tf].b;
                zero_tf(ENEMY, ennum);
                display_forces(ennum, plnum, &enodds, &plodds, &battle);
            };
        };
    };
    zero_tf(ENEMY, ennum);
    zero_tf(player, plnum);
    revolt(starnum);
    on_board(stars[starnum].x, stars[starnum].y);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movl %edi, %ebx
movl %edi, 0xc(%rsp)
movslq %edi, %r15
imulq $0x18, %r15, %rax
leaq 0xd6f2(%rip), %rcx      # 0x10490
movslq (%rcx,%rax), %rdi
movslq 0x4(%rcx,%rax), %rsi
imulq $0xc, %rsi, %rax
imulq $0xc0, %rdi, %rcx
addq 0xb1df(%rip), %rcx      # 0xdf98
movl $0x21, (%rax,%rcx)
pushq $0x1
popq %rdx
movl %edx, 0x14(%rsp)
callq 0x2ca4
leaq 0xcbbd(%rip), %rax      # 0xf990
leaq 0x44(%rax), %r12
cmpl %ebx, 0x10(%r12)
jne 0x2de6
cmpl $0x0, 0x14(%r12)
je 0x2df0
incl 0x14(%rsp)
addq $0x34, %r12
jmp 0x2dd7
leaq 0xbe29(%rip), %r14      # 0xec20
cmpl $0x1, 0x4(%r14,%r15,8)
jle 0x2e69
pushq $0x1
popq %rbp
leaq 0x4(%rsp), %rsi
movl %ebp, %edi
movl %ebx, %edx
callq 0x2990
movl $0x5b0, %ebx            # imm = 0x5B0
addq 0xb18c(%rip), %rbx      # 0xdfa8
pushq $0x1
popq %r15
cmpq $0x1b, %r15
je 0x2e8a
movl 0x20(%rbx), %eax
cmpl 0xc(%rsp), %eax
jne 0x2e60
cmpl $0x0, 0x24(%rbx)
jne 0x2e60
movl 0x4(%rsp), %eax
cmpq %rax, %r15
je 0x2e60
cltq
imulq $0x34, %rax, %rax
leaq 0xcb45(%rip), %rcx      # 0xf990
leaq (%rcx,%rax), %rsi
addq $0x57c, %rsi            # imm = 0x57C
movl %ebp, %edi
movq %rbx, %rdx
callq 0x29fc
incq %r15
addq $0x34, %rbx
jmp 0x2e20
movl $0x5d4, %eax            # imm = 0x5D4
addq 0xb133(%rip), %rax      # 0xdfa8
pushq $0x1
popq %rbp
cmpl %ebx, -0x4(%rax)
jne 0x2e82
cmpl $0x0, (%rax)
je 0x2e9c
incl %ebp
addq $0x34, %rax
jmp 0x2e78
movslq 0xc(%rsp), %rax
movl $0x1, 0x4(%r14,%rax,8)
movl 0x4(%rsp), %ebp
leaq 0x8(%rsp), %rdx
leaq 0x10(%rsp), %rcx
leaq 0x18(%rsp), %r8
movl 0x14(%rsp), %edi
movl %ebp, %esi
callq 0x24d3
callq 0x71b1
leaq 0x4(%r12), %rax
movq %rax, 0x58(%rsp)
leaq 0x8(%r12), %rax
movq %rax, 0x48(%rsp)
movq %r12, 0x30(%rsp)
leaq 0xc(%r12), %rax
movq %rax, 0x70(%rsp)
movl %ebp, 0x20(%rsp)
movslq %ebp, %rax
imulq $0x34, %rax, %rax
leaq 0xcaa0(%rip), %rcx      # 0xf990
leaq (%rcx,%rax), %rdx
addq $0x590, %rdx            # imm = 0x590
movq %rdx, 0x68(%rsp)
leaq 0x58c(%rcx,%rax), %rdx
movq %rdx, 0x60(%rsp)
leaq 0x594(%rcx,%rax), %rdx
movq %rdx, 0x50(%rsp)
addq %rcx, %rax
addq $0x598, %rax            # imm = 0x598
movq %rax, 0x40(%rsp)
leaq 0xd991(%rip), %r13      # 0x108c0
movl $0x0, 0x28(%rsp)
cmpl $0x0, 0x18(%rsp)
je 0x347d
cmpl $0x0, 0x60(%r13)
pushq $0x1
popq %r12
je 0x2f6b
movl %r12d, %edi
pushq $0x18
popq %rsi
callq 0x4dbd
leaq 0x6370(%rip), %rdi      # 0x92cf
xorl %eax, %eax
callq 0x2030
andl $0x0, 0x60(%r13)
movl %r12d, 0x24(%rsp)
movl %r12d, 0x2c(%rsp)
movl %r12d, %edi
pushq $0x15
popq %rsi
callq 0x4dbd
leaq 0x6367(%rip), %rdi      # 0x92ee
xorl %eax, %eax
callq 0x2030
movl %r12d, %edi
pushq $0x16
popq %rsi
callq 0x4dbd
leaq 0x636d(%rip), %rdi      # 0x930d
xorl %eax, %eax
callq 0x2030
movq 0x58(%rsp), %r12
pushq $0xf
popq %r13
movl %r13d, %edi
pushq $0x15
popq %rsi
callq 0x4dbd
movss 0x8(%rsp), %xmm0
movq %r12, %rdi
leaq 0x2c(%rsp), %rbx
movq %rbx, %rsi
pushq $0x74
popq %r14
movl %r14d, %edx
callq 0x2a34
movss 0x8(%rsp), %xmm0
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
pushq $0x73
popq %r15
movl %r15d, %edx
callq 0x2a34
movss 0x8(%rsp), %xmm0
movq 0x48(%rsp), %rdi
movq %rbx, %rsi
pushq $0x63
popq %rbp
movl %ebp, %edx
callq 0x2a34
movss 0x8(%rsp), %xmm0
movq 0x70(%rsp), %rdi
movq %rbx, %rsi
pushq $0x62
popq %rbx
movl %ebx, %edx
callq 0x2a34
movl %r13d, %edi
pushq $0x16
popq %rsi
callq 0x4dbd
movss 0x10(%rsp), %xmm0
movq 0x68(%rsp), %rdi
leaq 0x24(%rsp), %r13
movq %r13, %rsi
movl %r14d, %edx
callq 0x2a34
movss 0x10(%rsp), %xmm0
movq 0x60(%rsp), %rdi
movq %r13, %rsi
movl %r15d, %edx
callq 0x2a34
movss 0x10(%rsp), %xmm0
movq 0x50(%rsp), %rdi
movq %r13, %rsi
movl %ebp, %edx
callq 0x2a34
movss 0x10(%rsp), %xmm0
movq 0x40(%rsp), %rdi
movq %r13, %rsi
movl %ebx, %edx
callq 0x2a34
movl 0x2c(%rsp), %ecx
testl %ecx, %ecx
setne %dl
andb 0x28(%rsp), %dl
movl 0x24(%rsp), %eax
cmpb $0x1, %dl
jne 0x30a6
testl %eax, %eax
jne 0x2fac
testl %ecx, %ecx
je 0x30c7
pushq $0xf
popq %rdi
pushq $0x15
popq %rsi
callq 0x4dbd
leaq 0x6270(%rip), %rdi      # 0x932c
xorl %eax, %eax
callq 0x2030
movl 0x24(%rsp), %eax
testl %eax, %eax
leaq 0xd7f0(%rip), %r13      # 0x108c0
pushq $0x12
popq %rbx
leaq 0x6259(%rip), %r14      # 0x9333
pushq $0x3
popq %rbp
leaq 0x1f(%rsp), %r15
je 0x30fd
pushq $0xf
popq %rdi
pushq $0x16
popq %rsi
callq 0x4dbd
leaq 0x6236(%rip), %rdi      # 0x932c
xorl %eax, %eax
callq 0x2030
movl 0x14(%rsp), %edi
movl 0x20(%rsp), %esi
leaq 0x8(%rsp), %rdx
leaq 0x10(%rsp), %rcx
leaq 0x18(%rsp), %r8
callq 0x24d3
movb $0x1, %al
movl %eax, 0x28(%rsp)
cmpl $0x0, 0x18(%rsp)
pushq $0x15
popq %r12
je 0x2f37
movl 0xc(%rsp), %edx
xorl %edi, %edi
leaq 0x4(%rsp), %rsi
callq 0x2990
movq 0x50(%rsp), %rax
cmpl $0x0, (%rax)
leaq 0xc843(%rip), %rsi      # 0xf990
jg 0x315d
movq 0x40(%rsp), %rax
cmpl $0x0, (%rax)
jle 0x31e7
movslq 0x4(%rsp), %rax
imulq $0x34, %rax, %rax
movq 0x30(%rsp), %rcx
movq (%rcx), %rcx
movq %rcx, 0x10(%rsi,%rax)
leaq 0xc(%rsp), %rdi
leaq 0x3c(%rsp), %rsi
leaq 0x38(%rsp), %rdx
callq 0x2293
leaq 0xc802(%rip), %rsi      # 0xf990
movss 0x8(%rsp), %xmm1
cvtss2sd %xmm1, %xmm0
movsd 0x60a0(%rip), %xmm2     # 0x9240
ucomisd %xmm0, %xmm2
seta %cl
movl 0x3c(%rsp), %eax
cmpl $0x1e, %eax
setl %dl
testb %dl, %cl
jne 0x31d1
movss 0x60a3(%rip), %xmm2     # 0x9260
ucomiss %xmm1, %xmm2
jbe 0x3449
cmpl $0x1, 0x38(%rsp)
jne 0x3449
movslq 0x4(%rsp), %rax
imulq $0x34, %rax, %rax
movq 0x48(%rsp), %rcx
movq (%rcx), %rcx
movq %rcx, 0x18(%rsi,%rax)
movslq 0x4(%rsp), %rax
imulq $0x34, %rax, %rax
movdqu 0x10(%rsi,%rax), %xmm0
pshufd $0xee, %xmm0, %xmm1     # xmm1 = xmm0[2,3,2,3]
paddd %xmm0, %xmm1
pshufd $0x55, %xmm1, %xmm0     # xmm0 = xmm1[1,1,1,1]
paddd %xmm1, %xmm0
movd %xmm0, %ecx
testl %ecx, %ecx
jle 0x329b
movl 0xc(%rsp), %edi
leaq 0x80(%rsp), %rsi
leaq 0x7c(%rsp), %rdx
callq 0x6e9e
movl %r12d, %edi
callq 0x4e19
movslq %eax, %rcx
movss 0x80(%rsp,%rcx,4), %xmm0
pxor %xmm1, %xmm1
ucomiss %xmm0, %xmm1
jae 0x322a
movslq 0x4(%rsp), %rcx
imulq $0x34, %rcx, %rcx
leaq 0xc739(%rip), %rsi      # 0xf990
movl %eax, 0x20(%rsi,%rcx)
cvtss2sd %xmm0, %xmm0
addsd 0x5ff1(%rip), %xmm0     # 0x9258
leaq 0xd43a(%rip), %rax      # 0x106a8
cvtsi2sdl (%rax), %xmm1
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
incl %eax
movl %eax, 0x24(%rsi,%rcx)
movslq 0xc(%rsp), %rax
imulq $0x18, %rax, %rax
leaq 0xd200(%rip), %rdx      # 0x10490
movq (%rdx,%rax), %rax
movq %rax, 0x8(%rsi,%rcx)
jmp 0x32a2
addq %rsi, %rax
andl $0x0, 0x20(%rax)
leaq 0x5fbb(%rip), %r12      # 0x9264
pushq $0x1
popq %rdi
movl %ebx, %esi
callq 0x4dbd
movq %r14, %rdi
xorl %eax, %eax
callq 0x2030
movl %ebp, %edi
movl %ebx, %esi
callq 0x4dbd
movq %r15, %rdi
callq 0x6d93
movzbl 0x1f(%rsp), %eax
leal -0x3f(%rax), %ecx
cmpl $0x18, %ecx
ja 0x3370
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
callq 0x3eb4
jmp 0x3383
callq 0x7716
jmp 0x3383
movl 0x14(%rsp), %edi
movl 0x20(%rsp), %esi
leaq 0x8(%rsp), %rdx
leaq 0x10(%rsp), %rcx
leaq 0x18(%rsp), %r8
jmp 0x3354
pushq $0x2
popq %rdi
callq 0x706a
jmp 0x3383
movl 0xc(%rsp), %edi
movl 0x20(%rsp), %r13d
movl %r13d, %esi
callq 0x34cb
movl 0x14(%rsp), %edi
movl %r13d, %esi
leaq 0x8(%rsp), %rdx
leaq 0x10(%rsp), %rcx
leaq 0x18(%rsp), %r8
leaq 0xd573(%rip), %r13      # 0x108c0
leaq 0x5f10(%rip), %r12      # 0x9264
callq 0x24d3
jmp 0x3383
callq 0x5edc
jmp 0x3383
callq 0x40b4
jmp 0x3383
callq 0x418b
jmp 0x3383
cmpl $0x20, %eax
je 0x338e
leaq 0x67c6(%rip), %rdi      # 0x9b42
xorl %eax, %eax
callq 0x2030
cmpl $0x0, 0x18(%rsp)
jne 0x32a9
movl 0x4(%rsp), %esi
xorl %edi, %edi
callq 0x35b4
pushq $0x1
popq %rdi
movl 0x20(%rsp), %esi
callq 0x35b4
movslq 0x4(%rsp), %rax
imulq $0x34, %rax, %rax
leaq 0xc5db(%rip), %rcx      # 0xf990
cmpl $0x0, 0x20(%rcx,%rax)
je 0x2f37
pushq $0x1
popq %rdi
pushq $0x17
popq %rbx
movl %ebx, %esi
callq 0x4dbd
leaq 0x5f7e(%rip), %rdi      # 0x9352
xorl %eax, %eax
callq 0x2030
pushq $0xe
popq %rdi
movl %ebx, %esi
callq 0x4dbd
movslq 0x4(%rsp), %rax
imulq $0x34, %rax, %rdi
leaq 0xc59b(%rip), %rbx      # 0xf990
addq %rbx, %rdi
callq 0x274e
movslq 0x4(%rsp), %rax
imulq $0x34, %rax, %rax
movq 0x30(%rsp), %rcx
movdqu (%rcx), %xmm0
movdqu 0x10(%rbx,%rax), %xmm1
psubd %xmm1, %xmm0
movdqu %xmm0, (%rcx)
xorl %edi, %edi
movl 0x14(%rsp), %ebx
movl %ebx, %esi
callq 0x35b4
movl %ebx, %edi
movl 0x20(%rsp), %esi
leaq 0x8(%rsp), %rdx
leaq 0x10(%rsp), %rcx
leaq 0x18(%rsp), %r8
callq 0x24d3
jmp 0x2f37
movsd 0x5df7(%rip), %xmm1     # 0x9248
ucomisd %xmm0, %xmm1
seta %cl
cmpl $0x3c, %eax
setl %al
movsd 0x5dea(%rip), %xmm1     # 0x9250
ucomisd %xmm0, %xmm1
ja 0x31d1
andb %al, %cl
je 0x31e7
jmp 0x31d1
xorl %edi, %edi
movl 0x14(%rsp), %esi
callq 0x35b4
pushq $0x1
popq %rdi
movl 0x20(%rsp), %esi
callq 0x35b4
movl 0xc(%rsp), %edi
callq 0x4248
movslq 0xc(%rsp), %rax
imulq $0x18, %rax, %rax
leaq 0xcfe3(%rip), %rcx      # 0x10490
movl (%rcx,%rax), %edi
movl 0x4(%rcx,%rax), %esi
callq 0x7107
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq