#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__ INT32_MIN;
int /*<<< orphan*/ assert(int);
char *mp_store_u32(char *, scalar_t__);
char *mp_store_u64(char *, scalar_t__);
char *mp_store_u8(char *, int);
char *mp_encode_int32(char *data, int64_t num) {
  assert(num < 0);
  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_int32>:
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   1040 <assert@plt>
mov    -0x18(%rbp),%rax
mov    0x2e73(%rip),%rcx
cmp    (%rcx),%rax
jl     119e <mp_encode_int32+0x5e>
mov    -0x10(%rbp),%rdi
mov    $0xd2,%esi
call   1050 <mp_store_u8@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <mp_store_u32@plt>
mov    %rax,-0x8(%rbp)
jmp    11c1 <mp_encode_int32+0x81>
mov    -0x10(%rbp),%rdi
mov    $0xd3,%esi
call   1050 <mp_store_u8@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <mp_store_u64@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mp_encode_int32>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
shr    $0x3f,%rdi
call   1040 <assert@plt>
mov    0x2e83(%rip),%rax
cmp    %rbx,(%rax)
jle    1181 <mp_encode_int32+0x41>
mov    %r14,%rdi
mov    $0xd3,%esi
call   1050 <mp_store_u8@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <mp_store_u64@plt>
mov    %r14,%rdi
mov    $0xd2,%esi
call   1050 <mp_store_u8@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <mp_store_u32@plt>

LLVM IR (-O0):
@INT32_MIN = global i64 0
define i8* @mp_encode_int32(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* @INT32_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 210)
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = load i64, i64* %5
%18 = call i8* @mp_store_u32(i8* %16, i64 %17)
store i8* %18, i8** %3
br label %25
19: ; preds = %2
%20 = load i8*, i8** %4
%21 = call i8* @mp_store_u8(i8* %20, i32 211)
store i8* %21, i8** %4
%22 = load i8*, i8** %4
%23 = load i64, i64* %5
%24 = call i8* @mp_store_u64(i8* %22, i64 %23)
store i8* %24, i8** %3
br label %25
25: ; preds = %19, %13
%26 = load i8*, i8** %3
ret i8* %26
}

LLVM IR (-O2):
@INT32_MIN = global i64 0
define i8* @mp_encode_int32(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* @INT32_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 210)
%10 = tail call i8* @mp_store_u32(i8* %9, i64 %1)
br label %14
11: ; preds = %2
%12 = tail call i8* @mp_store_u8(i8* %0, i32 211)
%13 = tail call i8* @mp_store_u64(i8* %12, i64 %1)
br label %14
14: ; preds = %11, %8
%15 = phi i8* [ %10, %8 ], [ %13, %11 ]
ret i8* %15
}