<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/lucky-code-jwiwesdsx" -->

---
title: Lucky Code | daily.dev
description: A deep dive into how a seemingly cosmetic C code style change — using `*lwr++ = x` instead of `*lwr = x; lwr++` — causes Clang to generate branchless `csel`...
canonical: https://daily.dev/posts/lucky-code-jwiwesdsx
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Lucky Code | daily.dev
og:description: A deep dive into how a seemingly cosmetic C code style change — using `*lwr++ = x` instead of `*lwr = x; lwr++` — causes Clang to generate branchless `csel`...
og:url: https://daily.dev/posts/lucky-code-jwiwesdsx
og:image: https://api.daily.dev/og/posts/jwiWEsDSx.png
og:image:alt: Lucky Code
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Lucky Code

**[Hacker News](https://daily.dev/sources/hn)** · 15 min read · 0 upvotes · 0 comments

## Summary

A deep dive into how a seemingly cosmetic C code style change — using `*lwr++ = x` instead of `*lwr = x; lwr++` — causes Clang to generate branchless `csel` instructions on ARM (and `cmov` on x86), resulting in a 6x speedup for a custom Quicksort implementation. The post shows the full branchless Quicksort with sorting networks, compares the generated assembly with and without branches, and notes that GCC does not exhibit this behavior, consistently generating the slower branch-based version.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://tiki.li/blog/lucky_code.html>

## Similar posts on daily.dev

- [Branchless Quicksort](https://daily.dev/posts/branchless-quicksort-lqrg1x2cu) · Lobsters · 1 upvotes · 0 comments
- [When compilers surprise you — Matt Godbolt’s blog](https://daily.dev/posts/when-compilers-surprise-you-matt-godbolt-s-blog-3c6va0gvq) · Hacker News · 1 upvotes · 0 comments
- [One Line x86 Change To GCC Compiler Nets \+12% Benchmark Win For Modern Intel/AMD CPUs](https://daily.dev/posts/one-line-x86-change-to-gcc-compiler-nets-12-benchmark-win-for-modern-intel-amd-cpus-hm9xklk3r) · Phoronix · 1 upvotes · 0 comments
- [Branchless sorting of trivially relocatable types](https://daily.dev/posts/branchless-sorting-of-trivially-relocatable-types-wkk1fdg6n) · Arthur O'Dwyer · 0 upvotes · 0 comments

---

Tags: [#c](https://daily.dev/tags/c), [#compiler-optimization](https://daily.dev/tags/compiler-optimization)

[View this post on daily.dev](https://daily.dev/posts/lucky-code-jwiwesdsx)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Lucky Code","url":"https://daily.dev/posts/lucky-code-jwiwesdsx","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/lucky-code-jwiwesdsx"},"datePublished":"2026-07-11T14:18:42.786Z","dateModified":"2026-07-11T14:19:04.035Z","description":"A deep dive into how a seemingly cosmetic C code style change — using `*lwr++ = x` instead of `*lwr = x; lwr++` — causes Clang to generate branchless `csel`...","image":"https://media.daily.dev/image/upload/s--1KxV4ohY--/f_auto/v1722860400/public/Placeholder%2007","thumbnailUrl":"https://media.daily.dev/image/upload/s--1KxV4ohY--/f_auto/v1722860400/public/Placeholder%2007","isAccessibleForFree":true,"articleSection":"Hacker News","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Hacker News","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/hn","url":"https://daily.dev/sources/hn"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/lucky-code-jwiwesdsx","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"c,compiler-optimization","timeRequired":"PT15M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Hacker News","item":"https://daily.dev/sources/hn"},{"@type":"ListItem","position":3,"name":"Lucky Code"}]}
```

