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

/* Variables and functions */
scalar_t__ UINT32_MAX;
char *mp_store_u32(char *, scalar_t__);
char *mp_store_u64(char *, scalar_t__);
char *mp_store_u8(char *, int);
char *mp_encode_uint32(char *data, uint64_t num) {
  if (num <= UINT32_MAX) {
    data = mp_store_u8(data, 0xce);
    return mp_store_u32(data, num);
  } else {
    data = mp_store_u8(data, 0xcf);
    return mp_store_u64(data, num);
  }
}


x86 assembly (clang, -O0):
<mp_encode_uint32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2ead(%rip),%rcx
cmp    (%rcx),%rax
jg     117c <mp_encode_uint32+0x4c>
mov    -0x10(%rbp),%rdi
mov    $0xce,%esi
call   1040 <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    119f <mp_encode_uint32+0x6f>
mov    -0x10(%rbp),%rdi
mov    $0xcf,%esi
call   1040 <mp_store_u8@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <mp_store_u64@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mp_encode_uint32>:
push   %rbx
mov    %rsi,%rbx
mov    0x2ebd(%rip),%rax
cmp    %rsi,(%rax)
jge    1156 <mp_encode_uint32+0x26>
mov    $0xcf,%esi
call   1040 <mp_store_u8@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
pop    %rbx
jmp    1050 <mp_store_u64@plt>
mov    $0xce,%esi
call   1040 <mp_store_u8@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
pop    %rbx
jmp    1030 <mp_store_u32@plt>

LLVM IR (-O0):
@UINT32_MAX = global i64 0
define i8* @mp_encode_uint32(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 = load i64, i64* @UINT32_MAX
%8 = icmp sle i64 %6, %7
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = call i8* @mp_store_u8(i8* %10, i32 206)
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = load i64, i64* %5
%14 = call i8* @mp_store_u32(i8* %12, i64 %13)
store i8* %14, i8** %3
br label %21
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = call i8* @mp_store_u8(i8* %16, i32 207)
store i8* %17, i8** %4
%18 = load i8*, i8** %4
%19 = load i64, i64* %5
%20 = call i8* @mp_store_u64(i8* %18, i64 %19)
store i8* %20, i8** %3
br label %21
21: ; preds = %15, %9
%22 = load i8*, i8** %3
ret i8* %22
}

LLVM IR (-O2):
@UINT32_MAX = global i64 0
define i8* @mp_encode_uint32(i8* %0, i64 %1) {
%3 = load i64, i64* @UINT32_MAX
%4 = icmp slt i64 %3, %1
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i8* @mp_store_u8(i8* %0, i32 206)
%7 = tail call i8* @mp_store_u32(i8* %6, i64 %1)
br label %11
8: ; preds = %2
%9 = tail call i8* @mp_store_u8(i8* %0, i32 207)
%10 = tail call i8* @mp_store_u64(i8* %9, i64 %1)
br label %11
11: ; preds = %8, %5
%12 = phi i8* [ %7, %5 ], [ %10, %8 ]
ret i8* %12
}