int test_hhx_var(int i) {
  int n = __builtin_snprintf(0, 0, "%#hhx", i);
  do {
    extern void failure_on_line_102(void);
    if (!(0 < n && n < 5))
      failure_on_line_102();
  } while (0);
  do {
    extern void keep_call_on_line_104(void);
    if (1 == n)
      keep_call_on_line_104();
  } while (0);
  do {
    extern void keep_call_on_line_105(void);
    if (2 == n)
      keep_call_on_line_105();
  } while (0);
  do {
    extern void keep_call_on_line_106(void);
    if (3 == n)
      keep_call_on_line_106();
  } while (0);
  do {
    extern void keep_call_on_line_107(void);
    if (4 == n)
      keep_call_on_line_107();
  } while (0);
  return n;
}


x86 assembly (clang, -O0):
<test_hhx_var>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%esi
lea    0xe87(%rip),%rdx
mov    %rsi,%rdi
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%eax
jge    119b <test_hhx_var+0x3b>
cmpl   $0x5,-0x8(%rbp)
jl     11a0 <test_hhx_var+0x40>
call   1080 <failure_on_line_102@plt>
jmp    11a5 <test_hhx_var+0x45>
jmp    11aa <test_hhx_var+0x4a>
mov    $0x1,%eax
cmp    -0x8(%rbp),%eax
jne    11bd <test_hhx_var+0x5d>
call   1050 <keep_call_on_line_104@plt>
jmp    11c2 <test_hhx_var+0x62>
jmp    11c7 <test_hhx_var+0x67>
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
jne    11da <test_hhx_var+0x7a>
call   1060 <keep_call_on_line_105@plt>
jmp    11df <test_hhx_var+0x7f>
jmp    11e4 <test_hhx_var+0x84>
mov    $0x3,%eax
cmp    -0x8(%rbp),%eax
jne    11f7 <test_hhx_var+0x97>
call   1040 <keep_call_on_line_106@plt>
jmp    11fc <test_hhx_var+0x9c>
jmp    1201 <test_hhx_var+0xa1>
mov    $0x4,%eax
cmp    -0x8(%rbp),%eax
jne    1214 <test_hhx_var+0xb4>
call   1070 <keep_call_on_line_107@plt>
jmp    1219 <test_hhx_var+0xb9>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_hhx_var>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ecx
lea    0xea3(%rip),%rdx
xor    %edi,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
mov    %eax,%r14d
lea    -0x1(%r14),%ebx
cmp    $0x4,%ebx
jb     1189 <test_hhx_var+0x29>
call   1080 <failure_on_line_102@plt>
cmp    $0x3,%ebx
ja     11b8 <test_hhx_var+0x58>
lea    0xe6b(%rip),%rax
movslq (%rax,%rbx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
call   1050 <keep_call_on_line_104@plt>
jmp    11b8 <test_hhx_var+0x58>
call   1060 <keep_call_on_line_105@plt>
jmp    11b8 <test_hhx_var+0x58>
call   1040 <keep_call_on_line_106@plt>
jmp    11b8 <test_hhx_var+0x58>
call   1070 <keep_call_on_line_107@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%#hhx\00"
define i32 @test_hhx_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 ([6 x i8], [6 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, 5
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
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [6 x i8] c"%#hhx\00"
define i32 @test_hhx_var(i32 %0) {
%2 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* null, i64 0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %0)
%3 = add i32 %2, -1
%4 = icmp ult i32 %3, 4
br i1 %4, label %6, label %5
5: ; preds = %1
tail call void @failure_on_line_102()
br label %6
6: ; preds = %5, %1
switch i32 %2, label %11 [
i32 1, label %7
i32 2, label %8
i32 3, label %9
i32 4, label %10
]
7: ; preds = %6
tail call void @keep_call_on_line_104()
br label %11
8: ; preds = %6
tail call void @keep_call_on_line_105()
br label %11
9: ; preds = %6
tail call void @keep_call_on_line_106()
br label %11
10: ; preds = %6
tail call void @keep_call_on_line_107()
br label %11
11: ; preds = %9, %8, %7, %6, %10
ret i32 %2
}