Fixture 202

bit scan and count

C · 12 functions · 4 lanes · 48 of 48 function-lanes behave identically

All 4 lanes recompile and return the same results as the original.

Bit SCANS and bit COUNTS are two instruction families, not one spelling of another, and until 2026-08-19 the corpus reached them almost by accident.

x86 bsf/bsr report the INDEX of a set bit and leave the destination untouched when the source is zero; tzcnt/lzcnt report a COUNT and answer the operand's width there. GCC compiles __builtin_ctz to the TZCNT encoding at every optimisation level -- it is rep bsf, which a pre-BMI part executes as bsf -- so an ordinary build of the most ordinary bit idiom in C contains an instruction whose zero case differs from the one this decompiler had a lowering for. The only lane that reached it was one arm of a switch in 144_inline_asm, at 32 bits; nothing reached it at 64 bits, nothing reached the set/clear/toggle family at all, and nothing anywhere reached not on a byte view.

Every function here is total: the zero cases are spelled out and every shift count is masked, so the recompiled C has no undefined behaviour to disagree with the original about.

The controls are the point. A count lowered as if it were the opposite scan, or a btr whose mask never got complemented, produces C that compiles, runs, and returns a plausible number -- so each operation is paired with the neighbour it would be confused with, and the two disagree on almost every input.

tests/decompiler_fixtures/src/202_bit_scan_and_count.c source
#include <stdint.h>

/* Bit SCANS and bit COUNTS are two instruction families, not one spelling of
 * another, and until 2026-08-19 the corpus reached them almost by accident.
 *
 * x86 `bsf`/`bsr` report the INDEX of a set bit and leave the destination
 * untouched when the source is zero; `tzcnt`/`lzcnt` report a COUNT and answer
 * the operand's width there. GCC compiles `__builtin_ctz` to the `TZCNT`
 * encoding at every optimisation level -- it is `rep bsf`, which a pre-BMI part
 * executes as `bsf` -- so an ordinary build of the most ordinary bit idiom in C
 * contains an instruction whose zero case differs from the one this decompiler
 * had a lowering for. The only lane that reached it was one arm of a switch in
 * `144_inline_asm`, at 32 bits; nothing reached it at 64 bits, nothing reached
 * the set/clear/toggle family at all, and nothing anywhere reached `not` on a
 * byte view.
 *
 * Every function here is total: the zero cases are spelled out and every shift
 * count is masked, so the recompiled C has no undefined behaviour to disagree
 * with the original about.
 *
 * The controls are the point. A count lowered as if it were the opposite scan,
 * or a `btr` whose mask never got complemented, produces C that compiles, runs,
 * and returns a plausible number -- so each operation is paired with the
 * neighbour it would be confused with, and the two disagree on almost every
 * input. */

/* --- counts: trailing and leading, 32 and 64 bits --- */

__attribute__((noinline)) int32_t bsc202_ctz32(uint32_t value) {
    return (value == 0u) ? 32 : (int32_t)__builtin_ctz(value);
}

/* The control for `bsc202_ctz32`. Leading and trailing counts agree only on 0
 * and on the values with exactly one bit set at index 0 or 31, so a lowering
 * that confused them is visible on essentially every vector. */
__attribute__((noinline)) int32_t bsc202_clz32(uint32_t value) {
    return (value == 0u) ? 32 : (int32_t)__builtin_clz(value);
}

__attribute__((noinline)) int32_t bsc202_ctz64(uint64_t value) {
    return (value == 0u) ? 64 : (int32_t)__builtin_ctzll(value);
}

__attribute__((noinline)) int32_t bsc202_clz64(uint64_t value) {
    return (value == 0u) ? 64 : (int32_t)__builtin_clzll(value);
}

/* The count is a count, not an index: `ctz` and `31 - clz` are the same number
 * only for a single-bit operand. Returning both from one function makes a
 * lowering that reached for the bit-scan identity disagree here while both of
 * the two above still looked right. */
__attribute__((noinline)) int32_t bsc202_count_and_index(uint32_t value) {
    int32_t trailing;
    int32_t highest;

    if (value == 0u) {
        return -1;
    }
    trailing = (int32_t)__builtin_ctz(value);
    highest = 31 - (int32_t)__builtin_clz(value);
    return (highest * 64) + trailing;
}

