#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 int uint8_t;
typedef int uint32_t;

/* Variables and functions */
size_t append_little_endian_uint32(int *, int);
size_t append_cell_hex_sub(uint8_t *dst, uint32_t arg) {
  uint32_t operand = 2 * arg;
  if (operand < 0x80) {
    dst[0] = 0x83;
    dst[1] = 0xc1;
    dst[2] = operand;
    return 3;
  }
  dst[0] = 0x81;
  dst[1] = 0xc1;
  return 2 + append_little_endian_uint32(dst + 2, operand);
}


x86 assembly (clang, -O0):
<append_cell_hex_sub>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x80,-0x18(%rbp)
jge    1161 <append_cell_hex_sub+0x51>
mov    -0x10(%rbp),%rax
movl   $0x83,(%rax)
mov    -0x10(%rbp),%rax
movl   $0xc1,0x4(%rax)
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
movq   $0x3,-0x8(%rbp)
jmp    118e <append_cell_hex_sub+0x7e>
mov    -0x10(%rbp),%rax
movl   $0x81,(%rax)
mov    -0x10(%rbp),%rax
movl   $0xc1,0x4(%rax)
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
mov    -0x18(%rbp),%esi
call   1030 <append_little_endian_uint32@plt>
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_cell_hex_sub>:
push   %rax
mov    %esi,%eax
lea    (%rax,%rax,1),%esi
cmp    $0x3f,%eax
jg     1132 <append_cell_hex_sub+0x22>
movabs $0xc100000083,%rax
mov    %rax,(%rdi)
mov    %esi,0x8(%rdi)
mov    $0x3,%eax
pop    %rcx
ret
movabs $0xc100000081,%rax
mov    %rax,(%rdi)
add    $0x8,%rdi
call   1030 <append_little_endian_uint32@plt>
add    $0x2,%rax
pop    %rcx
ret

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

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