int main() {
  char buf[256];
  int errors = 0;
  snprintf(buf, 64,
           "%f%%%sA%cA%cA%cAAAA%"
           "sAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
           "BBBBBBBBBBB", 'C', 'D', 'E',
           "YAAAAAAABBBBCCCCCCCCDDDDDDDDEEEEEEEEFFFFFFFFGGGGGGGGGHHHHHHHHIIIIII"
           "JJJJJJ");
  errors +=
      (strncmp(
           buf,
           "f%BBBBBBBBBBBACADAEAAAAYAAAAAAABBBBCCCCCCCCDDDDDDDDEEEEEEEEFFFF",
           70) != 0);
  printout(1, "f%BBBBBBBBBBBACADAEAAAAYAAAAAAABBBBCCCCCCCCDDDDDDDDEEEEEEEEFFFF",
           buf);
  snprintf(buf, 40, "%b", 0xF0F0F0F0);
  errors += (strcmp(buf, "11110000111100001111000011110000") != 0);
  printout(2, "11110000111100001111000011110000", buf);
  snprintf(buf, 40, "%o", 0123456712);
  errors += (strcmp(buf, "123456712") != 0);
  printout(3, "123456712", buf);
  printf("%d out of 3 tests passed\n", 3 - errors);
  return errors;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x114(%rbp)
lea    -0x110(%rbp),%rdi
mov    $0x40,%esi
lea    0xe81(%rip),%rdx
lea    0xeca(%rip),%rcx
mov    $0x43,%r8d
mov    $0x44,%r9d
lea    0xec3(%rip),%rax
movl   $0x45,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    -0x110(%rbp),%rdi
lea    0xeec(%rip),%rsi
mov    $0x46,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    -0x114(%rbp),%eax
mov    %eax,-0x114(%rbp)
lea    -0x110(%rbp),%rdx
mov    $0x1,%edi
lea    0xeb8(%rip),%rsi
mov    $0x0,%al
call   1040 <printout@plt>
lea    -0x110(%rbp),%rdi
mov    $0x28,%esi
lea    0xede(%rip),%rdx
mov    $0xf0f0f0f0,%ecx
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    -0x110(%rbp),%rdi
lea    0xec7(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    -0x114(%rbp),%eax
mov    %eax,-0x114(%rbp)
lea    -0x110(%rbp),%rdx
mov    $0x2,%edi
lea    0xe98(%rip),%rsi
mov    $0x0,%al
call   1040 <printout@plt>
lea    -0x110(%rbp),%rdi
mov    $0x28,%esi
lea    0xe9f(%rip),%rdx
mov    $0x14e5dca,%ecx
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    -0x110(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    -0x114(%rbp),%eax
mov    %eax,-0x114(%rbp)
lea    -0x110(%rbp),%rdx
mov    $0x3,%edi
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1040 <printout@plt>
mov    $0x3,%esi
sub    -0x114(%rbp),%esi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x114(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
lea    0xf08(%rip),%rbp
lea    0xea5(%rip),%rdx
lea    0xeee(%rip),%rcx
mov    %rsp,%r15
mov    $0x40,%esi
mov    %r15,%rdi
mov    $0x43,%r8d
mov    $0x44,%r9d
xor    %eax,%eax
push   %rbp
push   $0x45
call   1050 <snprintf@plt>
add    $0x10,%rsp
lea    0xf18(%rip),%rbp
mov    $0x40,%edx
mov    %r15,%rdi
mov    %rbp,%rsi
call   1060 <bcmp@plt>
mov    %eax,%r14d
mov    $0x1,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1030 <printout@plt>
lea    0xf2c(%rip),%rdx
mov    $0x28,%esi
mov    %r15,%rdi
mov    $0xf0f0f0f0,%ecx
xor    %eax,%eax
call   1050 <snprintf@plt>
lea    0xf14(%rip),%rbp
mov    $0x21,%edx
mov    %r15,%rdi
mov    %rbp,%rsi
call   1060 <bcmp@plt>
xor    %ebx,%ebx
test   %eax,%eax
setne  %bl
cmp    $0x1,%r14d
sbb    $0xffffffff,%ebx
mov    $0x2,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1030 <printout@plt>
lea    0xefe(%rip),%rdx
mov    $0x28,%esi
mov    %r15,%rdi
mov    $0x14e5dca,%ecx
xor    %eax,%eax
call   1050 <snprintf@plt>
movabs $0x3137363534333231,%rax
36 37 31
xor    (%rsp),%rax
movzwl 0x8(%rsp),%ecx
xor    $0x32,%rcx
xor    %ebp,%ebp
or     %rax,%rcx
setne  %bpl
add    %ebx,%ebp
lea    0xec4(%rip),%rsi
mov    $0x3,%ebx
mov    $0x3,%edi
mov    %r15,%rdx
xor    %eax,%eax
call   1030 <printout@plt>
sub    %ebp,%ebx
lea    0xeb1(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [80 x i8] c"%f%%%sA%cA%cA%cAAAA%sAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\00"
@.str.1 = [12 x i8] c"BBBBBBBBBBB\00"
@.str.2 = [74 x i8] c"YAAAAAAABBBBCCCCCCCCDDDDDDDDEEEEEEEEFFFFFFFFGGGGGGGGGHHHHHHHHIIIIIIJJJJJJ\00"
@.str.3 = [64 x i8] c"f%BBBBBBBBBBBACADAEAAAAYAAAAAAABBBBCCCCCCCCDDDDDDDDEEEEEEEEFFFF\00"
@.str.4 = [3 x i8] c"%b\00"
@.str.5 = [33 x i8] c"11110000111100001111000011110000\00"
@.str.6 = [3 x i8] c"%o\00"
@.str.7 = [10 x i8] c"123456712\00"
@.str.8 = [26 x i8] c"%d out of 3 tests passed\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %4, i64 64, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 67, i32 68, i32 69, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.2, i64 0, i64 0))
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%7 = call i32 @strncmp(i8* %6, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0), i64 70)
%8 = icmp ne i32 %7, 0
%9 = zext i1 %8 to i32
%10 = load i32, i32* %3
%11 = add nsw i32 %10, %9
store i32 %11, i32* %3
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%13 = call i32 (i32, i8*, i8*, ...) bitcast (i32 (...)* @printout to i32 (i32, i8*, i8*, ...)*)(i32 1, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%15 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %14, i64 40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 -252645136)
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%17 = call i32 @strcmp(i8* %16, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
%18 = icmp ne i32 %17, 0
%19 = zext i1 %18 to i32
%20 = load i32, i32* %3
%21 = add nsw i32 %20, %19
store i32 %21, i32* %3
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%23 = call i32 (i32, i8*, i8*, ...) bitcast (i32 (...)* @printout to i32 (i32, i8*, i8*, ...)*)(i32 2, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %22)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%25 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %24, i64 40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 21913034)
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%27 = call i32 @strcmp(i8* %26, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
%29 = zext i1 %28 to i32
%30 = load i32, i32* %3
%31 = add nsw i32 %30, %29
store i32 %31, i32* %3
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%33 = call i32 (i32, i8*, i8*, ...) bitcast (i32 (...)* @printout to i32 (i32, i8*, i8*, ...)*)(i32 3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %32)
%34 = load i32, i32* %3
%35 = sub nsw i32 3, %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %35)
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [80 x i8] c"%f%%%sA%cA%cA%cAAAA%sAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\00"
@.str.1 = [12 x i8] c"BBBBBBBBBBB\00"
@.str.2 = [74 x i8] c"YAAAAAAABBBBCCCCCCCCDDDDDDDDEEEEEEEEFFFFFFFFGGGGGGGGGHHHHHHHHIIIIIIJJJJJJ\00"
@.str.3 = [64 x i8] c"f%BBBBBBBBBBBACADAEAAAAYAAAAAAABBBBCCCCCCCCDDDDDDDDEEEEEEEEFFFF\00"
@.str.4 = [3 x i8] c"%b\00"
@.str.5 = [33 x i8] c"11110000111100001111000011110000\00"
@.str.6 = [3 x i8] c"%o\00"
@.str.7 = [10 x i8] c"123456712\00"
@.str.8 = [26 x i8] c"%d out of 3 tests passed\0A\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %2, i64 64, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 67, i32 68, i32 69, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.2, i64 0, i64 0))
%4 = call i32 @bcmp(i8* dereferenceable(64) %2, i8* dereferenceable(64) getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0), i64 64)
%5 = icmp ne i32 %4, 0
%6 = zext i1 %5 to i32
%7 = call i32 (i32, i8*, i8*, ...) bitcast (i32 (...)* @printout to i32 (i32, i8*, i8*, ...)*)(i32 1, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%8 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %2, i64 40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 -252645136)
%9 = call i32 @bcmp(i8* dereferenceable(33) %2, i8* dereferenceable(33) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i64 33)
%10 = icmp ne i32 %9, 0
%11 = zext i1 %10 to i32
%12 = add nuw nsw i32 %11, %6
%13 = call i32 (i32, i8*, i8*, ...) bitcast (i32 (...)* @printout to i32 (i32, i8*, i8*, ...)*)(i32 2, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %2)
%14 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %2, i64 40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 21913034)
%15 = call i32 @bcmp(i8* dereferenceable(10) %2, i8* dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i64 10)
%16 = icmp ne i32 %15, 0
%17 = zext i1 %16 to i32
%18 = add nuw nsw i32 %12, %17
%19 = call i32 (i32, i8*, i8*, ...) bitcast (i32 (...)* @printout to i32 (i32, i8*, i8*, ...)*)(i32 3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %2)
%20 = sub nuw nsw i32 3, %18
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %20)
ret i32 %18
}