printf2(char *fmt, ...) {
  __builtin_va_list l;
  __builtin_va_start(l, 2531);
  for (; *fmt; fmt++)
    if (*fmt == '%') {
      switch (*++fmt) {
      case 's':;
        char *s = __builtin_va_arg(l, char *);
        write(1, s, strlen2(s));
        break;
      case 'd':;
        int d = '0' + __builtin_va_arg(l, int);
        write(1, &d, 1);
        break;
      default:
        write(1, fmt - 1, 1);
        goto norm;
      }
    } else {
    norm:
      write(1, fmt, 1);
    }
  __builtin_va_end(l);
}


x86 assembly (clang, -O0):
<printf2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
test   %al,%al
je     115f <printf2+0x3f>
movaps %xmm0,-0xc0(%rbp)
movaps %xmm1,-0xb0(%rbp)
movaps %xmm2,-0xa0(%rbp)
movaps %xmm3,-0x90(%rbp)
movaps %xmm4,-0x80(%rbp)
movaps %xmm5,-0x70(%rbp)
movaps %xmm6,-0x60(%rbp)
movaps %xmm7,-0x50(%rbp)
mov    %r9,-0xc8(%rbp)
mov    %r8,-0xd0(%rbp)
mov    %rcx,-0xd8(%rbp)
mov    %rdx,-0xe0(%rbp)
mov    %rsi,-0xe8(%rbp)
mov    %rdi,-0x10(%rbp)
lea    -0x30(%rbp),%rax
lea    -0xf0(%rbp),%rcx
mov    %rcx,0x10(%rax)
lea    0x10(%rbp),%rcx
mov    %rcx,0x8(%rax)
movl   $0x30,0x4(%rax)
movl   $0x8,(%rax)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1371 <printf2+0x251>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    1344 <printf2+0x224>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl 0x1(%rax),%eax
mov    %eax,-0xf4(%rbp)
sub    $0x64,%eax
je     129f <printf2+0x17f>
jmp    11ee <printf2+0xce>
mov    -0xf4(%rbp),%eax
sub    $0x73,%eax
jne    1324 <printf2+0x204>
jmp    1202 <printf2+0xe2>
lea    -0x30(%rbp),%rax
mov    %rax,-0x100(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0xf8(%rbp)
cmp    $0x28,%eax
ja     1244 <printf2+0x124>
mov    -0x100(%rbp),%rcx
mov    -0xf8(%rbp),%edx
movslq %edx,%rax
add    0x10(%rcx),%rax
add    $0x8,%edx
mov    %edx,(%rcx)
mov    %rax,-0x108(%rbp)
jmp    1261 <printf2+0x141>
mov    -0x100(%rbp),%rcx
mov    0x8(%rcx),%rdx
mov    %rdx,%rax
add    $0x8,%rdx
mov    %rdx,0x8(%rcx)
mov    %rax,-0x108(%rbp)
mov    -0x108(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x110(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x0,%al
call   1040 <strlen2@plt>
mov    -0x110(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
mov    $0x0,%al
call   1030 <write@plt>
jmp    133f <printf2+0x21f>
lea    -0x30(%rbp),%rax
mov    %rax,-0x120(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x114(%rbp)
cmp    $0x28,%eax
ja     12e1 <printf2+0x1c1>
mov    -0x120(%rbp),%rcx
mov    -0x114(%rbp),%edx
movslq %edx,%rax
add    0x10(%rcx),%rax
add    $0x8,%edx
mov    %edx,(%rcx)
mov    %rax,-0x128(%rbp)
jmp    12fe <printf2+0x1de>
mov    -0x120(%rbp),%rcx
mov    0x8(%rcx),%rdx
mov    %rdx,%rax
add    $0x8,%rdx
mov    %rdx,0x8(%rcx)
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rax
mov    (%rax),%eax
add    $0x30,%eax
mov    %eax,-0x3c(%rbp)
mov    $0x1,%edx
lea    -0x3c(%rbp),%rsi
mov    %edx,%edi
mov    $0x0,%al
call   1030 <write@plt>
jmp    133f <printf2+0x21f>
mov    -0x10(%rbp),%rsi
add    $0xffffffffffffffff,%rsi
mov    $0x1,%edx
mov    %edx,%edi
mov    $0x0,%al
call   1030 <write@plt>
jmp    1349 <printf2+0x229>
jmp    135b <printf2+0x23b>
jmp    1349 <printf2+0x229>
mov    -0x10(%rbp),%rsi
mov    $0x1,%edx
mov    %edx,%edi
mov    $0x0,%al
call   1030 <write@plt>
jmp    1360 <printf2+0x240>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11aa <printf2+0x8a>
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printf2>:
push   %r15
push   %r14
push   %rbx
sub    $0xd0,%rsp
mov    %rdi,%rbx
mov    %rsi,0x28(%rsp)
mov    %rdx,0x30(%rsp)
mov    %rcx,0x38(%rsp)
mov    %r8,0x40(%rsp)
mov    %r9,0x48(%rsp)
test   %al,%al
je     1183 <printf2+0x63>
movaps %xmm0,0x50(%rsp)
movaps %xmm1,0x60(%rsp)
movaps %xmm2,0x70(%rsp)
movaps %xmm3,0x80(%rsp)
movaps %xmm4,0x90(%rsp)
movaps %xmm5,0xa0(%rsp)
movaps %xmm6,0xb0(%rsp)
movaps %xmm7,0xc0(%rsp)
lea    0x20(%rsp),%rax
mov    %rax,0x10(%rsp)
lea    0xf0(%rsp),%rax
mov    %rax,0x8(%rsp)
movabs $0x3000000008,%rax
mov    %rax,(%rsp)
lea    0x1c(%rsp),%r14
jmp    11d0 <printf2+0xb0>
nop
test   %al,%al
je     1292 <printf2+0x172>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x25,%al
jne    11b0 <printf2+0x90>
lea    0x1(%rbx),%r15
movsbl 0x1(%rbx),%eax
cmp    $0x64,%eax
je     1202 <printf2+0xe2>
cmp    $0x73,%eax
jne    121b <printf2+0xfb>
mov    (%rsp),%ecx
cmp    $0x28,%rcx
ja     1234 <printf2+0x114>
mov    %rcx,%rax
add    0x10(%rsp),%rax
add    $0x8,%ecx
mov    %ecx,(%rsp)
jmp    1242 <printf2+0x122>
mov    (%rsp),%ecx
cmp    $0x28,%rcx
ja     125b <printf2+0x13b>
mov    %rcx,%rax
add    0x10(%rsp),%rax
add    $0x8,%ecx
mov    %ecx,(%rsp)
jmp    1269 <printf2+0x149>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    %r15,%rbx
jmp    11b8 <printf2+0x98>
mov    0x8(%rsp),%rax
lea    0x8(%rax),%rcx
mov    %rcx,0x8(%rsp)
mov    (%rax),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <strlen2@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
jmp    127f <printf2+0x15f>
mov    0x8(%rsp),%rax
lea    0x8(%rax),%rcx
mov    %rcx,0x8(%rsp)
mov    (%rax),%eax
add    $0x30,%eax
mov    %eax,0x1c(%rsp)
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
add    $0x1,%r15
mov    %r15,%rbx
jmp    11d0 <printf2+0xb0>
add    $0xd0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.__va_list_tag = type { i32, i32, i8*, i8* }
define i32 @printf2(i8* %0, ...) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [1 x %struct.__va_list_tag]
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
%7 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %4, i64 0, i64 0
%8 = bitcast %struct.__va_list_tag* %7 to i8*
br label %9
9: ; preds = %77, %1
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %80
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 37
br i1 %17, label %18, label %72
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %3
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
switch i32 %22, label %67 [
i32 115, label %23
i32 100, label %46
]
23: ; preds = %18
%24 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %4, i64 0, i64 0
%25 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = icmp ule i32 %26, 40
br i1 %27, label %28, label %34
28: ; preds = %23
%29 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %24, i32 0, i32 3
%30 = load i8*, i8** %29
%31 = getelementptr i8, i8* %30, i32 %26
%32 = bitcast i8* %31 to i8**
%33 = add i32 %26, 8
store i32 %33, i32* %25
br label %39
34: ; preds = %23
%35 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %24, i32 0, i32 2
%36 = load i8*, i8** %35
%37 = bitcast i8* %36 to i8**
%38 = getelementptr i8, i8* %36, i32 8
store i8* %38, i8** %35
br label %39
39: ; preds = %34, %28
%40 = phi i8** [ %32, %28 ], [ %37, %34 ]
%41 = load i8*, i8** %40
store i8* %41, i8** %5
%42 = load i8*, i8** %5
%43 = load i8*, i8** %5
%44 = call i32 (i8*, ...) bitcast (i32 (...)* @strlen2 to i32 (i8*, ...)*)(i8* %43)
%45 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 1, i8* %42, i32 %44)
br label %71
46: ; preds = %18
%47 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %4, i64 0, i64 0
%48 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %47, i32 0, i32 0
%49 = load i32, i32* %48
%50 = icmp ule i32 %49, 40
br i1 %50, label %51, label %57
51: ; preds = %46
%52 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %47, i32 0, i32 3
%53 = load i8*, i8** %52
%54 = getelementptr i8, i8* %53, i32 %49
%55 = bitcast i8* %54 to i32*
%56 = add i32 %49, 8
store i32 %56, i32* %48
br label %62
57: ; preds = %46
%58 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %47, i32 0, i32 2
%59 = load i8*, i8** %58
%60 = bitcast i8* %59 to i32*
%61 = getelementptr i8, i8* %59, i32 8
store i8* %61, i8** %58
br label %62
62: ; preds = %57, %51
%63 = phi i32* [ %55, %51 ], [ %60, %57 ]
%64 = load i32, i32* %63
%65 = add nsw i32 48, %64
store i32 %65, i32* %6
%66 = call i32 (i32, i32*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i32*, i32, ...)*)(i32 1, i32* %6, i32 1)
br label %71
67: ; preds = %18
%68 = load i8*, i8** %3
%69 = getelementptr inbounds i8, i8* %68, i64 -1
%70 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 1, i8* %69, i32 1)
br label %73
71: ; preds = %62, %39
br label %76
72: ; preds = %13
br label %73
73: ; preds = %72, %67
%74 = load i8*, i8** %3
%75 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 1, i8* %74, i32 1)
br label %76
76: ; preds = %73, %71
br label %77
77: ; preds = %76
%78 = load i8*, i8** %3
%79 = getelementptr inbounds i8, i8* %78, i32 1
store i8* %79, i8** %3
br label %9
80: ; preds = %9
%81 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %4, i64 0, i64 0
%82 = bitcast %struct.__va_list_tag* %81 to i8*
%83 = load i32, i32* %2
ret i32 %83
}

