Coding Challenge (C amd64 Linux)

What does this output and how does it work?

#include <stdio.h>

#define TAUNT 1

void taunt1(void)
{
    printf("skill\n");
}

void taunt2(void)
{
    printf("issue\n");
}

void dispatch(void)
{
    asm volatile goto(
        "mov %0, %%rcx\n"
        "test %%rcx, %%rcx\n"
        "jz %l[taunt1]\n"
        "jmp %l[taunt2]\n"
        : : "i"(TAUNT) : "rcx" : taunt2, taunt1
    );
    
taunt1:
    taunt1();
    return;

taunt2:
    taunt2();
    return;
}

int main(void)
{
    dispatch();

    return 0;
}
Was this page helpful?