// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movslq 0x30(%rax), %rcx
leaq 0x676b(%rip), %rax      # 0x12c30
cmpl $0x0, (%rax,%rcx,8)
jne 0xc4f5
movq -0x8(%rbp), %rax
movl 0x30(%rax), %edx
xorl %edi, %edi
leaq -0x1c(%rbp), %rsi
callq 0x2e80
movq -0x8(%rbp), %rax
movslq 0x30(%rax), %rcx
leaq 0x6744(%rip), %rax      # 0x12c30
movl $0x1, (%rax,%rcx,8)
jmp 0xc551
movl $0x1, -0x1c(%rbp)
movslq -0x1c(%rbp), %rcx
leaq 0x7499(%rip), %rax      # 0x139a0
imulq $0x34, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %ecx
movq -0x8(%rbp), %rdx
movb $0x1, %al
cmpl 0x30(%rdx), %ecx
movb %al, -0x25(%rbp)
jne 0xc53b
movslq -0x1c(%rbp), %rcx
leaq 0x7476(%rip), %rax      # 0x139a0
imulq $0x34, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x24(%rax)
setne %al
movb %al, -0x25(%rbp)
movb -0x25(%rbp), %al
testb $0x1, %al
jne 0xc544
jmp 0xc54f
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xc4fc
jmp 0xc551
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl $0x14, %ecx
cltd
idivl %ecx
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rcx
xorl %eax, %eax
cmpl $0x0, 0x1c(%rcx)
movb %al, -0x26(%rbp)
jne 0xc59c
movq -0x8(%rbp), %rcx
xorl %eax, %eax
cmpl $0x0, 0x20(%rcx)
movb %al, -0x26(%rbp)
jne 0xc59c
movq -0x8(%rbp), %rax
movl 0x18(%rax), %ecx
xorl %eax, %eax
cmpl -0x14(%rbp), %ecx
movb %al, -0x26(%rbp)
jge 0xc59c
cmpl $0x8, -0x10(%rbp)
setge %al
movb %al, -0x26(%rbp)
movb -0x26(%rbp), %al
testb $0x1, %al
jne 0xc5a5
jmp 0xc5c1
movl -0x10(%rbp), %eax
subl $0x8, %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x18(%rax), %ecx
addl $0x1, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x18(%rax)
jmp 0xc563
cmpl $0x46, -0x10(%rbp)
jl 0xc61c
movl $0x5, %edi
callq 0x6a70
cmpl $0x1, %eax
je 0xc61c
movl $0x7, %edi
callq 0x6a70
movq -0x8(%rbp), %rcx
movl 0x1c(%rcx), %ecx
addl $0x3, %ecx
cmpl %ecx, %eax
jg 0xc61c
movq -0x8(%rbp), %rax
cmpl $0x1, 0x1c(%rax)
jle 0xc61c
movl -0x10(%rbp), %eax
subl $0x46, %eax
movl %eax, -0x10(%rbp)
movslq -0x1c(%rbp), %rcx
leaq 0x7394(%rip), %rax      # 0x139a0
imulq $0x34, %rcx, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1c(%rax)
cmpl $0x23, -0x10(%rbp)
jl 0xc65b
movq -0x8(%rbp), %rax
cmpl $0x4, 0x1c(%rax)
jl 0xc63b
movl $0x2, %edi
callq 0x6a70
cmpl $0x2, %eax
jne 0xc65b
movq -0x8(%rbp), %rax
cmpl $0x0, 0x20(%rax)
jne 0xc65b
movl -0x10(%rbp), %eax
subl $0x23, %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1c(%rax)
jmp 0xc65d
cmpl $0x9, -0x10(%rbp)
jl 0xc958
movl $0xc, %edi
callq 0x6a70
movl %eax, %ecx
movl %ecx, %eax
decl %eax
movl %ecx, -0x2c(%rbp)
subl $0x2, %eax
jb 0xc6b1
jmp 0xc681
movl -0x2c(%rbp), %eax
addl $-0x3, %eax
subl $0x2, %eax
jb 0xc733
jmp 0xc692
movl -0x2c(%rbp), %eax
subl $0xa, %eax
je 0xc733
jmp 0xc6a0
movl -0x2c(%rbp), %eax
addl $-0xb, %eax
subl $0x2, %eax
jb 0xc7b1
jmp 0xc6d5
xorl %edi, %edi
movl $0x8, %edx
leaq 0x66d1(%rip), %rax      # 0x12d90
movsbl (%rax), %esi
callq 0xb670
movl -0x10(%rbp), %eax
subl $0x8, %eax
movl %eax, -0x10(%rbp)
jmp 0xc953
movq -0x8(%rbp), %rax
movl 0x10(%rax), %ecx
shll %ecx
movq -0x8(%rbp), %rax
subl 0x14(%rax), %ecx
movl $0x3, %eax
cmpl %ecx, %eax
jge 0xc6f8
movl $0x3, %eax
movl %eax, -0x30(%rbp)
jmp 0xc70b
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
shll %eax
movq -0x8(%rbp), %rcx
subl 0x14(%rcx), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0xc(%rbp)
movl -0x10(%rbp), %eax
imull $0x3, -0xc(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %ecx
addl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x14(%rax)
jmp 0xc953
cmpl $0x10, -0x10(%rbp)
jl 0xc75f
movl -0x10(%rbp), %eax
subl $0x10, %eax
movl %eax, -0x10(%rbp)
movslq -0x1c(%rbp), %rcx
leaq 0x7253(%rip), %rax      # 0x139a0
imulq $0x34, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x18(%rax)
jmp 0xc7ac
movq -0x8(%rbp), %rax
cmpl $0x0, 0x20(%rax)
jne 0xc78b
cmpl $0x8, -0x10(%rbp)
jl 0xc78b
movl -0x10(%rbp), %eax
subl $0x8, %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x18(%rax), %ecx
addl $0x1, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x18(%rax)
jmp 0xc7aa
movl -0x10(%rbp), %eax
subl $0x9, %eax
movl %eax, -0x10(%rbp)
xorl %edi, %edi
movl $0x9, %edx
leaq 0x65ee(%rip), %rax      # 0x12d90
movsbl (%rax), %esi
callq 0xb670
jmp 0xc7ac
jmp 0xc953
movq -0x8(%rbp), %rax
cvtsi2ssl 0x10(%rax), %xmm0
movq -0x8(%rbp), %rax
cvtsi2ssl 0x4(%rax), %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x2a5d(%rip), %xmm0     # 0xf230
ucomisd %xmm1, %xmm0
ja 0xc7ed
movq -0x8(%rbp), %rax
cmpl $0x23, 0x4(%rax)
jl 0xc84b
movq -0x8(%rbp), %rax
cmpl $0x50, 0x14(%rax)
jge 0xc84b
movq -0x8(%rbp), %rax
movl 0x10(%rax), %ecx
shll %ecx
movq -0x8(%rbp), %rax
subl 0x14(%rax), %ecx
movl $0x3, %eax
cmpl %ecx, %eax
jge 0xc810
movl $0x3, %eax
movl %eax, -0x34(%rbp)
jmp 0xc823
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
shll %eax
movq -0x8(%rbp), %rcx
subl 0x14(%rcx), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0xc(%rbp)
movl -0x10(%rbp), %eax
imull $0x3, -0xc(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %ecx
addl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x14(%rax)
jmp 0xc951
movq -0x8(%rbp), %rax
cmpl $0x0, 0x20(%rax)
jne 0xc94f
movl $0x2, %edi
callq 0x6a70
addl $0x6, %eax
movq -0x8(%rbp), %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0xc886
movl $0x2, %edi
callq 0x6a70
addl $0x6, %eax
movl %eax, -0x38(%rbp)
jmp 0xc893
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
subl $0x1, %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x46, 0x14(%rax)
jle 0xc8cf
movl -0x18(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x14(%rcx), %ecx
subl $0x46, %ecx
cmpl %ecx, %eax
jge 0xc8bc
movl -0x18(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0xc8c9
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
subl $0x46, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x10(%rbp), %eax
subl -0x18(%rbp), %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %ecx
subl -0x18(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
subl -0x18(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
shll %eax
movl %eax, -0x24(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0xc912
movl -0x20(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0xc918
movl -0x24(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x14(%rax)
movslq -0x1c(%rbp), %rcx
leaq 0x7073(%rip), %rax      # 0x139a0
imulq $0x34, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %ecx
addl -0x18(%rbp), %ecx
movslq -0x1c(%rbp), %rdx
leaq 0x705b(%rip), %rax      # 0x139a0
imulq $0x34, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x14(%rax)
jmp 0xc951
jmp 0xc953
jmp 0xc65d
movl -0x1c(%rbp), %esi
xorl %edi, %edi
callq 0x4280
leaq 0x6427(%rip), %rax      # 0x12d90
movb (%rax), %al
movl -0x10(%rbp), %edx
xorl %edi, %edi
movsbl %al, %esi
callq 0xb670
addq $0x40, %rsp
popq %rbp
retq
nop