/* --- set / clear / toggle: the bit-modify family --- */

__attribute__((noinline)) uint32_t bsc202_set_bit(uint32_t word, int32_t index) {
    return word | (1u << (index & 31));
}

/* The control for `bsc202_set_bit`. If the clearing mask is not complemented,
 * this returns exactly what setting returns. */
__attribute__((noinline)) uint32_t bsc202_clear_bit(uint32_t word,
                                                    int32_t index) {
    return word & ~(1u << (index & 31));
}

__attribute__((noinline)) uint32_t bsc202_toggle_bit(uint32_t word,
                                                     int32_t index) {
    return word ^ (1u << (index & 31));
}

/* Both polarities of the same write, chosen at run time. This is the shape
 * clang -O2 compiles to `bts` into a copy, `btr` into the original, and a
 * `cmov` to pick one: while both writes were invisible the two arms of that
 * select were the same expression and the bit was written at NEITHER polarity,
 * which no single-polarity test above can detect. */
__attribute__((noinline)) uint32_t bsc202_assign_bit(uint32_t word,
                                                     int32_t index,
                                                     int32_t bit) {
    uint32_t mask = 1u << (index & 31);

    if (bit != 0) {
        return word | mask;
    }
    return word & ~mask;
}

/* The same shape over a whole word, so the select runs many times with a
 * carried result rather than once at a return. */
__attribute__((noinline)) uint32_t bsc202_scatter_bits(uint32_t word,
                                                       uint32_t bits) {
    int32_t i;

    for (i = 0; i < 16; i++) {
        uint32_t mask = 1u << (i & 31);

        if (((bits >> (i & 31)) & 1u) != 0u) {
            word |= mask;
        } else {
            word &= ~mask;
        }
    }
    return word;
}

/* `7 - (at & 7)`, which compilers spell `not` on a BYTE view followed by
 * `and $7`. A byte register is not canonicalised to its 64-bit parent, so a
 * complement written to the byte name alone is a definition nothing reads and
 * the reflection silently disappears — leaving `at & 7`, which differs from the
 * correct answer for every input. */
__attribute__((noinline)) int32_t bsc202_reflect_in_byte(int32_t at) {
    return 7 - (at & 7);
}

/* The reflection where it actually occurs: addressing a bit inside a byte
 * buffer most-significant-bit first. */
__attribute__((noinline)) uint32_t bsc202_msb_first_bit(uint32_t word,
                                                        int32_t at) {
    int32_t shift = 7 - (at & 7);

    return (word >> shift) & 1u;
}

Recovered C

Generated by glaurung decompile --style decbench at b47f6b43. baseline.json records the result after recompiling the C and calling it beside the original with seeded inputs.

clang -O0

