int main() {
  char s[] = "hello";
  int max = 4;
  printf("%.*s\n", max, s);
  printf("%.4s\n", s);
  printf(":%s:\n", "hello, world");
  printf(":%10s:\n", "hello, world");
  printf(":%.10s:\n", "hello, world");
  printf(":%-10s:\n", "hello, world");
  printf(":%.15s:\n", "hello, world");
  printf(":%-15s:\n", "hello, world");
  printf(":%15.10s:\n", "hello, world");
  printf(":%-15.10s:\n", "hello, world");
  char s2[20];
  sprintf(s2, "Test: %d", 10);
  printf("%s\n", s2);
  printf("%x\n", 138);
  printf("%o\n", 138);
  minprintf("Testing: %d -> %s\n", 10, "hehe");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xebb(%rip),%eax
mov    %eax,-0xa(%rbp)
mov    0xeb5(%rip),%ax
mov    %ax,-0x6(%rbp)
movl   $0x4,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    -0xa(%rbp),%rdx
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xa(%rbp),%rsi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8a(%rip),%rdi
lea    0xe89(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe88(%rip),%rdi
lea    0xe74(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe7b(%rip),%rdi
lea    0xe5f(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe6f(%rip),%rdi
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe63(%rip),%rdi
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe57(%rip),%rdi
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe4b(%rip),%rdi
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe41(%rip),%rdi
lea    0xdf6(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
lea    0xe34(%rip),%rsi
mov    $0xa,%edx
mov    $0x0,%al
call   1050 <sprintf@plt>
lea    -0x30(%rbp),%rsi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe18(%rip),%rdi
mov    $0x8a,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe09(%rip),%rdi
mov    $0x8a,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdfa(%rip),%rdi
mov    $0xa,%esi
lea    0xe01(%rip),%rdx
mov    $0x0,%al
call   1040 <minprintf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
movw   $0x6f,0xc(%rsp)
movl   $0x6c6c6568,0x8(%rsp)
6c
lea    0xeab(%rip),%rdi
lea    0x8(%rsp),%rbx
mov    $0x4,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe96(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe8b(%rip),%rdi
lea    0xe8a(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe86(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe7d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe75(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe6d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe65(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe5d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe57(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe52(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xa,%edx
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xe38(%rip),%rdi
mov    $0x8a,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe29(%rip),%rdi
mov    $0x8a,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe1a(%rip),%rdi
lea    0xe26(%rip),%rdx
mov    $0xa,%esi
xor    %eax,%eax
call   1050 <minprintf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.s = [6 x i8] c"hello\00"
@.str = [6 x i8] c"%.*s\0A\00"
@.str.1 = [6 x i8] c"%.4s\0A\00"
@.str.2 = [6 x i8] c":%s:\0A\00"
@.str.3 = [13 x i8] c"hello, world\00"
@.str.4 = [8 x i8] c":%10s:\0A\00"
@.str.5 = [9 x i8] c":%.10s:\0A\00"
@.str.6 = [9 x i8] c":%-10s:\0A\00"
@.str.7 = [9 x i8] c":%.15s:\0A\00"
@.str.8 = [9 x i8] c":%-15s:\0A\00"
@.str.9 = [11 x i8] c":%15.10s:\0A\00"
@.str.10 = [12 x i8] c":%-15.10s:\0A\00"
@.str.11 = [9 x i8] c"Test: %d\00"
@.str.12 = [4 x i8] c"%s\0A\00"
@.str.13 = [4 x i8] c"%x\0A\00"
@.str.14 = [4 x i8] c"%o\0A\00"
@.str.15 = [19 x i8] c"Testing: %d -> %s\0A\00"
@.str.16 = [5 x i8] c"hehe\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [6 x i8]
%3 = alloca i32
%4 = alloca [20 x i8]
store i32 0, i32* %1
%5 = bitcast [6 x i8]* %2 to i8*
store i32 4, i32* %3
%6 = load i32, i32* %3
%7 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %6, i8* %7)
%9 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%20 = call i32 (i8*, i8*, ...) @sprintf(i8* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0), i32 10)
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i8* %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), i32 138)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.14, i64 0, i64 0), i32 138)
%25 = call i32 (i8*, i32, i8*, ...) bitcast (i32 (...)* @minprintf to i32 (i8*, i32, i8*, ...)*)(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.15, i64 0, i64 0), i32 10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.16, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@__const.main.s = [6 x i8] c"hello\00"
@.str = [6 x i8] c"%.*s\0A\00"
@.str.1 = [6 x i8] c"%.4s\0A\00"
@.str.2 = [6 x i8] c":%s:\0A\00"
@.str.3 = [13 x i8] c"hello, world\00"
@.str.4 = [8 x i8] c":%10s:\0A\00"
@.str.5 = [9 x i8] c":%.10s:\0A\00"
@.str.6 = [9 x i8] c":%-10s:\0A\00"
@.str.7 = [9 x i8] c":%.15s:\0A\00"
@.str.8 = [9 x i8] c":%-15s:\0A\00"
@.str.9 = [11 x i8] c":%15.10s:\0A\00"
@.str.10 = [12 x i8] c":%-15.10s:\0A\00"
@.str.11 = [9 x i8] c"Test: %d\00"
@.str.13 = [4 x i8] c"%x\0A\00"
@.str.14 = [4 x i8] c"%o\0A\00"
@.str.15 = [19 x i8] c"Testing: %d -> %s\0A\00"
@.str.16 = [5 x i8] c"hehe\00"
define i32 @main() {
%1 = alloca [6 x i8]
%2 = alloca [20 x i8]
%3 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 4, i8* %3)
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%15 = call i32 (i8*, i8*, ...) @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0), i32 10)
%16 = call i32 @puts(i8* %14)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), i32 138)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.14, i64 0, i64 0), i32 138)
%19 = call i32 (i8*, i32, i8*, ...) bitcast (i32 (...)* @minprintf to i32 (i8*, i32, i8*, ...)*)(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.15, i64 0, i64 0), i32 10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.16, i64 0, i64 0))
ret i32 0
}