int f2(const char *s) {
  int n = __builtin_snprintf(0, 0, "%.*s", 2, s);
  do {
    extern void failure_on_line_59(void);
    if (!(0 <= n && n <= 2))
      failure_on_line_59();
  } while (0);
  do {
    extern void keep_call_on_line_61(void);
    if (0 == n)
      keep_call_on_line_61();
  } while (0);
  do {
    extern void keep_call_on_line_62(void);
    if (1 == n)
      keep_call_on_line_62();
  } while (0);
  do {
    extern void keep_call_on_line_63(void);
    if (2 == n)
      keep_call_on_line_63();
  } while (0);
  return n;
}


x86 assembly (clang, -O0):
<f2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%r8
xor    %eax,%eax
mov    %eax,%esi
lea    0xe95(%rip),%rdx
mov    $0x2,%ecx
mov    %rsi,%rdi
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
jg     1192 <f2+0x42>
cmpl   $0x2,-0xc(%rbp)
jle    1197 <f2+0x47>
call   1050 <failure_on_line_59@plt>
jmp    119c <f2+0x4c>
jmp    11a1 <f2+0x51>
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
jne    11b1 <f2+0x61>
call   1060 <keep_call_on_line_61@plt>
jmp    11b6 <f2+0x66>
jmp    11bb <f2+0x6b>
mov    $0x1,%eax
cmp    -0xc(%rbp),%eax
jne    11ce <f2+0x7e>
call   1030 <keep_call_on_line_62@plt>
jmp    11d3 <f2+0x83>
jmp    11d8 <f2+0x88>
mov    $0x2,%eax
cmp    -0xc(%rbp),%eax
jne    11eb <f2+0x9b>
call   1070 <keep_call_on_line_63@plt>
jmp    11f0 <f2+0xa0>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f2>:
push   %rbx
mov    %rdi,%r8
lea    0xea5(%rip),%rdx
xor    %edi,%edi
xor    %esi,%esi
mov    $0x2,%ecx
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %eax,%ebx
cmp    $0x3,%eax
jb     1177 <f2+0x27>
call   1050 <failure_on_line_59@plt>
cmp    $0x2,%ebx
je     118c <f2+0x3c>
cmp    $0x1,%ebx
je     1193 <f2+0x43>
test   %ebx,%ebx
jne    1198 <f2+0x48>
call   1060 <keep_call_on_line_61@plt>
jmp    1198 <f2+0x48>
call   1070 <keep_call_on_line_63@plt>
jmp    1198 <f2+0x48>
call   1030 <keep_call_on_line_62@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%.*s\00"
define i32 @f2(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %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 2, i8* %4)
store i32 %5, i32* %3
br label %6
6: ; preds = %1
%7 = load i32, i32* %3
%8 = icmp sle i32 0, %7
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = load i32, i32* %3
%11 = icmp sle i32 %10, 2
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 0, %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 1, %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 2, %28
br i1 %29, label %30, label %31
30: ; preds = %27
br label %31
31: ; preds = %30, %27
br label %32
32: ; preds = %31
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str = [5 x i8] c"%.*s\00"
define i32 @f2(i8* %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 2, i8* %0)
%3 = icmp ult i32 %2, 3
br i1 %3, label %5, label %4
4: ; preds = %1
tail call void @failure_on_line_59()
br label %5
5: ; preds = %4, %1
switch i32 %2, label %9 [
i32 0, label %6
i32 1, label %7
i32 2, label %8
]
6: ; preds = %5
tail call void @keep_call_on_line_61()
br label %9
7: ; preds = %5
tail call void @keep_call_on_line_62()
br label %9
8: ; preds = %5
tail call void @keep_call_on_line_63()
br label %9
9: ; preds = %7, %6, %5, %8
ret i32 %2
}