#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__ int64_t;

/* Variables and functions */
scalar_t__ INT16_MIN;
scalar_t__ INT32_MIN;
int /*<<< orphan*/ assert(int);
char *mp_store_u16(char *, scalar_t__);
char *mp_store_u32(char *, scalar_t__);
char *mp_store_u64(char *, scalar_t__);
char *mp_store_u8(char *, int);
char *mp_encode_int16(char *data, int64_t num) {
  assert(num < 0);
  if (num >= INT16_MIN) {
    data = mp_store_u8(data, 0xd1);
    return mp_store_u16(data, num);
  } else if (num >= INT32_MIN) {
    data = mp_store_u8(data, 0xd2);
    return mp_store_u32(data, num);
  } else {
    data = mp_store_u8(data, 0xd3);
    return mp_store_u64(data, num);
  }
}


x86 assembly (clang, -O0):
<mp_encode_int16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rax
mov    0x2e5b(%rip),%rcx
cmp    (%rcx),%rax
jl     11ae <mp_encode_int16+0x5e>
mov    -0x10(%rbp),%rdi
mov    $0xd1,%esi
call   1060 <mp_store_u8@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <mp_store_u16@plt>
mov    %rax,-0x8(%rbp)
jmp    120d <mp_encode_int16+0xbd>
mov    -0x18(%rbp),%rax
mov    0x2e27(%rip),%rcx
cmp    (%rcx),%rax
jl     11ea <mp_encode_int16+0x9a>
mov    -0x10(%rbp),%rdi
mov    $0xd2,%esi
call   1060 <mp_store_u8@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <mp_store_u32@plt>
mov    %rax,-0x8(%rbp)
jmp    120d <mp_encode_int16+0xbd>
mov    -0x10(%rbp),%rdi
mov    $0xd3,%esi
call   1060 <mp_store_u8@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <mp_store_u64@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mp_encode_int16>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
shr    $0x3f,%rdi
call   1050 <assert@plt>
mov    0x2e6b(%rip),%rax
cmp    %rbx,(%rax)
jle    119d <mp_encode_int16+0x4d>
mov    0x2e67(%rip),%rax
cmp    %rbx,(%rax)
jle    11bc <mp_encode_int16+0x6c>
mov    %r14,%rdi
mov    $0xd3,%esi
call   1060 <mp_store_u8@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <mp_store_u64@plt>
mov    %r14,%rdi
mov    $0xd1,%esi
call   1060 <mp_store_u8@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <mp_store_u16@plt>
mov    %r14,%rdi
mov    $0xd2,%esi
call   1060 <mp_store_u8@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <mp_store_u32@plt>

LLVM IR (-O0):
@INT16_MIN = global i64 0
@INT32_MIN = global i64 0
define i8* @mp_encode_int16(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
%6 = load i64, i64* %5
%7 = icmp slt i64 %6, 0
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i64, i64* %5
%11 = load i64, i64* @INT16_MIN
%12 = icmp sge i64 %10, %11
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i8* @mp_store_u8(i8* %14, i32 209)
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = load i64, i64* %5
%18 = call i8* @mp_store_u16(i8* %16, i64 %17)
store i8* %18, i8** %3
br label %35
19: ; preds = %2
%20 = load i64, i64* %5
%21 = load i64, i64* @INT32_MIN
%22 = icmp sge i64 %20, %21
br i1 %22, label %23, label %29
23: ; preds = %19
%24 = load i8*, i8** %4
%25 = call i8* @mp_store_u8(i8* %24, i32 210)
store i8* %25, i8** %4
%26 = load i8*, i8** %4
%27 = load i64, i64* %5
%28 = call i8* @mp_store_u32(i8* %26, i64 %27)
store i8* %28, i8** %3
br label %35
29: ; preds = %19
%30 = load i8*, i8** %4
%31 = call i8* @mp_store_u8(i8* %30, i32 211)
store i8* %31, i8** %4
%32 = load i8*, i8** %4
%33 = load i64, i64* %5
%34 = call i8* @mp_store_u64(i8* %32, i64 %33)
store i8* %34, i8** %3
br label %35
35: ; preds = %29, %23, %13
%36 = load i8*, i8** %3
ret i8* %36
}

LLVM IR (-O2):
@INT16_MIN = global i64 0
@INT32_MIN = global i64 0
define i8* @mp_encode_int16(i8* %0, i64 %1) {
%3 = lshr i64 %1, 63
%4 = trunc i64 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = load i64, i64* @INT16_MIN
%7 = icmp sgt i64 %6, %1
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = tail call i8* @mp_store_u8(i8* %0, i32 209)
%10 = tail call i8* @mp_store_u16(i8* %9, i64 %1)
br label %20
11: ; preds = %2
%12 = load i64, i64* @INT32_MIN
%13 = icmp sgt i64 %12, %1
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = tail call i8* @mp_store_u8(i8* %0, i32 210)
%16 = tail call i8* @mp_store_u32(i8* %15, i64 %1)
br label %20
17: ; preds = %11
%18 = tail call i8* @mp_store_u8(i8* %0, i32 211)
%19 = tail call i8* @mp_store_u64(i8* %18, i64 %1)
br label %20
20: ; preds = %17, %14, %8
%21 = phi i8* [ %10, %8 ], [ %16, %14 ], [ %19, %17 ]
ret i8* %21
}