#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 *, short);
int /*<<< orphan*/ snprintf(char *, int, char *, short);
scalar_t__ strncmp(char *, char *, int);
void test_printf_h(short i) {
  char *buf = (char *)malloc(32);
  char buf2[32];
  skiboot_snprintf(buf, 32, 32, "%hd", i);
  snprintf(buf2, 32, "%hd", i);
  assert(0 == strncmp(buf, buf2, 32));
  free(buf);
}


x86 assembly (clang, -O0):
<test_printf_h>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    $0x20,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x20,%edx
lea    0xe73(%rip),%rcx
mov    %edx,%esi
movswl -0x2(%rbp),%r8d
call   1040 <skiboot_snprintf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x20,%esi
lea    0xe57(%rip),%rdx
movswl -0x2(%rbp),%ecx
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_h>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebp
mov    $0x20,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
lea    0xe80(%rip),%r14
mov    %rax,%rdi
mov    $0x20,%esi
mov    $0x20,%edx
mov    %r14,%rcx
mov    %ebp,%r8d
call   1040 <skiboot_snprintf@plt>
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x20,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1060 <snprintf@plt>
mov    %rbx,%rdi
mov    %r15,%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    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%hd\00"
define void @test_printf_h(i16 signext %0) {
%2 = alloca i16
%3 = alloca i8*
%4 = alloca [32 x i8]
store i16 %0, i16* %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 i16, i16* %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), i16 signext %8)
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%11 = load i16, i16* %2
%12 = call i32 @snprintf(i8* %10, i32 32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i16 signext %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"%hd\00"
define void @test_printf_h(i16 signext %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), i16 signext %0)
%7 = call i32 @snprintf(i8* %5, i32 32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i16 signext %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
}