12/12
bsc202_assign_bit pass 11 lines
// glaurung: bsc202_assign_bit @ 0x1290
uint32_t bsc202_assign_bit(uint32_t arg0, int32_t arg1, int32_t arg2) {
    unsigned int mask;
    // x86-64 prologue: save rbp
    mask = (1 << ((unsigned long)((unsigned int)(((unsigned long)((unsigned int)(arg1)) & 31))) & 31));
    if (((unsigned long)((unsigned int)(arg2)) == 0)) {
        return (unsigned int)(((unsigned long)(arg0) & (unsigned long)((unsigned int)(((unsigned long)(mask) ^ -1)))));
    } else {
        return (unsigned int)(((unsigned long)(arg0) | mask));
    }
}
bsc202_clear_bit pass 6 lines
// glaurung: bsc202_clear_bit @ 0x1240
uint32_t bsc202_clear_bit(uint32_t arg0, int32_t arg1) {
    // x86-64 prologue: save rbp
    // x86-64 epilogue: restore rbp
    return (unsigned int)(((unsigned long)(arg0) & (unsigned long)((unsigned int)(((unsigned long)((unsigned int)((1 << ((unsigned long)((unsigned int)(((unsigned long)((unsigned int)(arg1)) & 31))) & 31)))) ^ -1)))));
}
bsc202_clz32 pass 9 lines
// glaurung: bsc202_clz32 @ 0x1130
int32_t bsc202_clz32(uint32_t arg0) {
    // x86-64 prologue: save rbp
    if ((arg0 != 0)) {
        return (unsigned int)(((31 - (((unsigned int)((unsigned long)((unsigned int)((unsigned long)(arg0)))) == 0) ? 32 : __builtin_clz((unsigned int)((unsigned long)((unsigned int)((unsigned long)(arg0))))))) ^ 31));
    } else {
        return 32;
    }
}
bsc202_clz64 pass 9 lines
// glaurung: bsc202_clz64 @ 0x1190
int32_t bsc202_clz64(uint64_t arg0) {
    // x86-64 prologue: save rbp
    if ((arg0 != 0)) {
        return (unsigned int)(((63 - (((unsigned long long)(arg0) == 0) ? 64 : __builtin_clzll((unsigned long long)(arg0)))) ^ 63));
    } else {
        return 64;
    }
}
bsc202_count_and_index pass 13 lines
// glaurung: bsc202_count_and_index @ 0x11d0
int32_t bsc202_count_and_index(uint32_t arg0) {
    int trailing;
    int highest;
    // x86-64 prologue: save rbp
    if ((arg0 != 0)) {
        trailing = (31 - (((unsigned int)((arg0 ^ (arg0 - 1))) == 0) ? 32 : __builtin_clz((unsigned int)((arg0 ^ (arg0 - 1))))));
        highest = (31 - (unsigned int)(((31 - (((unsigned int)(arg0) == 0) ? 32 : __builtin_clz((unsigned int)(arg0)))) ^ 31)));
        return (unsigned int)(((unsigned long)((unsigned int)(((unsigned long)((unsigned int)(highest)) << 6))) + trailing));
    } else {
        return (unsigned int)(-1);
    }
}
bsc202_ctz32 pass 9 lines
// glaurung: bsc202_ctz32 @ 0x1100
int32_t bsc202_ctz32(uint32_t arg0) {
    // x86-64 prologue: save rbp
    if ((arg0 != 0)) {
        return (unsigned int)((31 - (((unsigned int)(((unsigned long)((unsigned int)((unsigned long)(arg0))) ^ ((unsigned long)((unsigned int)((unsigned long)(arg0))) - 1))) == 0) ? 32 : __builtin_clz((unsigned int)(((unsigned long)((unsigned int)((unsigned long)(arg0))) ^ ((unsigned long)((unsigned int)((unsigned long)(arg0))) - 1)))))));
    } else {
        return 32;
    }
}
bsc202_ctz64 pass 9 lines
// glaurung: bsc202_ctz64 @ 0x1160
int32_t bsc202_ctz64(uint64_t arg0) {
    // x86-64 prologue: save rbp
    if ((arg0 != 0)) {
        return (unsigned int)((63 - (((unsigned long long)((arg0 ^ (arg0 - 1))) == 0) ? 64 : __builtin_clzll((unsigned long long)((arg0 ^ (arg0 - 1)))))));
    } else {
        return 64;
    }
}
bsc202_msb_first_bit pass 8 lines
// glaurung: bsc202_msb_first_bit @ 0x1380
uint32_t bsc202_msb_first_bit(uint32_t arg0, int32_t arg1) {
    int shift;
    // x86-64 prologue: save rbp
    shift = (7 - (unsigned int)(((unsigned long)((unsigned int)(arg1)) & 7)));
    // x86-64 epilogue: restore rbp
    return (unsigned int)(((unsigned long)((unsigned int)(((unsigned long)(arg0) >> ((unsigned long)((unsigned int)(shift)) & 31)))) & 1));
}
bsc202_reflect_in_byte pass 6 lines
// glaurung: bsc202_reflect_in_byte @ 0x1360
int32_t bsc202_reflect_in_byte(int32_t arg0) {
    // x86-64 prologue: save rbp
    // x86-64 epilogue: restore rbp
    return (unsigned int)((7 - (unsigned long)((unsigned int)(((unsigned long)((unsigned int)(arg0)) & 7)))));
}
bsc202_scatter_bits pass 12 lines
// glaurung: bsc202_scatter_bits @ 0x12e0
uint32_t bsc202_scatter_bits(uint32_t arg0, uint32_t arg1) {
    int i;
    unsigned int mask;
    // x86-64 prologue: save rbp
    for (i = 0; ((long)(i) < 16); i++) {
        mask = (1 << ((unsigned long)((unsigned int)(((unsigned long)((unsigned int)(i)) & 31))) & 31));
        arg0 = (((unsigned long)((unsigned int)(((unsigned long)((unsigned int)(((unsigned long)(arg1) >> ((unsigned long)((unsigned int)(((unsigned long)((unsigned int)(i)) & 31))) & 31)))) & 1))) == 0) ? ((unsigned long)((unsigned int)((mask ^ -1))) & (unsigned long)(arg0)) : ((unsigned long)(mask) | (unsigned long)(arg0)));
    }
    // x86-64 epilogue: restore rbp
    return arg0;
}
bsc202_set_bit pass 6 lines
// glaurung: bsc202_set_bit @ 0x1220
uint32_t bsc202_set_bit(uint32_t arg0, int32_t arg1) {
    // x86-64 prologue: save rbp
    // x86-64 epilogue: restore rbp
    return (unsigned int)(((unsigned long)(arg0) | (unsigned long)((unsigned int)((1 << ((unsigned long)((unsigned int)(((unsigned long)((unsigned int)(arg1)) & 31))) & 31))))));
}
bsc202_toggle_bit pass 6 lines
// glaurung: bsc202_toggle_bit @ 0x1270
uint32_t bsc202_toggle_bit(uint32_t arg0, int32_t arg1) {
    // x86-64 prologue: save rbp
    // x86-64 epilogue: restore rbp
    return (unsigned int)(((unsigned long)(arg0) ^ (unsigned long)((unsigned int)((1 << ((unsigned long)((unsigned int)(((unsigned long)((unsigned int)(arg1)) & 31))) & 31))))));
}

