#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 */
typedef scalar_t__ uint8_t;
typedef int /*<<< orphan*/ int16_t;

/* Variables and functions */
scalar_t__ snprint_d16(char *, size_t, int /*<<< orphan*/);
uint8_t snprint_sd16(char *buffer, size_t buf_size, int16_t num) {
  if (num < 0) {
    buffer[0] = '-';
    buffer++;
    buf_size--;
    return (snprint_d16(buffer, buf_size, -num) + 1);
  } else {
    return (snprint_d16(buffer, buf_size, num));
  }
}


x86 assembly (clang, -O0):
<snprint_sd16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    116b <snprint_sd16+0x5b>
mov    -0x10(%rbp),%rax
movb   $0x2d,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %edx,%edx
sub    -0x1c(%rbp),%edx
call   1030 <snprint_d16@plt>
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    117f <snprint_sd16+0x6f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <snprint_d16@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<snprint_sd16>:
test   %edx,%edx
js     1119 <snprint_sd16+0x9>
jmp    1030 <snprint_d16@plt>
push   %rax
movb   $0x2d,(%rdi)
add    $0x1,%rdi
add    $0xffffffffffffffff,%rsi
neg    %edx
call   1030 <snprint_d16@plt>
add    $0x1,%rax
pop    %rcx
ret

LLVM IR (-O0):
define i64 @snprint_sd16(i8* %0, i64 %1, i32 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
%8 = load i32, i32* %7
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %3
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i64 0
store i8 45, i8* %12
%13 = load i8*, i8** %5
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %5
%15 = load i64, i64* %6
%16 = add i64 %15, -1
store i64 %16, i64* %6
%17 = load i8*, i8** %5
%18 = load i64, i64* %6
%19 = load i32, i32* %7
%20 = sub nsw i32 0, %19
%21 = call i64 @snprint_d16(i8* %17, i64 %18, i32 %20)
%22 = add nsw i64 %21, 1
store i64 %22, i64* %4
br label %28
23: ; preds = %3
%24 = load i8*, i8** %5
%25 = load i64, i64* %6
%26 = load i32, i32* %7
%27 = call i64 @snprint_d16(i8* %24, i64 %25, i32 %26)
store i64 %27, i64* %4
br label %28
28: ; preds = %23, %10
%29 = load i64, i64* %4
ret i64 %29
}

LLVM IR (-O2):
define i64 @snprint_sd16(i8* %0, i64 %1, i32 %2) {
%4 = icmp slt i32 %2, 0
br i1 %4, label %5, label %11
5: ; preds = %3
store i8 45, i8* %0
%6 = getelementptr inbounds i8, i8* %0, i64 1
%7 = add i64 %1, -1
%8 = sub nsw i32 0, %2
%9 = tail call i64 @snprint_d16(i8* %6, i64 %7, i32 %8)
%10 = add nsw i64 %9, 1
br label %13
11: ; preds = %3
%12 = tail call i64 @snprint_d16(i8* %0, i64 %1, i32 %2)
br label %13
13: ; preds = %11, %5
%14 = phi i64 [ %10, %5 ], [ %12, %11 ]
ret i64 %14
}