void test_va_int(__builtin_va_list va) {
  do {
    int n = __builtin_vsnprintf(0, 0, "%02hhx", va);
    do {
      extern void failure_on_line_152(int);
      extern void success_on_line_152(int);
      if (n == 2)
        success_on_line_152(n);
      else
        failure_on_line_152(n);
    } while (0);
  } while (0);
  do {
    int n = __builtin_vsnprintf(0, 0, "%04hx", va);
    do {
      extern void failure_on_line_153(int);
      extern void success_on_line_153(int);
      if (n == 4)
        success_on_line_153(n);
      else
        failure_on_line_153(n);
    } while (0);
  } while (0);
}


x86 assembly (clang, -O0):
<test_va_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%esi
lea    0xe95(%rip),%rdx
mov    %rsi,%rdi
call   1050 <vsnprintf@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x2,-0xc(%rbp)
jne    118d <test_va_int+0x3d>
mov    -0xc(%rbp),%edi
call   1040 <success_on_line_152@plt>
jmp    1195 <test_va_int+0x45>
mov    -0xc(%rbp),%edi
call   1060 <failure_on_line_152@plt>
jmp    119a <test_va_int+0x4a>
jmp    119f <test_va_int+0x4f>
jmp    11a4 <test_va_int+0x54>
mov    -0x8(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%esi
lea    0xe54(%rip),%rdx
mov    %rsi,%rdi
call   1050 <vsnprintf@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jne    11d5 <test_va_int+0x85>
mov    -0x10(%rbp),%edi
call   1070 <success_on_line_153@plt>
jmp    11dd <test_va_int+0x8d>
mov    -0x10(%rbp),%edi
call   1030 <failure_on_line_153@plt>
jmp    11e2 <test_va_int+0x92>
jmp    11e7 <test_va_int+0x97>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_va_int>:
push   %rbx
mov    %rdi,%rbx
lea    0xea5(%rip),%rdx
xor    %edi,%edi
xor    %esi,%esi
mov    %rbx,%rcx
call   1050 <vsnprintf@plt>
cmp    $0x2,%eax
jne    1178 <test_va_int+0x28>
mov    $0x2,%edi
call   1040 <success_on_line_152@plt>
jmp    117f <test_va_int+0x2f>
mov    %eax,%edi
call   1060 <failure_on_line_152@plt>
lea    0xe81(%rip),%rdx
xor    %edi,%edi
xor    %esi,%esi
mov    %rbx,%rcx
call   1050 <vsnprintf@plt>
cmp    $0x4,%eax
jne    11a2 <test_va_int+0x52>
mov    $0x4,%edi
pop    %rbx
jmp    1070 <success_on_line_153@plt>
mov    %eax,%edi
pop    %rbx
jmp    1030 <failure_on_line_153@plt>

LLVM IR (-O0):
%struct.__va_list_tag = type { i32, i32, i8*, i8* }
@.str = [7 x i8] c"%02hhx\00"
@.str.1 = [6 x i8] c"%04hx\00"
define void @test_va_int(%struct.__va_list_tag* %0) {
%2 = alloca %struct.__va_list_tag*
%3 = alloca i32
%4 = alloca i32
store %struct.__va_list_tag* %0, %struct.__va_list_tag** %2
br label %5
5: ; preds = %1
%6 = load %struct.__va_list_tag*, %struct.__va_list_tag** %2
%7 = call i32 @vsnprintf(i8* null, i64 0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %struct.__va_list_tag* %6)
store i32 %7, i32* %3
br label %8
8: ; preds = %5
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = load i32, i32* %3
br label %15
13: ; preds = %8
%14 = load i32, i32* %3
br label %15
15: ; preds = %13, %11
br label %16
16: ; preds = %15
br label %17
17: ; preds = %16
br label %18
18: ; preds = %17
%19 = load %struct.__va_list_tag*, %struct.__va_list_tag** %2
%20 = call i32 @vsnprintf(i8* null, i64 0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %struct.__va_list_tag* %19)
store i32 %20, i32* %4
br label %21
21: ; preds = %18
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 4
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = load i32, i32* %4
br label %28
26: ; preds = %21
%27 = load i32, i32* %4
br label %28
28: ; preds = %26, %24
br label %29
29: ; preds = %28
br label %30
30: ; preds = %29
ret void
}

LLVM IR (-O2):
%struct.__va_list_tag = type { i32, i32, i8*, i8* }
@.str = [7 x i8] c"%02hhx\00"
@.str.1 = [6 x i8] c"%04hx\00"
define void @test_va_int(%struct.__va_list_tag* %0) {
%2 = tail call i32 @vsnprintf(i8* null, i64 0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %struct.__va_list_tag* %0)
%3 = icmp eq i32 %2, 2
br i1 %3, label %4, label %5
4: ; preds = %1
tail call void @success_on_line_152(i32 2)
br label %6
5: ; preds = %1
tail call void @failure_on_line_152(i32 %2)
br label %6
6: ; preds = %5, %4
%7 = tail call i32 @vsnprintf(i8* null, i64 0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %struct.__va_list_tag* %0)
%8 = icmp eq i32 %7, 4
br i1 %8, label %9, label %10
9: ; preds = %6
tail call void @success_on_line_153(i32 4)
br label %11
10: ; preds = %6
tail call void @failure_on_line_153(i32 %7)
br label %11
11: ; preds = %10, %9
ret void
}