int test_hx_var(int i) {
  int n = __builtin_snprintf(0, 0, "%#hx", i);
  do {
    extern void failure_on_line_126(void);
    if (!(0 < n && n < 7))
      failure_on_line_126();
  } while (0);
  do {
    extern void keep_call_on_line_128(void);
    if (1 == n)
      keep_call_on_line_128();
  } while (0);
  do {
    extern void keep_call_on_line_129(void);
    if (2 == n)
      keep_call_on_line_129();
  } while (0);
  do {
    extern void keep_call_on_line_130(void);
    if (3 == n)
      keep_call_on_line_130();
  } while (0);
  do {
    extern void keep_call_on_line_131(void);
    if (4 == n)
      keep_call_on_line_131();
  } while (0);
  do {
    extern void keep_call_on_line_132(void);
    if (5 == n)
      keep_call_on_line_132();
  } while (0);
  do {
    extern void keep_call_on_line_133(void);
    if (6 == n)
      keep_call_on_line_133();
  } while (0);
  return n;
}


x86 assembly (clang, -O0):
<test_hx_var>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%esi
lea    0xe67(%rip),%rdx
mov    %rsi,%rdi
mov    $0x0,%al
call   1050 <snprintf@plt>
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%eax
jge    11bb <test_hx_var+0x3b>
cmpl   $0x7,-0x8(%rbp)
jl     11c0 <test_hx_var+0x40>
call   1090 <failure_on_line_126@plt>
jmp    11c5 <test_hx_var+0x45>
jmp    11ca <test_hx_var+0x4a>
mov    $0x1,%eax
cmp    -0x8(%rbp),%eax
jne    11dd <test_hx_var+0x5d>
call   1030 <keep_call_on_line_128@plt>
jmp    11e2 <test_hx_var+0x62>
jmp    11e7 <test_hx_var+0x67>
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
jne    11fa <test_hx_var+0x7a>
call   1070 <keep_call_on_line_129@plt>
jmp    11ff <test_hx_var+0x7f>
jmp    1204 <test_hx_var+0x84>
mov    $0x3,%eax
cmp    -0x8(%rbp),%eax
jne    1217 <test_hx_var+0x97>
call   10a0 <keep_call_on_line_130@plt>
jmp    121c <test_hx_var+0x9c>
jmp    1221 <test_hx_var+0xa1>
mov    $0x4,%eax
cmp    -0x8(%rbp),%eax
jne    1234 <test_hx_var+0xb4>
call   1060 <keep_call_on_line_131@plt>
jmp    1239 <test_hx_var+0xb9>
jmp    123e <test_hx_var+0xbe>
mov    $0x5,%eax
cmp    -0x8(%rbp),%eax
jne    1251 <test_hx_var+0xd1>
call   1080 <keep_call_on_line_132@plt>
jmp    1256 <test_hx_var+0xd6>
jmp    125b <test_hx_var+0xdb>
mov    $0x6,%eax
cmp    -0x8(%rbp),%eax
jne    126e <test_hx_var+0xee>
call   1040 <keep_call_on_line_133@plt>
jmp    1273 <test_hx_var+0xf3>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_hx_var>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ecx
lea    0xe8b(%rip),%rdx
xor    %edi,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    %eax,%r14d
lea    -0x1(%r14),%ebx
cmp    $0x6,%ebx
jb     11a9 <test_hx_var+0x29>
call   1090 <failure_on_line_126@plt>
cmp    $0x5,%ebx
ja     11e6 <test_hx_var+0x66>
lea    0xe4b(%rip),%rax
movslq (%rax,%rbx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
call   1030 <keep_call_on_line_128@plt>
jmp    11e6 <test_hx_var+0x66>
call   1070 <keep_call_on_line_129@plt>
jmp    11e6 <test_hx_var+0x66>
call   10a0 <keep_call_on_line_130@plt>
jmp    11e6 <test_hx_var+0x66>
call   1060 <keep_call_on_line_131@plt>
jmp    11e6 <test_hx_var+0x66>
call   1080 <keep_call_on_line_132@plt>
jmp    11e6 <test_hx_var+0x66>
call   1040 <keep_call_on_line_133@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%#hx\00"
define i32 @test_hx_var(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* null, i64 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %3
br label %6
6: ; preds = %1
%7 = load i32, i32* %3
%8 = icmp slt i32 0, %7
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 7
br i1 %11, label %13, label %12
12: ; preds = %9, %6
br label %13
13: ; preds = %12, %9
br label %14
14: ; preds = %13
br label %15
15: ; preds = %14
%16 = load i32, i32* %3
%17 = icmp eq i32 1, %16
br i1 %17, label %18, label %19
18: ; preds = %15
br label %19
19: ; preds = %18, %15
br label %20
20: ; preds = %19
br label %21
21: ; preds = %20
%22 = load i32, i32* %3
%23 = icmp eq i32 2, %22
br i1 %23, label %24, label %25
24: ; preds = %21
br label %25
25: ; preds = %24, %21
br label %26
26: ; preds = %25
br label %27
27: ; preds = %26
%28 = load i32, i32* %3
%29 = icmp eq i32 3, %28
br i1 %29, label %30, label %31
30: ; preds = %27
br label %31
31: ; preds = %30, %27
br label %32
32: ; preds = %31
br label %33
33: ; preds = %32
%34 = load i32, i32* %3
%35 = icmp eq i32 4, %34
br i1 %35, label %36, label %37
36: ; preds = %33
br label %37
37: ; preds = %36, %33
br label %38
38: ; preds = %37
br label %39
39: ; preds = %38
%40 = load i32, i32* %3
%41 = icmp eq i32 5, %40
br i1 %41, label %42, label %43
42: ; preds = %39
br label %43
43: ; preds = %42, %39
br label %44
44: ; preds = %43
br label %45
45: ; preds = %44
%46 = load i32, i32* %3
%47 = icmp eq i32 6, %46
br i1 %47, label %48, label %49
48: ; preds = %45
br label %49
49: ; preds = %48, %45
br label %50
50: ; preds = %49
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@.str = [5 x i8] c"%#hx\00"
define i32 @test_hx_var(i32 %0) {
%2 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* null, i64 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %0)
%3 = add i32 %2, -1
%4 = icmp ult i32 %3, 6
br i1 %4, label %6, label %5
5: ; preds = %1
tail call void @failure_on_line_126()
br label %6
6: ; preds = %5, %1
switch i32 %2, label %13 [
i32 1, label %7
i32 2, label %8
i32 3, label %9
i32 4, label %10
i32 5, label %11
i32 6, label %12
]
7: ; preds = %6
tail call void @keep_call_on_line_128()
br label %13
8: ; preds = %6
tail call void @keep_call_on_line_129()
br label %13
9: ; preds = %6
tail call void @keep_call_on_line_130()
br label %13
10: ; preds = %6
tail call void @keep_call_on_line_131()
br label %13
11: ; preds = %6
tail call void @keep_call_on_line_132()
br label %13
12: ; preds = %6
tail call void @keep_call_on_line_133()
br label %13
13: ; preds = %11, %10, %9, %8, %7, %6, %12
ret i32 %2
}