clang -O2

12/12
bsc202_assign_bit pass 4 lines
// glaurung: bsc202_assign_bit @ 0x11b0
uint32_t bsc202_assign_bit(uint32_t arg0, int32_t arg1, int32_t arg2) {
    return (((unsigned long)((unsigned int)(arg2)) == 0) ? (unsigned long)((unsigned int)((arg0 & (~((unsigned int)(1) << (arg1 & 31)))))) : (unsigned long)((unsigned int)(((unsigned long)(arg0) | ((unsigned int)(1) << (arg1 & 31))))));
}
bsc202_clear_bit pass 4 lines
// glaurung: bsc202_clear_bit @ 0x1190
uint32_t bsc202_clear_bit(uint32_t arg0, int32_t arg1) {
    return (unsigned int)(((unsigned long)(arg0) & (~((unsigned int)(1) << (arg1 & 31)))));
}
bsc202_clz32 pass 7 lines
// glaurung: bsc202_clz32 @ 0x1110
int32_t bsc202_clz32(uint32_t arg0) {
    if ((arg0 == 0)) {
        return 32;
    }
    return (unsigned int)(((31 - (((unsigned int)((unsigned long)(arg0)) == 0) ? 32 : __builtin_clz((unsigned int)((unsigned long)(arg0))))) ^ 31));
}
bsc202_clz64 pass 7 lines
// glaurung: bsc202_clz64 @ 0x1140
int32_t bsc202_clz64(uint64_t arg0) {
    if ((arg0 == 0)) {
        return 64;
    }
    return ((63 - (((unsigned long long)(arg0) == 0) ? 64 : __builtin_clzll((unsigned long long)(arg0)))) ^ 63);
}
bsc202_count_and_index pass 8 lines
// glaurung: bsc202_count_and_index @ 0x1160
int32_t bsc202_count_and_index(uint32_t arg0) {
    int trailing;
    if ((arg0 == 0)) {
        return 0xffffffff;
    }
    return (unsigned int)(((unsigned long)((unsigned int)(((unsigned long)((unsigned int)(((unsigned long)((unsigned int)(((31 - (((unsigned int)((unsigned long)(arg0)) == 0) ? 32 : __builtin_clz((unsigned int)((unsigned long)(arg0))))) ^ 31))) << 6))) | (31 - (((unsigned int)(((unsigned long)(arg0) ^ ((unsigned long)(arg0) - 1))) == 0) ? 32 : __builtin_clz((unsigned int)(((unsigned long)(arg0) ^ ((unsigned long)(arg0) - 1))))))))) ^ 1984));
}
bsc202_ctz32 pass 7 lines
// glaurung: bsc202_ctz32 @ 0x1100
int32_t bsc202_ctz32(uint32_t arg0) {
    if ((arg0 == 0)) {
        return 32;
    }
    return (31 - (((unsigned int)(((unsigned long)(arg0) ^ ((unsigned long)(arg0) - 1))) == 0) ? 32 : __builtin_clz((unsigned int)(((unsigned long)(arg0) ^ ((unsigned long)(arg0) - 1))))));
}
bsc202_ctz64 pass 7 lines
// glaurung: bsc202_ctz64 @ 0x1130
int32_t bsc202_ctz64(uint64_t arg0) {
    if ((arg0 == 0)) {
        return 64;
    }
    return (63 - (((unsigned long long)((arg0 ^ (arg0 - 1))) == 0) ? 64 : __builtin_clzll((unsigned long long)((arg0 ^ (arg0 - 1))))));
}
bsc202_msb_first_bit pass 4 lines
// glaurung: bsc202_msb_first_bit @ 0x1260
uint32_t bsc202_msb_first_bit(uint32_t arg0, int32_t arg1) {
    return (unsigned int)(((unsigned long)((unsigned int)(((unsigned long)(arg0) >> ((~((unsigned long)((unsigned int)(arg1)) & 255)) & 7)))) & 1));
}
bsc202_reflect_in_byte pass 4 lines
// glaurung: bsc202_reflect_in_byte @ 0x1250
int32_t bsc202_reflect_in_byte(int32_t arg0) {
    return (unsigned int)(((~(unsigned long)((unsigned int)(arg0))) & 7));
}
bsc202_scatter_bits pass 6 lines
// glaurung: bsc202_scatter_bits @ 0x11c0
uint32_t bsc202_scatter_bits(uint32_t arg0, uint32_t arg1) {
    int i;
    unsigned int mask;
    return (unsigned int)(((unsigned long)((unsigned int)(((unsigned long)((unsigned int)(((unsigned long)((unsigned int)(((unsigned long)(arg1) & 0x4000))) | (unsigned long)((unsigned int)(((unsigned long)(arg1) & 0x2000)))))) | (unsigned long)((unsigned int)((arg1 & 0x8000)))))) | (unsigned long)((unsigned int)(((unsigned long)((unsigned int)(((unsigned long)((unsigned int)(((unsigned long)(arg1) & 4096))) | (unsigned long)((unsigned int)(((unsigned long)((unsigned int)(((unsigned long)(arg1) & 2048))) | (unsigned long)((unsigned int)(((unsigned long)((unsigned int)(((unsigned long)(arg1) & 1024))) | (unsigned long)((unsigned int)(((unsigned long)((unsigned int)(((unsigned long)(arg1) & 512))) | (unsigned long)((unsigned int)(((unsigned long)((unsigned int)(((unsigned long)(arg1) & 256))) | (unsigned long)((unsigned int)(((unsigned long)((unsigned int)(((unsigned long)(arg1) & 128))) | (unsigned long)((unsigned int)(((unsigned long)(arg1) & 64))))))))))))))))))))) | (unsigned long)((unsigned int)(((unsigned long)((unsigned int)(((unsigned long)(arg1) & 32))) | (unsigned long)((unsigned int)(((unsigned long)((unsigned int)(((unsigned long)(arg1) & 16))) | (unsigned long)((unsigned int)(((unsigned long)((unsigned int)(((unsigned long)(arg1) & 8))) | (unsigned long)((unsigned int)(((unsigned long)((unsigned int)(((unsigned long)(arg1) & 4))) | (unsigned long)((unsigned int)(((unsigned long)((unsigned int)(((unsigned long)(arg1) & 2))) | (unsigned long)((unsigned int)(((unsigned long)((unsigned int)(((unsigned long)(arg1) & 1))) | (unsigned long)((unsigned int)((arg0 & -0x10000LL))))))))))))))))))))))))));
}
bsc202_set_bit pass 4 lines
// glaurung: bsc202_set_bit @ 0x1180
uint32_t bsc202_set_bit(uint32_t arg0, int32_t arg1) {
    return (unsigned int)(((unsigned long)(arg0) | ((unsigned int)(1) << (arg1 & 31))));
}
bsc202_toggle_bit pass 4 lines
// glaurung: bsc202_toggle_bit @ 0x11a0
uint32_t bsc202_toggle_bit(uint32_t arg0, int32_t arg1) {
    return (unsigned int)(((unsigned long)(arg0) ^ ((unsigned int)(1) << (arg1 & 31))));
}

