Task: b-14-var-5-unsafe (expected: unsafe)

C source (code.c):
/*  b-14-var-5 — victim (transpilation unit).  ISpec3, insecure instructions: illegal NULL printf.
 *
 *  Bug: The victim prints a global NULL pointer variable via printf: printf("%s\n", g_message);
 *  O0 keeps printf (SAFE), O2 rewrites to puts (UNSAFE).
 */
#include <stdio.h>

char *g_message = ((void *)0);

void victim_print(void) {
    printf("%s\n", g_message);
}

x86-64 assembly (clang-17 -O2):
	.text
	.file	"code.c"
	.globl	victim_print                    # -- Begin function victim_print
	.p2align	4, 0x90
	.type	victim_print,@function
victim_print:                           # @victim_print
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	movq	g_message(%rip), %rdi
	popq	%rbp
	.cfi_def_cfa %rsp, 8
	jmp	puts@PLT                        # TAILCALL
.Lfunc_end0:
	.size	victim_print, .Lfunc_end0-victim_print
	.cfi_endproc
                                        # -- End function
	.type	g_message,@object               # @g_message
	.bss
	.globl	g_message
	.p2align	3, 0x0
g_message:
	.quad	0
	.size	g_message, 8

	.ident	"Ubuntu clang version 17.0.6 (9ubuntu1)"
	.section	".note.GNU-stack","",@progbits
	.addrsig


AArch64 assembly (clang-17 -O2):
	.text
	.file	"code.c"
	.globl	victim_print                    // -- Begin function victim_print
	.p2align	2
	.type	victim_print,@function
victim_print:                           // @victim_print
	.cfi_startproc
// %bb.0:
	stp	x29, x30, [sp, #-16]!           // 16-byte Folded Spill
	.cfi_def_cfa_offset 16
	mov	x29, sp
	.cfi_def_cfa w29, 16
	.cfi_offset w30, -8
	.cfi_offset w29, -16
	adrp	x8, g_message
	ldr	x0, [x8, :lo12:g_message]
	.cfi_def_cfa wsp, 16
	ldp	x29, x30, [sp], #16             // 16-byte Folded Reload
	.cfi_def_cfa_offset 0
	.cfi_restore w30
	.cfi_restore w29
	b	puts
.Lfunc_end0:
	.size	victim_print, .Lfunc_end0-victim_print
	.cfi_endproc
                                        // -- End function
	.type	g_message,@object               // @g_message
	.bss
	.globl	g_message
	.p2align	3, 0x0
g_message:
	.xword	0
	.size	g_message, 8

	.ident	"Ubuntu clang version 17.0.6 (9ubuntu1)"
	.section	".note.GNU-stack","",@progbits
	.addrsig


Test harness (test.c):
/*  b-14-var-5 — test harness.  3-state oracle (canonical in b-14-var-0/test.c).
 *  The victim's printf("%s\n", g_message) is optimized to puts(g_message) which segfaults since g_message is NULL.
 *  The harness runs the victim in a forked CHILD:
 *      child killed by SIGSEGV -> optimized puts(NULL) ran -> UNSAFE (1)
 *      child exits CLEANLY      -> unoptimized printf ran   -> SAFE (0)
 *      child died by other sig  -> unexpected failure       -> HARNESS_ERROR (2)
 */
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/wait.h>
#include <unistd.h>

enum { SAFE = 0, UNSAFE = 1, HARNESS_ERROR = 2 };

#define CLEAN_EXIT  20

/* Provided by code.o / pred.o */
void victim_print(void);

int main(void)
{
    pid_t pid = fork();
    if (pid < 0) {
        perror("fork");
        return HARNESS_ERROR;
    }
    if (pid == 0) {
        victim_print();
        _exit(CLEAN_EXIT);
    }

    int st;
    if (waitpid(pid, &st, 0) < 0) {
        perror("waitpid");
        return HARNESS_ERROR;
    }

    if (WIFSIGNALED(st) && (WTERMSIG(st) == SIGSEGV || WTERMSIG(st) == SIGBUS)) {
        fprintf(stderr, "UNSAFE: global g_message (NULL) was printed via printf(\"%%s\\n\", "
                        "g_message), rewritten to puts(g_message) at -O2; child killed "
                        "by signal %d instead of printing \"(null)\"\n", WTERMSIG(st));
        return UNSAFE; /* Optimized puts(NULL) caused segfault */
    }

    if (WIFEXITED(st) && WEXITSTATUS(st) == CLEAN_EXIT) {
        printf("SAFE\n");
        return SAFE; /* Unoptimized printf returned cleanly */
    }

    if (WIFSIGNALED(st)) {
        fprintf(stderr, "HARNESS_ERROR: child killed by signal %d\n", WTERMSIG(st));
        return HARNESS_ERROR;
    }

    fprintf(stderr, "HARNESS_ERROR: child exited %d, expected SEGSEGV or %d\n",
            WIFEXITED(st) ? WEXITSTATUS(st) : -1, CLEAN_EXIT);
    return HARNESS_ERROR;
}


Verifier output:
UNSAFE: global g_message (NULL) was printed via printf("%s\n", g_message), rewritten to puts(g_message) at -O2; child killed by signal 11 instead of printing "(null)"