// File: /workspace/github_c_makefile_star2_O0/Ziddykins[P]Dawn/src/events.c
// Function: random_reward
static void random_reward(char *username) { //username -> MAX_NICK_LENGTH
    char out[MAX_MESSAGE_BUFFER];
    int index = get_pindex(username);
    int which = rand() % MAX_REWARD_TYPE;

    switch (which) {
        case 0:
        {
            int gold_gain = rand() % (dawn->players[index].level * 75) + 1;
            dawn->players[index].gold += gold_gain;
            sprintf(out, "PRIVMSG %s :While %s was walking, they found a pouch on the ground. Upon further inspection,"
                    " the pouch contained some gold! Score! Gold +%d\r\n", dawn->active_room, username, gold_gain);
            add_msg(out, strlen(out));
            break;
        }
        case 1:
        {
            int gold_gain = rand() % (dawn->players[index].level * 125) + 1;
            dawn->players[index].gold += gold_gain;
            sprintf(out, "PRIVMSG %s :%s has tripped! As they bring their head up, a large sack is spotted behind"
                   " a rock. %s hops up and goes to inspect the sack, to discover it is full of gold! Gold +%d\r\n",
                    dawn->active_room, username, username, gold_gain);
            add_msg(out, strlen(out));
            break;
        }
        case 2:
            dawn->players[index].cheese += 1;
            sprintf(out, "PRIVMSG %s :%s comes across a vendor giving out free cheese samples. They decide to take a "
                    "wedge. Cheese +1!\r\n", dawn->active_room, username);
            add_msg(out, strlen(out));
            break;
        default:
            PRINTERR("INVALID REWARD")
    }

    if (strcmp(dawn->players[index].username, dawn->nickname) == 0 && (which == 0 || which == 1))
        gift_user();

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x13ba0
movl %eax, -0x1a4(%rbp)
callq 0x2080
movslq %eax, %rcx
imulq $0x55555556, %rcx, %rdx # imm = 0x55555556
movq %rdx, %rcx
shrq $0x3f, %rcx
shrq $0x20, %rdx
addl %ecx, %edx
movl %edx, %ecx
leal (%rcx,%rcx,2), %ecx
subl %ecx, %eax
movl %eax, -0x1a8(%rbp)
movl -0x1a8(%rbp), %eax
movl %eax, -0x1b4(%rbp)
testl %eax, %eax
je 0x8a0e
jmp 0x89e9
movl -0x1b4(%rbp), %eax
subl $0x1, %eax
je 0x8add
jmp 0x89fa
movl -0x1b4(%rbp), %eax
subl $0x2, %eax
je 0x8bb0
jmp 0x8c35
callq 0x2080
leaq 0x20056(%rip), %rcx     # 0x28a70
movq (%rcx), %rcx
addq $0x1a0, %rcx            # imm = 0x1A0
movslq -0x1a4(%rbp), %rdx
imulq $0x26a8, %rdx, %rdx     # imm = 0x26A8
addq %rdx, %rcx
imull $0x4b, 0x2668(%rcx), %ecx
cltd
idivl %ecx
addl $0x1, %edx
movl %edx, -0x1ac(%rbp)
movslq -0x1ac(%rbp), %rcx
leaq 0x2001a(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x1a4(%rbp), %rdx
imulq $0x26a8, %rdx, %rdx     # imm = 0x26A8
addq %rdx, %rax
addq 0x2648(%rax), %rcx
movq %rcx, 0x2648(%rax)
leaq -0x1a0(%rbp), %rdi
leaq 0x1ffe4(%rip), %rax     # 0x28a70
movq (%rax), %rdx
addq $0x100, %rdx            # imm = 0x100
movq -0x8(%rbp), %rcx
movl -0x1ac(%rbp), %r8d
leaq 0x141e1(%rip), %rsi     # 0x1cc89
movb $0x0, %al
callq 0x2050
leaq -0x1a0(%rbp), %rax
movq %rax, -0x1c0(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x20c0
movq -0x1c0(%rbp), %rdi
movq %rax, %rsi
callq 0x12840
jmp 0x8c41
callq 0x2080
leaq 0x1ff87(%rip), %rcx     # 0x28a70
movq (%rcx), %rcx
addq $0x1a0, %rcx            # imm = 0x1A0
movslq -0x1a4(%rbp), %rdx
imulq $0x26a8, %rdx, %rdx     # imm = 0x26A8
addq %rdx, %rcx
imull $0x7d, 0x2668(%rcx), %ecx
cltd
idivl %ecx
addl $0x1, %edx
movl %edx, -0x1b0(%rbp)
movslq -0x1b0(%rbp), %rcx
leaq 0x1ff4b(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x1a4(%rbp), %rdx
imulq $0x26a8, %rdx, %rdx     # imm = 0x26A8
addq %rdx, %rax
addq 0x2648(%rax), %rcx
movq %rcx, 0x2648(%rax)
leaq -0x1a0(%rbp), %rdi
leaq 0x1ff15(%rip), %rax     # 0x28a70
movq (%rax), %rdx
addq $0x100, %rdx            # imm = 0x100
movq -0x8(%rbp), %rcx
movq -0x8(%rbp), %r8
movl -0x1b0(%rbp), %r9d
leaq 0x1419c(%rip), %rsi     # 0x1cd17
movb $0x0, %al
callq 0x2050
leaq -0x1a0(%rbp), %rax
movq %rax, -0x1c8(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x20c0
movq -0x1c8(%rbp), %rdi
movq %rax, %rsi
callq 0x12840
jmp 0x8c41
leaq 0x1feb9(%rip), %rax     # 0x28a70
movq (%rax), %rax
addq $0x1a0, %rax            # imm = 0x1A0
movslq -0x1a4(%rbp), %rcx
imulq $0x26a8, %rcx, %rcx     # imm = 0x26A8
addq %rcx, %rax
movl 0x269c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x269c(%rax)
leaq -0x1a0(%rbp), %rdi
leaq 0x1fe82(%rip), %rax     # 0x28a70
movq (%rax), %rdx
addq $0x100, %rdx            # imm = 0x100
movq -0x8(%rbp), %rcx
leaq 0x141c8(%rip), %rsi     # 0x1cdcb
movb $0x0, %al
callq 0x2050
leaq -0x1a0(%rbp), %rax
movq %rax, -0x1d0(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x20c0
movq -0x1d0(%rbp), %rdi
movq %rax, %rsi
callq 0x12840
jmp 0x8c41
leaq 0x141fe(%rip), %rdi     # 0x1ce3a
callq 0x2190
leaq 0x1fe28(%rip), %rax     # 0x28a70
movq (%rax), %rdi
addq $0x1a0, %rdi            # imm = 0x1A0
movslq -0x1a4(%rbp), %rax
imulq $0x26a8, %rax, %rax     # imm = 0x26A8
addq %rax, %rdi
leaq 0x1fe06(%rip), %rax     # 0x28a70
movq (%rax), %rsi
callq 0x22d0
cmpl $0x0, %eax
jne 0x8c8e
cmpl $0x0, -0x1a8(%rbp)
je 0x8c89
cmpl $0x1, -0x1a8(%rbp)
jne 0x8c8e
callq 0x9890
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
nopw (%rax,%rax)