gcc -O0

12/12
bsc202_assign_bit pass 11 lines
// glaurung: bsc202_assign_bit @ 0x1234
uint32_t bsc202_assign_bit(uint32_t arg0, int32_t arg1, int32_t arg2) {
    unsigned int mask;
    // x86-64 prologue: save rbp
    mask = (1 << ((unsigned long)((unsigned int)(((unsigned long)((unsigned int)(arg1)) & 31))) & 31));
    if (((unsigned long)((unsigned int)(arg2)) == 0)) {
        return (unsigned int)(((~(unsigned long)(mask)) & arg0));
    } else {
        return (unsigned int)(((unsigned long)(arg0) | mask));
    }
}
bsc202_clear_bit pass 6 lines
// glaurung: bsc202_clear_bit @ 0x11ea
uint32_t bsc202_clear_bit(uint32_t arg0, int32_t arg1) {
    // x86-64 prologue: save rbp
    // x86-64 epilogue: restore rbp
    return (unsigned int)(((~(unsigned long)((unsigned int)((1 << ((unsigned long)((unsigned int)(((unsigned long)((unsigned int)(arg1)) & 31))) & 31))))) & arg0));
}
bsc202_clz32 pass 9 lines
// glaurung: bsc202_clz32 @ 0x111a
int32_t bsc202_clz32(uint32_t arg0) {
    // x86-64 prologue: save rbp
    if ((arg0 == 0)) {
        return 32;
    } else {
        return (unsigned int)(((31 - (((unsigned int)((unsigned long)(arg0)) == 0) ? 32 : __builtin_clz((unsigned int)((unsigned long)(arg0))))) ^ 31));
    }
}
bsc202_clz64 pass 9 lines
// glaurung: bsc202_clz64 @ 0x115f
int32_t bsc202_clz64(uint64_t arg0) {
    // x86-64 prologue: save rbp
    if ((arg0 == 0)) {
        return 64;
    } else {
        return ((63 - (((unsigned long long)(arg0) == 0) ? 64 : __builtin_clzll((unsigned long long)(arg0)))) ^ 63);
    }
}
bsc202_count_and_index pass 13 lines
// glaurung: bsc202_count_and_index @ 0x1184
int32_t bsc202_count_and_index(uint32_t arg0) {
    int trailing;
    int highest;
    // x86-64 prologue: save rbp
    if ((arg0 != 0)) {
        trailing = (((unsigned int)(arg0) == 0) ? 32 : __builtin_ctz((unsigned int)(arg0)));
        highest = (31 - (unsigned int)(((31 - (((unsigned int)(arg0) == 0) ? 32 : __builtin_clz((unsigned int)(arg0)))) ^ 31)));
        return (unsigned int)(((unsigned long)((unsigned int)(trailing)) + (unsigned long)((unsigned int)(((unsigned long)((unsigned int)(highest)) << 6)))));
    } else {
        return 0xffffffff;
    }
}
bsc202_ctz32 pass 9 lines
// glaurung: bsc202_ctz32 @ 0x10f9
int32_t bsc202_ctz32(uint32_t arg0) {
    // x86-64 prologue: save rbp
    if ((arg0 == 0)) {
        return 32;
    } else {
        return (((unsigned int)((unsigned long)(arg0)) == 0) ? 32 : __builtin_ctz((unsigned int)((unsigned long)(arg0))));
    }
}
bsc202_ctz64 pass 9 lines
// glaurung: bsc202_ctz64 @ 0x113b
int32_t bsc202_ctz64(uint64_t arg0) {
    // x86-64 prologue: save rbp
    if ((arg0 == 0)) {
        return 64;
    } else {
        return (((unsigned long long)(arg0) == 0) ? 64 : __builtin_ctzll((unsigned long long)(arg0)));
    }
}
bsc202_msb_first_bit pass 8 lines
// glaurung: bsc202_msb_first_bit @ 0x12e6
uint32_t bsc202_msb_first_bit(uint32_t arg0, int32_t arg1) {
    int shift;
    // x86-64 prologue: save rbp
    shift = ((~(unsigned long)((unsigned int)(arg1))) & 7);
    // x86-64 epilogue: restore rbp
    return (unsigned int)(((unsigned long)((unsigned int)(((unsigned long)(arg0) >> ((unsigned long)((unsigned int)(shift)) & 31)))) & 1));
}
bsc202_reflect_in_byte pass 6 lines
// glaurung: bsc202_reflect_in_byte @ 0x12d1
int32_t bsc202_reflect_in_byte(int32_t arg0) {
    // x86-64 prologue: save rbp
    // x86-64 epilogue: restore rbp
    return (unsigned int)(((~(unsigned long)((unsigned int)(arg0))) & 7));
}
bsc202_scatter_bits pass 12 lines
// glaurung: bsc202_scatter_bits @ 0x1271
uint32_t bsc202_scatter_bits(uint32_t arg0, uint32_t arg1) {
    int i;
    unsigned int mask;
    // x86-64 prologue: save rbp
    for (i = 0; ((((unsigned long)((unsigned int)(i)) == 15) | ((long)(i) < 15)) != 0); i++) {
        mask = (1 << ((unsigned long)((unsigned int)(((unsigned long)((unsigned int)(i)) & 31))) & 31));
        arg0 = (((unsigned long)((unsigned int)(((unsigned long)((unsigned int)(((unsigned long)(arg1) >> ((unsigned long)((unsigned int)(((unsigned long)((unsigned int)(i)) & 31))) & 31)))) & 1))) == 0) ? ((unsigned long)(arg0) & (~(unsigned long)(mask))) : ((unsigned long)(arg0) | (unsigned long)(mask)));
    }
    // x86-64 epilogue: restore rbp
    return arg0;
}
bsc202_set_bit pass 6 lines
// glaurung: bsc202_set_bit @ 0x11c6
uint32_t bsc202_set_bit(uint32_t arg0, int32_t arg1) {
    // x86-64 prologue: save rbp
    // x86-64 epilogue: restore rbp
    return (unsigned int)(((unsigned long)((unsigned int)((1 << ((unsigned long)((unsigned int)(((unsigned long)((unsigned int)(arg1)) & 31))) & 31)))) | arg0));
}
bsc202_toggle_bit pass 6 lines
// glaurung: bsc202_toggle_bit @ 0x1210
uint32_t bsc202_toggle_bit(uint32_t arg0, int32_t arg1) {
    // x86-64 prologue: save rbp
    // x86-64 epilogue: restore rbp
    return (unsigned int)(((unsigned long)((unsigned int)((1 << ((unsigned long)((unsigned int)(((unsigned long)((unsigned int)(arg1)) & 31))) & 31)))) ^ arg0));
}

