// File: /workspace/github_c_makefile_star2_O3/beejjorgensen[P]conquest/conqve.c
// Function: inv_enemy
void inv_enemy(struct stplanet *planet)
{
    int inv_amount, balance, min_mb, transports, new_tf;
    int trash1, trash2;

    balance = planet->iu;
    if (tf_stars[planet->pstar][ENEMY] == 0) {
        get_tf(ENEMY, &new_tf, planet->pstar);
        tf_stars[planet->pstar][ENEMY] = 1;
    } else {                    /*use present tf */
        new_tf = 1;
        while ((tf[ENEMY][new_tf].dest != planet->pstar)
               || (tf[ENEMY][new_tf].eta != 0))
            new_tf = new_tf + 1;
    };
    min_mb = planet->capacity / 20;
    while (((planet->amb == 0) && (!planet->conquered) &&
            (planet->mb < min_mb) && (balance >= mb_cost))) {
        balance = balance - mb_cost;
        planet->mb = planet->mb + 1;
    };
    if ((balance >= b_cost) && (rnd(5) != 1)
        && (rnd(07) <= planet->amb + 3)
        && (planet->amb > 1)) {
        balance = balance - b_cost;
        tf[ENEMY][new_tf].b++;
    };
    if ((balance >= amb_cost) && ((planet->amb < 4) || (rnd(2) == 2))
        && (!planet->conquered)) {
        balance = balance - amb_cost;
        planet->amb++;
    };
    while (balance >= 9) {
        switch (rnd(12)) {
        case 1:
        case 2:
            research(ENEMY, en_research, 8);
            balance = balance - 8;
            break;

        default:
            inv_amount =
                MIN(3, planet->inhabitants * iu_ratio - planet->iu);
            balance = balance - i_cost * inv_amount;
            planet->iu = planet->iu + inv_amount;
            break;

        case 3:
        case 4:
        case 10:
            if (balance >= c_cost) {
                balance = balance - c_cost;
                tf[ENEMY][new_tf].c++;
            } else if ((!planet->conquered) && (balance >= mb_cost)
                ) {
                balance = balance - mb_cost;
                planet->mb = planet->mb + 1;
            } else {
                balance = balance - 9;
                research(ENEMY, en_research, 9);
            };
            break;

        case 11:
        case 12:
            if (((float) planet->inhabitants / planet->capacity < 0.6) || ((planet->capacity >= b_cost / iu_ratio) && (planet->iu < b_cost + 10))) {    /*no t"s */
                inv_amount =
                    MIN(3, planet->inhabitants * iu_ratio - planet->iu);
                balance = balance - inv_amount * i_cost;
                planet->iu = planet->iu + inv_amount;
            } else /*build transports */ if (!(planet->conquered)) {
                transports = MIN(rnd(2) + 6, planet->inhabitants - 1);
                if (planet->iu > b_cost)
                    transports = MIN(transports, planet->iu - b_cost);
                balance = balance - transports;
                planet->inhabitants = planet->inhabitants - transports;
                trash1 = planet->iu - transports;
                trash2 = planet->inhabitants * iu_ratio;
                planet->iu = MIN(trash1, trash2);
                tf[ENEMY][new_tf].t = tf[ENEMY][new_tf].t + transports;
            };
            break;
            /*
               balance = balance - s_cost;
               tf[ENEMY][new_tf].s = tf[ENEMY][new_tf].s + 1;
               if ( debug ) write(tty, "s ");
             */
        };                      /*switch ( */
    };                          /*while ( */
    zero_tf(ENEMY, new_tf);
    research(ENEMY, en_research, balance);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
movl 0x14(%rdi), %ebx
movslq 0x30(%rdi), %rdx
leaq 0x5898(%rip), %r15      # 0xdc20
cmpl $0x0, (%r15,%rdx,8)
je 0x83b7
leaq 0x65fa(%rip), %rax      # 0xe990
addq $0x58, %rax
movl $0x1, %ecx
cmpl %edx, -0x4(%rax)
jne 0x83a9
cmpl $0x0, (%rax)
je 0x83b1
incl %ecx
addq $0x34, %rax
jmp 0x839f
movl %ecx, 0x4(%rsp)
jmp 0x83cf
leaq 0x4(%rsp), %rsi
xorl %edi, %edi
callq 0x2ac4
movslq 0x30(%r14), %rax
movl $0x1, (%r15,%rax,8)
movl 0x1c(%r14), %ecx
testl %ecx, %ecx
jne 0x8417
movl 0x20(%r14), %eax
testl %eax, %eax
jne 0x8417
movslq 0x4(%r14), %rdx
imulq $0x66666667, %rdx, %rdx # imm = 0x66666667
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x23, %rdx
addl %esi, %edx
movl 0x18(%r14), %edi
movl %ebx, %esi
cmpl %edx, %edi
jge 0x8415
cmpl $0x8, %esi
jl 0x8415
addl $-0x8, %esi
incl %edi
movl %edi, 0x18(%r14)
testl %eax, %eax
je 0x83fd
jmp 0x8417
movl %esi, %ebx
cmpl $0x46, %ebx
jl 0x8462
movl $0x5, %edi
callq 0x4fd5
cmpl $0x1, %eax
jne 0x8431
movl 0x1c(%r14), %ecx
jmp 0x8467
movl $0x7, %edi
callq 0x4fd5
movl 0x1c(%r14), %ecx
cmpl $0x2, %ecx
jl 0x8467
leal 0x3(%rcx), %edx
cmpl %edx, %eax
jg 0x8467
addl $-0x46, %ebx
movslq 0x4(%rsp), %rax
imulq $0x34, %rax, %rax
leaq 0x6532(%rip), %rdx      # 0xe990
incl 0x1c(%rdx,%rax)
cmpl $0x23, %ebx
jl 0x8489
cmpl $0x4, %ecx
jl 0x847b
movl $0x2, %edi
callq 0x4fd5
cmpl $0x2, %eax
jne 0x8492
cmpl $0x0, 0x20(%r14)
jne 0x8492
addl $-0x23, %ebx
incl 0x1c(%r14)
cmpl $0x9, %ebx
jl 0x85eb
movl $0x418, %r12d           # imm = 0x418
leaq 0x64f1(%rip), %r13      # 0xe990
movl $0x6, %r15d
movl $0x1800, %ebp           # imm = 0x1800
movl $0xc, %edi
callq 0x4fd5
cmpl $0xc, %eax
ja 0x85c0
btl %eax, %r12d
jb 0x8589
btl %eax, %r15d
jb 0x85a5
btl %eax, %ebp
jae 0x85c0
movl 0x10(%r14), %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movl 0x4(%r14), %ecx
xorps %xmm1, %xmm1
cvtsi2ss %ecx, %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x1b68(%rip), %xmm1     # 0xa068
ucomisd %xmm0, %xmm1
ja 0x85c4
cmpl $0x23, %ecx
jl 0x851c
movl 0x14(%r14), %ecx
cmpl $0x4f, %ecx
jle 0x85c8
cmpl $0x0, 0x20(%r14)
jne 0x85e2
movl $0x2, %edi
callq 0x4fd5
movl %eax, %ecx
addl $0x6, %ecx
movl 0x10(%r14), %edx
leal -0x1(%rdx), %eax
cmpl %eax, %ecx
jge 0x8552
movl $0x2, %edi
callq 0x4fd5
addl $0x6, %eax
movl 0x10(%r14), %edx
movl 0x14(%r14), %ecx
leal -0x46(%rcx), %esi
cmpl %esi, %eax
cmovll %eax, %esi
cmpl $0x47, %ecx
cmovll %eax, %esi
subl %esi, %ebx
subl %esi, %edx
movl %edx, 0x10(%r14)
subl %esi, %ecx
addl %edx, %edx
cmpl %edx, %ecx
cmovll %ecx, %edx
movl %edx, 0x14(%r14)
movslq 0x4(%rsp), %rax
imulq $0x34, %rax, %rax
addl %esi, 0x14(%r13,%rax)
jmp 0x85e2
cmpl $0x10, %ebx
jb 0x8618
addl $-0x10, %ebx
movslq 0x4(%rsp), %rax
imulq $0x34, %rax, %rax
incl 0x18(%r13,%rax)
jmp 0x85e2
leaq 0x57d4(%rip), %rax      # 0xdd80
movsbl (%rax), %esi
xorl %edi, %edi
movl $0x8, %edx
callq 0x7c5d
addl $-0x8, %ebx
jmp 0x85e2
movl 0x10(%r14), %eax
movl 0x14(%r14), %ecx
addl %eax, %eax
subl %ecx, %eax
cmpl $0x3, %eax
movl $0x3, %edx
cmovgel %edx, %eax
leal (%rax,%rax,2), %edx
subl %edx, %ebx
addl %ecx, %eax
movl %eax, 0x14(%r14)
cmpl $0x8, %ebx
jg 0x84aa
movl 0x4(%rsp), %esi
xorl %edi, %edi
callq 0x36f5
leaq 0x5783(%rip), %rax      # 0xdd80
movsbl (%rax), %esi
xorl %edi, %edi
movl %ebx, %edx
callq 0x7c5d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x0, 0x20(%r14)
je 0x863a
addl $-0x9, %ebx
leaq 0x5757(%rip), %rax      # 0xdd80
movsbl (%rax), %esi
xorl %edi, %edi
movl $0x9, %edx
callq 0x7c5d
jmp 0x85eb
addl $-0x8, %ebx
incl 0x18(%r14)
jmp 0x85eb