// File: /workspace/github_c_makefile_star2_O0/Ziddykins[P]Dawn/src/market.c
// Function: market_buysell
void market_buysell(struct Message *m, int buysell, char *which, long amount) {
    int pindex = get_pindex(m->sender_nick);
    int material = get_itemID(which);
    char out[MAX_MESSAGE_BUFFER];

    if (material == -1 || amount < 1 || amount >= LONG_MAX) return;

    if (buysell == 0) {
        //sell
        if (dawn->players[pindex].materials[material] >= amount) {
            if (dawn->players[pindex].gold + dawn->market.materials[material] * amount >= LONG_MAX) {
                sprintf(out, "PRIVMSG %s :%s, you can't carry that much gold\r\n", m->receiver, m->sender_nick);
                add_msg(out, strlen(out));
                return;
            }
            dawn->players[pindex].materials[material] -= amount;
            dawn->players[pindex].gold += dawn->market.materials[material] * amount;
            sprintf(out, "PRIVMSG %s :%s, you have sold %ld %s for %ld gold\r\n",
                    m->receiver, m->sender_nick, amount, which, dawn->market.materials[material] * amount);

        } else {
            sprintf(out, "PRIVMSG %s :%s, you do not have enough %s to do that\r\n",
                    m->receiver, m->sender_nick, which);
        }
    } else {
        //buy
        if (dawn->players[pindex].materials[material] + amount >= LONG_MAX) {
            sprintf(out, "PRIVMSG %s :%s, you can't carry anymore %s\r\n", m->receiver, m->sender_nick, which);
            add_msg(out, strlen(out));
            return;
        }
        if (dawn->players[pindex].gold >= dawn->market.materials[material] * amount) {
            dawn->players[pindex].gold -= dawn->market.materials[material] * amount;
            dawn->players[pindex].materials[material] += amount;
            sprintf(out, "PRIVMSG %s :%s, you have purchased %ld %s for %ld gold\r\n",
                    m->receiver, m->sender_nick, amount, which, dawn->market.materials[material] * amount);
        } else {
            sprintf(out, "PRIVMSG %s :%s, you do not have enough gold to purchase that much %s\r\n",
                    m->receiver, m->sender_nick, which);
        }
    }
    add_msg(out, strlen(out));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1e0, %rsp            # imm = 0x1E0
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0x13ba0
movl %eax, -0x24(%rbp)
movq -0x18(%rbp), %rdi
callq 0x104a0
movl %eax, -0x28(%rbp)
cmpl $-0x1, -0x28(%rbp)
je 0x100af
cmpq $0x1, -0x20(%rbp)
jl 0x100af
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
cmpq %rax, -0x20(%rbp)
jl 0x100b4
jmp 0x1048c
cmpl $0x0, -0xc(%rbp)
jne 0x10290
leaq 0x189ab(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x24(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movslq -0x28(%rbp), %rcx
movq 0x25f8(%rax,%rcx,8), %rax
cmpq -0x20(%rbp), %rax
jl 0x10263
leaq 0x18977(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x24(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movq 0x2648(%rax), %rax
leaq 0x18952(%rip), %rcx     # 0x28a70
movq (%rcx), %rcx
movslq -0x28(%rbp), %rdx
movslq 0xf2e78(%rcx,%rdx,4), %rcx
imulq -0x20(%rbp), %rcx
addq %rcx, %rax
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
cmpq %rcx, %rax
jl 0x10196
leaq -0x1c0(%rbp), %rdi
movq -0x8(%rbp), %rdx
addq $0xc0, %rdx
movq -0x8(%rbp), %rcx
leaq 0xf3f1(%rip), %rsi      # 0x1f552
movb $0x0, %al
callq 0x2050
leaq -0x1c0(%rbp), %rax
movq %rax, -0x1c8(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x20c0
movq -0x1c8(%rbp), %rdi
movq %rax, %rsi
callq 0x12840
jmp 0x1048c
movq -0x20(%rbp), %rsi
leaq 0x188cf(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x24(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movslq -0x28(%rbp), %rcx
movq 0x25f8(%rax,%rcx,8), %rdx
subq %rsi, %rdx
movq %rdx, 0x25f8(%rax,%rcx,8)
leaq 0x1889a(%rip), %rax     # 0x28a70
movq (%rax), %rax
movslq -0x28(%rbp), %rcx
movslq 0xf2e78(%rax,%rcx,4), %rcx
imulq -0x20(%rbp), %rcx
leaq 0x1887f(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x24(%rbp), %rdx
imulq $0x26a8, %rdx, %rdx     # imm = 0x26A8
addq %rdx, %rax
addq 0x2648(%rax), %rcx
movq %rcx, 0x2648(%rax)
leaq -0x1c0(%rbp), %rdi
movq -0x8(%rbp), %rdx
addq $0xc0, %rdx
movq -0x8(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x18(%rbp), %r9
leaq 0x18835(%rip), %rax     # 0x28a70
movq (%rax), %rax
movslq -0x28(%rbp), %rsi
movslq 0xf2e78(%rax,%rsi,4), %rax
imulq -0x20(%rbp), %rax
leaq 0xf32d(%rip), %rsi      # 0x1f583
movq %rax, (%rsp)
movb $0x0, %al
callq 0x2050
jmp 0x1028b
leaq -0x1c0(%rbp), %rdi
movq -0x8(%rbp), %rdx
addq $0xc0, %rdx
movq -0x8(%rbp), %rcx
movq -0x18(%rbp), %r8
leaq 0xf333(%rip), %rsi      # 0x1f5b7
movb $0x0, %al
callq 0x2050
jmp 0x10463
leaq 0x187d9(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x24(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movslq -0x28(%rbp), %rcx
movq 0x25f8(%rax,%rcx,8), %rax
addq -0x20(%rbp), %rax
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
cmpq %rcx, %rax
jl 0x10323
leaq -0x1c0(%rbp), %rdi
movq -0x8(%rbp), %rdx
addq $0xc0, %rdx
movq -0x8(%rbp), %rcx
movq -0x18(%rbp), %r8
leaq 0xf300(%rip), %rsi      # 0x1f5ee
movb $0x0, %al
callq 0x2050
leaq -0x1c0(%rbp), %rax
movq %rax, -0x1d0(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x20c0
movq -0x1d0(%rbp), %rdi
movq %rax, %rsi
callq 0x12840
jmp 0x1048c
leaq 0x18746(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x24(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movq 0x2648(%rax), %rax
leaq 0x18721(%rip), %rcx     # 0x28a70
movq (%rcx), %rcx
movslq -0x28(%rbp), %rdx
movslq 0xf2e78(%rcx,%rdx,4), %rcx
imulq -0x20(%rbp), %rcx
cmpq %rcx, %rax
jl 0x10439
leaq 0x186fd(%rip), %rax     # 0x28a70
movq (%rax), %rax
movslq -0x28(%rbp), %rcx
movslq 0xf2e78(%rax,%rcx,4), %rdx
imulq -0x20(%rbp), %rdx
leaq 0x186e2(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x24(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movq 0x2648(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x2648(%rax)
movq -0x20(%rbp), %rdx
leaq 0x186af(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x24(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movslq -0x28(%rbp), %rcx
addq 0x25f8(%rax,%rcx,8), %rdx
movq %rdx, 0x25f8(%rax,%rcx,8)
leaq -0x1c0(%rbp), %rdi
movq -0x8(%rbp), %rdx
addq $0xc0, %rdx
movq -0x8(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x18(%rbp), %r9
leaq 0x1865f(%rip), %rax     # 0x28a70
movq (%rax), %rax
movslq -0x28(%rbp), %rsi
movslq 0xf2e78(%rax,%rsi,4), %rax
imulq -0x20(%rbp), %rax
leaq 0xf1ef(%rip), %rsi      # 0x1f61b
movq %rax, (%rsp)
movb $0x0, %al
callq 0x2050
jmp 0x10461
leaq -0x1c0(%rbp), %rdi
movq -0x8(%rbp), %rdx
addq $0xc0, %rdx
movq -0x8(%rbp), %rcx
movq -0x18(%rbp), %r8
leaq 0xf1fa(%rip), %rsi      # 0x1f654
movb $0x0, %al
callq 0x2050
jmp 0x10463
leaq -0x1c0(%rbp), %rax
movq %rax, -0x1d8(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x20c0
movq -0x1d8(%rbp), %rdi
movq %rax, %rsi
callq 0x12840
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbp
retq
nopw %cs:(%rax,%rax)