// File: /workspace/github_c_makefile_star2_O1/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, %rbx
movl 0x14(%rdi), %r14d
movslq 0x30(%rdi), %rdx
leaq 0x580f(%rip), %r15      # 0xdc30
cmpl $0x0, (%r15,%rdx,8)
je 0x8450
leaq 0x6571(%rip), %rax      # 0xe9a0
addq $0x58, %rax
movl $0x1, %ecx
cmpl %edx, -0x4(%rax)
jne 0x8442
cmpl $0x0, (%rax)
je 0x844a
incl %ecx
addq $0x34, %rax
jmp 0x8438
movl %ecx, 0x4(%rsp)
jmp 0x8468
leaq 0x4(%rsp), %rsi
xorl %edi, %edi
callq 0x2a18
movslq 0x30(%rbx), %rax
movl $0x1, (%r15,%rax,8)
movl 0x1c(%rbx), %eax
testl %eax, %eax
je 0x8693
movl %r14d, %ebp
cmpl $0x46, %ebp
jl 0x84ba
movl $0x5, %edi
callq 0x4fc5
cmpl $0x1, %eax
je 0x84ba
movl $0x7, %edi
callq 0x4fc5
movl 0x1c(%rbx), %ecx
cmpl $0x2, %ecx
jl 0x84ba
addl $0x3, %ecx
cmpl %ecx, %eax
jg 0x84ba
addl $-0x46, %ebp
movslq 0x4(%rsp), %rax
imulq $0x34, %rax, %rax
leaq 0x64ea(%rip), %rcx      # 0xe9a0
incl 0x1c(%rcx,%rax)
cmpl $0x23, %ebp
jl 0x84e0
cmpl $0x4, 0x1c(%rbx)
jl 0x84d4
movl $0x2, %edi
callq 0x4fc5
cmpl $0x2, %eax
jne 0x84e0
cmpl $0x0, 0x20(%rbx)
jne 0x84e0
addl $-0x23, %ebp
incl 0x1c(%rbx)
cmpl $0x9, %ebp
jl 0x8666
movl $0x418, %r15d           # imm = 0x418
leaq 0x589a(%rip), %r13      # 0xdd90
movl $0x6, %r12d
movl $0x1800, %r14d          # imm = 0x1800
movl $0xc, %edi
callq 0x4fc5
cmpl $0xc, %eax
ja 0x85b4
btl %eax, %r15d
jb 0x8560
btl %eax, %r12d
jb 0x857e
btl %eax, %r14d
jae 0x85b4
movl 0x10(%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movl 0x4(%rbx), %ecx
xorps %xmm1, %xmm1
cvtsi2ss %ecx, %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x1ac9(%rip), %xmm1     # 0xa018
ucomisd %xmm0, %xmm1
jbe 0x85e1
addl %eax, %eax
movl 0x14(%rbx), %ecx
jmp 0x85bc
cmpl $0x10, %ebp
jl 0x8594
addl $-0x10, %ebp
movslq 0x4(%rsp), %rax
imulq $0x34, %rax, %rax
leaq 0x6428(%rip), %rcx      # 0xe9a0
incl 0x18(%rcx,%rax)
jmp 0x85d3
movsbl (%r13), %esi
xorl %edi, %edi
movl $0x8, %edx
callq 0x7cc9
addl $-0x8, %ebp
jmp 0x85d3
cmpl $0x0, 0x20(%rbx)
je 0x865b
addl $-0x9, %ebp
movsbl (%r13), %esi
xorl %edi, %edi
movl $0x9, %edx
callq 0x7cc9
jmp 0x85d3
movl 0x10(%rbx), %eax
movl 0x14(%rbx), %ecx
addl %eax, %eax
subl %ecx, %eax
cmpl $0x3, %eax
movl $0x3, %edx
cmovgel %edx, %eax
leal (%rax,%rax,2), %edx
subl %edx, %ebp
addl %ecx, %eax
movl %eax, 0x14(%rbx)
cmpl $0x8, %ebp
jg 0x8502
jmp 0x8666
cmpl $0x23, %ecx
jl 0x85f0
cmpl $0x4f, 0x14(%rbx)
jle 0x8559
cmpl $0x0, 0x20(%rbx)
jne 0x85d3
movl $0x2, %edi
callq 0x4fc5
movl %eax, %ecx
addl $0x6, %ecx
movl 0x10(%rbx), %eax
decl %eax
cmpl %eax, %ecx
jge 0x861b
movl $0x2, %edi
callq 0x4fc5
addl $0x6, %eax
movl 0x10(%rbx), %ecx
movl 0x14(%rbx), %edx
leal -0x46(%rdx), %esi
cmpl %esi, %eax
cmovll %eax, %esi
cmpl $0x47, %edx
cmovll %eax, %esi
subl %esi, %ebp
subl %esi, %ecx
movl %ecx, 0x10(%rbx)
subl %esi, %edx
addl %ecx, %ecx
cmpl %ecx, %edx
cmovll %edx, %ecx
movl %ecx, 0x14(%rbx)
movslq 0x4(%rsp), %rax
imulq $0x34, %rax, %rax
leaq 0x634e(%rip), %rcx      # 0xe9a0
addl %esi, 0x14(%rcx,%rax)
jmp 0x85d3
addl $-0x8, %ebp
incl 0x18(%rbx)
jmp 0x85d3
movl 0x4(%rsp), %esi
xorl %edi, %edi
callq 0x3695
leaq 0x5718(%rip), %rax      # 0xdd90
movsbl (%rax), %esi
xorl %edi, %edi
movl %ebp, %edx
callq 0x7cc9
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq 0x4(%rbx), %rcx
imulq $0x66666667, %rcx, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x23, %rcx
addl %edx, %ecx
movl 0x20(%rbx), %edx
movl %r14d, %ebp
testl %edx, %edx
jne 0x8473
movl 0x18(%rbx), %esi
cmpl %ecx, %esi
jge 0x8476
cmpl $0x8, %ebp
jl 0x8476
addl $-0x8, %ebp
incl %esi
movl %esi, 0x18(%rbx)
testl %eax, %eax
je 0x86b1
jmp 0x8476