gcc -O2

12/12
bsc202_assign_bit pass 7 lines
// glaurung: bsc202_assign_bit @ 0x11e0
uint32_t bsc202_assign_bit(uint32_t arg0, int32_t arg1, int32_t arg2) {
    unsigned int mask;
    long var4;
    var4 = (unsigned long)((unsigned int)((1 << ((unsigned long)((unsigned int)(arg1)) & 31))));
    return (((unsigned long)((unsigned int)(arg2)) != 0) ? (unsigned long)((unsigned int)(((unsigned long)((unsigned int)(var4)) | arg0))) : (unsigned long)((unsigned int)(((~var4) & arg0))));
}
bsc202_clear_bit pass 4 lines
// glaurung: bsc202_clear_bit @ 0x11c0
uint32_t bsc202_clear_bit(uint32_t arg0, int32_t arg1) {
    return (unsigned int)(((unsigned long)(arg0) & (~((unsigned int)(1) << (arg1 & 31)))));
}
bsc202_clz32 pass 9 lines
// glaurung: bsc202_clz32 @ 0x1120
int32_t bsc202_clz32(uint32_t arg0) {
    long ret;
    ret = 32;
    if ((arg0 != 0)) {
        ret = (unsigned long)((unsigned int)(((31 - (((unsigned int)(arg0) == 0) ? 32 : __builtin_clz((unsigned int)(arg0)))) ^ 31)));
    }
    return ret;
}
bsc202_clz64 pass 9 lines
// glaurung: bsc202_clz64 @ 0x1160
int32_t bsc202_clz64(uint64_t arg0) {
    long ret;
    ret = 64;
    if ((arg0 != 0)) {
        ret = (unsigned long)((unsigned int)(((63 - (((unsigned long long)(arg0) == 0) ? 64 : __builtin_clzll((unsigned long long)(arg0)))) ^ 63)));
    }
    return ret;
}
bsc202_count_and_index pass 9 lines
// glaurung: bsc202_count_and_index @ 0x1180
int32_t bsc202_count_and_index(uint32_t arg0) {
    int highest;
    int trailing;
    if ((arg0 == 0)) {
        return 0xffffffff;
    }
    return (unsigned int)(((unsigned long)((unsigned int)(((unsigned long)((unsigned int)((31 - (unsigned long)((unsigned int)(((31 - (((unsigned int)((unsigned long)(arg0)) == 0) ? 32 : __builtin_clz((unsigned int)((unsigned long)(arg0))))) ^ 31)))))) << 6))) + (((unsigned int)((unsigned long)(arg0)) == 0) ? 32 : __builtin_ctz((unsigned int)((unsigned long)(arg0))))));
}
bsc202_ctz32 pass 4 lines
// glaurung: bsc202_ctz32 @ 0x1100
int32_t bsc202_ctz32(uint32_t arg0) {
    return (((unsigned long)(arg0) == 0) ? 32 : (((unsigned int)((unsigned long)(arg0)) == 0) ? 32 : __builtin_ctz((unsigned int)((unsigned long)(arg0)))));
}
bsc202_ctz64 pass 4 lines
// glaurung: bsc202_ctz64 @ 0x1140
int32_t bsc202_ctz64(uint64_t arg0) {
    return ((arg0 != 0) ? (((unsigned long long)(arg0) == 0) ? 64 : __builtin_ctzll((unsigned long long)(arg0))) : 64);
}
bsc202_msb_first_bit pass 5 lines
// glaurung: bsc202_msb_first_bit @ 0x1250
uint32_t bsc202_msb_first_bit(uint32_t arg0, int32_t arg1) {
    int shift;
    return (unsigned int)(((unsigned long)((unsigned int)(((unsigned long)(arg0) >> ((unsigned long)((unsigned int)(((unsigned long)((unsigned int)((~arg1))) & 7))) & 31)))) & 1));
}
bsc202_reflect_in_byte pass 4 lines
// glaurung: bsc202_reflect_in_byte @ 0x1240
int32_t bsc202_reflect_in_byte(int32_t arg0) {
    return (unsigned int)(((~(unsigned long)((unsigned int)(arg0))) & 7));
}
bsc202_scatter_bits pass 20 lines
// glaurung: bsc202_scatter_bits @ 0x1200
uint32_t bsc202_scatter_bits(uint32_t arg0, uint32_t arg1) {
    int i;
    unsigned int mask;
    long ret;
    int var21;
    int var3;
    long var4;
    var3 = 1;
    var4 = (unsigned long)(arg0);
    i = 0;
    do {
        mask = (unsigned long)((unsigned int)(((unsigned long)((unsigned int)(var3)) << (i & 31))));
        ret = (((unsigned long)((unsigned int)(((unsigned long)((unsigned int)(((unsigned long)(arg1) >> (i & 31)))) & 1))) != 0) ? (unsigned long)((unsigned int)(((unsigned long)((unsigned int)(var4)) | mask))) : (unsigned long)((unsigned int)((var4 & (~mask)))));
        var21 = (i + 1);
        i = (unsigned long)((unsigned int)(var21));
        var4 = ret;
    } while (((unsigned long)((unsigned int)(var21)) != 16));
    return ret;
}
bsc202_set_bit pass 4 lines
// glaurung: bsc202_set_bit @ 0x11b0
uint32_t bsc202_set_bit(uint32_t arg0, int32_t arg1) {
    return (unsigned int)(((unsigned long)(arg0) | ((unsigned int)(1) << (arg1 & 31))));
}
bsc202_toggle_bit pass 4 lines
// glaurung: bsc202_toggle_bit @ 0x11d0
uint32_t bsc202_toggle_bit(uint32_t arg0, int32_t arg1) {
    return (unsigned int)(((unsigned long)(arg0) ^ ((unsigned int)(1) << (arg1 & 31))));
}

← 213 fixtures