// File: /workspace/github_c_makefile_star2_O2/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 0x6db0(%rip), %r15      # 0xec20
cmpl $0x0, (%r15,%rdx,8)
je 0x7e9d
leaq 0x7b12(%rip), %rax      # 0xf990
addq $0x58, %rax
pushq $0x1
popq %rcx
cmpl %edx, -0x4(%rax)
jne 0x7e8f
cmpl $0x0, (%rax)
je 0x7e97
incl %ecx
addq $0x34, %rax
jmp 0x7e85
movl %ecx, 0x4(%rsp)
jmp 0x7eb5
leaq 0x4(%rsp), %rsi
xorl %edi, %edi
callq 0x2990
movslq 0x30(%r14), %rax
movl $0x1, (%r15,%rax,8)
movl 0x4(%r14), %eax
movl 0x1c(%r14), %ecx
pushq $0x14
popq %rsi
cltd
idivl %esi
movl %ebx, %edx
testl %ecx, %ecx
jne 0x7eea
cmpl $0x0, 0x20(%r14)
jne 0x7ee8
movl 0x18(%r14), %esi
cmpl %eax, %esi
jge 0x7ee8
cmpl $0x8, %edx
jl 0x7ee8
addl $-0x8, %edx
incl %esi
movl %esi, 0x18(%r14)
jmp 0x7ec5
movl %edx, %ebx
cmpl $0x46, %ebx
jl 0x7f31
pushq $0x5
popq %rdi
callq 0x4e19
cmpl $0x1, %eax
jne 0x7f02
movl 0x1c(%r14), %ecx
jmp 0x7f36
pushq $0x7
popq %rdi
callq 0x4e19
movl 0x1c(%r14), %ecx
cmpl $0x2, %ecx
jl 0x7f36
leal 0x3(%rcx), %edx
cmpl %edx, %eax
jg 0x7f36
addl $-0x46, %ebx
movslq 0x4(%rsp), %rax
imulq $0x34, %rax, %rax
leaq 0x7a63(%rip), %rdx      # 0xf990
incl 0x1c(%rdx,%rax)
cmpl $0x23, %ebx
jl 0x7f56
cmpl $0x4, %ecx
jl 0x7f48
pushq $0x2
popq %rdi
callq 0x4e19
cmpl $0x2, %eax
jne 0x7f56
cmpl $0x0, 0x20(%r14)
jne 0x7f56
addl $-0x23, %ebx
incl 0x1c(%r14)
pushq $0xc
popq %rbp
movl $0x418, %r12d           # imm = 0x418
leaq 0x6e1a(%rip), %r13      # 0xed80
pushq $0x6
popq %r15
cmpl $0x9, %ebx
jl 0x80d6
movl %ebp, %edi
callq 0x4e19
cmpl $0xc, %eax
ja 0x80a5
btl %eax, %r12d
jb 0x804f
btl %eax, %r15d
jb 0x8070
movl $0x1800, %ecx           # imm = 0x1800
btl %eax, %ecx
jae 0x80a5
movl 0x10(%r14), %eax
cvtsi2ss %eax, %xmm0
movl 0x4(%r14), %ecx
cvtsi2ss %ecx, %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x2063(%rip), %xmm1     # 0xa028
ucomisd %xmm0, %xmm1
ja 0x80a9
cmpl $0x23, %ecx
jl 0x7fe1
movl 0x14(%r14), %ecx
cmpl $0x4f, %ecx
jle 0x80ad
cmpl $0x0, 0x20(%r14)
jne 0x7f6a
pushq $0x2
popq %rdi
callq 0x4e19
movl %eax, %ecx
addl $0x6, %ecx
movl 0x10(%r14), %edx
leal -0x1(%rdx), %eax
cmpl %eax, %ecx
jge 0x800f
pushq $0x2
popq %rdi
callq 0x4e19
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
leaq 0x794a(%rip), %rcx      # 0xf990
addl %esi, 0x14(%rcx,%rax)
jmp 0x7f6a
cmpl $0x10, %ebx
jb 0x8087
addl $-0x10, %ebx
movslq 0x4(%rsp), %rax
imulq $0x34, %rax, %rax
leaq 0x7929(%rip), %rcx      # 0xf990
incl 0x18(%rcx,%rax)
jmp 0x7f6a
movsbl (%r13), %esi
xorl %edi, %edi
pushq $0x8
popq %rdx
callq 0x77c6
addl $-0x8, %ebx
jmp 0x7f6a
cmpl $0x0, 0x20(%r14)
je 0x80ca
addl $-0x9, %ebx
movsbl (%r13), %esi
xorl %edi, %edi
pushq $0x9
popq %rdx
callq 0x77c6
jmp 0x7f6a
movl 0x10(%r14), %eax
movl 0x14(%r14), %ecx
addl %eax, %eax
subl %ecx, %eax
cmpl $0x3, %eax
pushq $0x3
popq %rdx
cmovgel %edx, %eax
imull $-0x3, %eax, %edx
addl %edx, %ebx
addl %ecx, %eax
movl %eax, 0x14(%r14)
jmp 0x7f6a
addl $-0x8, %ebx
incl 0x18(%r14)
jmp 0x7f6a
movl 0x4(%rsp), %esi
xorl %edi, %edi
callq 0x35b4
movsbl (%r13), %esi
xorl %edi, %edi
movl %ebx, %edx
callq 0x77c6
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq