void test_misc() {
  char buffer[100];
  sprintf(buffer, "%u%u%ctest%d %s", 5, 3000, 'a', -20, "bit");
  assertStringsEqual(buffer, "53000atest-20 bit");
  sprintf(buffer, "%.*f", 2, 0.33333333);
  assertStringsEqual(buffer, "0.33");
  sprintf(buffer, "%.3s", "foobar");
  assertStringsEqual(buffer, "foo");
  sprintf(buffer, "%10.5d", 4);
  assertStringsEqual(buffer, "     00004");
  sprintf(buffer, "%*sx", -3, "hi");
  assertStringsEqual(buffer, "hi x");
}


x86 assembly (clang, -O0):
<test_misc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    -0x70(%rbp),%rdi
lea    0xed2(%rip),%rsi
mov    $0x5,%edx
mov    $0xbb8,%ecx
mov    $0x61,%r8d
mov    $0xffffffec,%r9d
lea    0xed3(%rip),%rax
mov    %rax,(%rsp)
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    -0x70(%rbp),%rdi
lea    0xeaf(%rip),%rsi
mov    $0x0,%al
call   1030 <assertStringsEqual@plt>
lea    -0x70(%rbp),%rdi
lea    0xeaf(%rip),%rsi
mov    $0x2,%edx
movsd  0xe78(%rip),%xmm0
mov    $0x1,%al
call   1040 <sprintf@plt>
lea    -0x70(%rbp),%rdi
lea    0xe95(%rip),%rsi
mov    $0x0,%al
call   1030 <assertStringsEqual@plt>
lea    -0x70(%rbp),%rdi
lea    0xe88(%rip),%rsi
lea    0xe86(%rip),%rdx
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    -0x70(%rbp),%rdi
lea    0xe7b(%rip),%rsi
mov    $0x0,%al
call   1030 <assertStringsEqual@plt>
lea    -0x70(%rbp),%rdi
lea    0xe6d(%rip),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    -0x70(%rbp),%rdi
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1030 <assertStringsEqual@plt>
lea    -0x70(%rbp),%rdi
lea    0xe56(%rip),%rsi
mov    $0xfffffffd,%edx
lea    0xe4f(%rip),%rcx
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    -0x70(%rbp),%rdi
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1030 <assertStringsEqual@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_misc>:
push   %rbx
sub    $0x80,%rsp
lea    0xef7(%rip),%rax
mov    %rax,(%rsp)
lea    0xece(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x5,%edx
mov    $0xbb8,%ecx
mov    $0x61,%r8d
mov    $0xffffffec,%r9d
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xeb2(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <assertStringsEqual@plt>
lea    0xeb3(%rip),%rsi
movsd  0xe81(%rip),%xmm0
mov    %rbx,%rdi
mov    $0x2,%edx
mov    $0x1,%al
call   1040 <sprintf@plt>
lea    0xe9a(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <assertStringsEqual@plt>
lea    0xe8e(%rip),%rsi
lea    0xe8c(%rip),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xe82(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <assertStringsEqual@plt>
lea    0xe75(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xe66(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <assertStringsEqual@plt>
lea    0xe60(%rip),%rsi
lea    0xe5e(%rip),%rcx
mov    %rbx,%rdi
mov    $0xfffffffd,%edx
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xe4b(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <assertStringsEqual@plt>
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"%u%u%ctest%d %s\00"
@.str.1 = [4 x i8] c"bit\00"
@.str.2 = [18 x i8] c"53000atest-20 bit\00"
@.str.3 = [5 x i8] c"%.*f\00"
@.str.4 = [5 x i8] c"0.33\00"
@.str.5 = [5 x i8] c"%.3s\00"
@.str.6 = [7 x i8] c"foobar\00"
@.str.7 = [4 x i8] c"foo\00"
@.str.8 = [7 x i8] c"%10.5d\00"
@.str.9 = [11 x i8] c" 00004\00"
@.str.10 = [5 x i8] c"%*sx\00"
@.str.11 = [3 x i8] c"hi\00"
@.str.12 = [5 x i8] c"hi x\00"
define void @test_misc() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = call i32 (i8*, i8*, ...) @sprintf(i8* %2, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 5, i32 3000, i32 97, i32 -20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%5 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @assertStringsEqual to i32 (i8*, i8*, ...)*)(i8* %4, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%7 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 2, double 0x3FD5555551C112DA)
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%9 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @assertStringsEqual to i32 (i8*, i8*, ...)*)(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%11 = call i32 (i8*, i8*, ...) @sprintf(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%13 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @assertStringsEqual to i32 (i8*, i8*, ...)*)(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%15 = call i32 (i8*, i8*, ...) @sprintf(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32 4)
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%17 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @assertStringsEqual to i32 (i8*, i8*, ...)*)(i8* %16, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%19 = call i32 (i8*, i8*, ...) @sprintf(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i32 -3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%21 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @assertStringsEqual to i32 (i8*, i8*, ...)*)(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"%u%u%ctest%d %s\00"
@.str.1 = [4 x i8] c"bit\00"
@.str.2 = [18 x i8] c"53000atest-20 bit\00"
@.str.3 = [5 x i8] c"%.*f\00"
@.str.4 = [5 x i8] c"0.33\00"
@.str.5 = [5 x i8] c"%.3s\00"
@.str.6 = [7 x i8] c"foobar\00"
@.str.7 = [4 x i8] c"foo\00"
@.str.8 = [7 x i8] c"%10.5d\00"
@.str.9 = [11 x i8] c" 00004\00"
@.str.10 = [5 x i8] c"%*sx\00"
@.str.11 = [3 x i8] c"hi\00"
@.str.12 = [5 x i8] c"hi x\00"
define void @test_misc() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = call i32 (i8*, i8*, ...) @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 5, i32 3000, i32 97, i32 -20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @assertStringsEqual to i32 (i8*, i8*, ...)*)(i8* %2, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%5 = call i32 (i8*, i8*, ...) @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 2, double 0x3FD5555551C112DA)
%6 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @assertStringsEqual to i32 (i8*, i8*, ...)*)(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%7 = call i32 (i8*, i8*, ...) @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%8 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @assertStringsEqual to i32 (i8*, i8*, ...)*)(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%9 = call i32 (i8*, i8*, ...) @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32 4)
%10 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @assertStringsEqual to i32 (i8*, i8*, ...)*)(i8* %2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
%11 = call i32 (i8*, i8*, ...) @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i32 -3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%12 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @assertStringsEqual to i32 (i8*, i8*, ...)*)(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
ret void
}