#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ skiboot_snprintf(char *, int, int, char *, size_t);
int /*<<< orphan*/ snprintf(char *, int, char *, size_t);
scalar_t__ strncmp(char *, char *, int);
void test_printf_z(size_t i) {
  char *buf = (char *)malloc(32);
  char buf2[32];
  skiboot_snprintf(buf, 32, 32, "%zu", i);
  snprintf(buf2, 32, "%zu", i);
  assert(0 == strncmp(buf, buf2, 32));
  free(buf);
}


x86 assembly (clang, -O0):
<test_printf_z>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x20,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%r8
mov    $0x20,%edx
lea    0xe72(%rip),%rcx
mov    %edx,%esi
call   1040 <skiboot_snprintf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x20,%esi
lea    0xe57(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x20,%edx
call   1050 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_printf_z>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
mov    $0x20,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
lea    0xe7e(%rip),%r15
mov    %rax,%rdi
mov    $0x20,%esi
mov    $0x20,%edx
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <skiboot_snprintf@plt>
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x20,%esi
mov    %r15,%rdx
mov    %r14,%rcx
call   1060 <snprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x20,%edx
call   1050 <strncmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%zu\00"
define void @test_printf_z(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca [32 x i8]
store i64 %0, i64* %2
%5 = call i64 @malloc(i32 32)
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = load i64, i64* %2
%9 = call i32 @skiboot_snprintf(i8* %7, i32 32, i32 32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %8)
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%11 = load i64, i64* %2
%12 = call i32 @snprintf(i8* %10, i32 32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %11)
%13 = load i8*, i8** %3
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%15 = call i64 @strncmp(i8* %13, i8* %14, i32 32)
%16 = icmp eq i64 0, %15
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i8*, i8** %3
%20 = call i32 @free(i8* %19)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%zu\00"
define void @test_printf_z(i64 %0) {
%2 = alloca [32 x i8]
%3 = tail call i64 @malloc(i32 32)
%4 = inttoptr i64 %3 to i8*
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%6 = tail call i32 @skiboot_snprintf(i8* %4, i32 32, i32 32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %0)
%7 = call i32 @snprintf(i8* %5, i32 32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %0)
%8 = call i64 @strncmp(i8* %4, i8* %5, i32 32)
%9 = icmp eq i64 %8, 0
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = call i32 @free(i8* %4)
ret void
}