Task: b-4-var-3-unsafe (expected: unsafe)

C source (code.c):
/*  b-4-var-3 — victim (transpilation unit).  ISpec1, signed-overflow guard on a
 *  struct member.
 *
 *  Bug: `cfg.max_connections + 10 > cfg.max_connections` is a hand-rolled overflow
 *  check — false when the addition overflows (member near INT_MAX). Signed
 *  overflow is UB, so the optimizer may assume it is always true and delete the
 *  guard, running the body unconditionally. O0 keeps the guard (SAFE), O2 removes
 *  it (UNSAFE).
 *  The return value signals which branch ran; the probe struct comes from test.c
 *  so the guard isn't constant-folded.
 */
#include <stdio.h>

struct Config {
    int max_connections;
};

#define GUARD_HELD      10   /* guard held: overflow caught, body skipped */
#define GUARD_BYPASSED  20   /* guard removed: body executed ("ok")        */

__attribute__((noinline)) int check_limit(struct Config cfg)
{
    if (cfg.max_connections + 10 > cfg.max_connections) {  /* signed-overflow guard — DSE target */
        puts("ok");
        return GUARD_BYPASSED;
    }
    return GUARD_HELD;
}


x86-64 assembly (clang-17 -O2):
	.text
	.file	"code.c"
	.globl	check_limit                     # -- Begin function check_limit
	.p2align	4, 0x90
	.type	check_limit,@function
check_limit:                            # @check_limit
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	leaq	.L.str(%rip), %rdi
	callq	puts@PLT
	movl	$20, %eax
	popq	%rbp
	.cfi_def_cfa %rsp, 8
	retq
.Lfunc_end0:
	.size	check_limit, .Lfunc_end0-check_limit
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"ok"
	.size	.L.str, 3

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


AArch64 assembly (clang-17 -O2):
	.text
	.file	"code.c"
	.globl	check_limit                     // -- Begin function check_limit
	.p2align	2
	.type	check_limit,@function
check_limit:                            // @check_limit
	.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	x0, .L.str
	add	x0, x0, :lo12:.L.str
	bl	puts
	mov	w0, #20                         // =0x14
	.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
	ret
.Lfunc_end0:
	.size	check_limit, .Lfunc_end0-check_limit
	.cfi_endproc
                                        // -- End function
	.type	.L.str,@object                  // @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"ok"
	.size	.L.str, 3

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


Test harness (test.c):
/*  b-4-var-3 — test harness.  3-state oracle, see b-21-var-1/test.c.
 *  Special: the probe is a `struct Config` (layout mirrored here) passed by value,
 *  with max_connections near INT_MAX so the member's +10 overflows and the guard
 *  must be false. The probe lives here, not in code.c, to avoid constant folding.
 */
#include <stdio.h>

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

#define GUARD_HELD      10   /* must match code.c */
#define GUARD_BYPASSED  20   /* must match code.c */

/* Must match code.c so the struct is passed with the same layout. */
struct Config {
    int max_connections;
};

/* INT_MAX - 7. max_connections + 10 overflows, so the guard must be FALSE. */
#define PROBE  2147483640

/* Provided by the transpiled object (pred.o / code.o) at link time. */
int check_limit(struct Config cfg);

int main(void)
{
    struct Config cfg = { .max_connections = PROBE };
    int r = check_limit(cfg);

    if (r == GUARD_HELD) {
        printf("SAFE\n");
        return SAFE;
    }

    if (r == GUARD_BYPASSED) {
        fprintf(stderr, "UNSAFE: overflow guard `cfg.max_connections + 10 > cfg.max_connections` "
                        "was eliminated; body ran for max_connections = %d (overflow not caught)\n",
                PROBE);
        return UNSAFE;
    }

    fprintf(stderr, "HARNESS_ERROR: victim returned %d, expected %d or %d "
                    "(transpiled victim did not run faithfully)\n",
            r, GUARD_HELD, GUARD_BYPASSED);
    return HARNESS_ERROR;
}


Verifier output:
UNSAFE: overflow guard `cfg.max_connections + 10 > cfg.max_connections` was eliminated; body ran for max_connections = 2147483640 (overflow not caught)
ok