LLVM IR (-O2):
%struct.__va_list_tag = type { i32, i32, i8*, i8* }
define i32 @printf2(i8* %0, ...) {
%2 = alloca [1 x %struct.__va_list_tag]
%3 = alloca i32
%4 = bitcast [1 x %struct.__va_list_tag]* %2 to i8*
%5 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %2, i64 0, i64 0, i32 0
%6 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %2, i64 0, i64 0, i32 2
%7 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %2, i64 0, i64 0, i32 3
br label %8
8: ; preds = %54, %1
%9 = phi i8* [ %0, %1 ], [ %56, %54 ]
%10 = load i8, i8* %9
switch i8 %10, label %51 [
i8 0, label %57
i8 37, label %11
]
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %9, i64 1
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
switch i32 %14, label %49 [
i32 115, label %15
i32 100, label %32
]
15: ; preds = %11
%16 = load i32, i32* %5
%17 = icmp ult i32 %16, 41
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = load i8*, i8** %7
%20 = zext i32 %16 to i64
%21 = getelementptr i8, i8* %19, i64 %20
%22 = add nuw nsw i32 %16, 8
store i32 %22, i32* %5
br label %26
23: ; preds = %15
%24 = load i8*, i8** %6
%25 = getelementptr i8, i8* %24, i64 8
store i8* %25, i8** %6
br label %26
26: ; preds = %23, %18
%27 = phi i8* [ %21, %18 ], [ %24, %23 ]
%28 = bitcast i8* %27 to i8**
%29 = load i8*, i8** %28
%30 = call i32 (i8*, ...) bitcast (i32 (...)* @strlen2 to i32 (i8*, ...)*)(i8* %29)
%31 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 1, i8* %29, i32 %30)
br label %54
32: ; preds = %11
%33 = load i32, i32* %5
%34 = icmp ult i32 %33, 41
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load i8*, i8** %7
%37 = zext i32 %33 to i64
%38 = getelementptr i8, i8* %36, i64 %37
%39 = add nuw nsw i32 %33, 8
store i32 %39, i32* %5
br label %43
40: ; preds = %32
%41 = load i8*, i8** %6
%42 = getelementptr i8, i8* %41, i64 8
store i8* %42, i8** %6
br label %43
43: ; preds = %40, %35
%44 = phi i8* [ %38, %35 ], [ %41, %40 ]
%45 = bitcast i8* %44 to i32*
%46 = load i32, i32* %45
%47 = add nsw i32 %46, 48
store i32 %47, i32* %3
%48 = call i32 (i32, i32*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i32*, i32, ...)*)(i32 1, i32* %3, i32 1)
br label %54
49: ; preds = %11
%50 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 1, i8* %9, i32 1)
br label %51
51: ; preds = %8, %49
%52 = phi i8* [ %12, %49 ], [ %9, %8 ]
%53 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 1, i8* %52, i32 1)
br label %54
54: ; preds = %51, %43, %26
%55 = phi i8* [ %52, %51 ], [ %12, %43 ], [ %12, %26 ]
%56 = getelementptr inbounds i8, i8* %55, i64 1
br label %8
57: ; preds = %8
ret i32 undef
}