#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 /*<<< orphan*/ uint8_t;
typedef int uint64_t;
typedef int /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ uint16_t;
struct cbor_buf {
  int dummy;
};

/* Variables and functions */
int UINT16_MAX;
int UINT32_MAX;
int UINT8_MAX;
int cbor_buf_append_2byte(struct cbor_buf *, int, int /*<<< orphan*/);
int cbor_buf_append_3byte(struct cbor_buf *, int, int /*<<< orphan*/);
int cbor_buf_append_5byte(struct cbor_buf *, int, int /*<<< orphan*/);
int cbor_buf_append_9byte(struct cbor_buf *, int, int);
int cbor_buf_append_byte(struct cbor_buf *, int /*<<< orphan*/);
bool cbor_add_uint64(struct cbor_buf *buf, uint64_t n) {
  if (n <= 23) {
    return cbor_buf_append_byte(buf, (uint8_t)n);
  }
  if (n <= UINT8_MAX) {
    return cbor_buf_append_2byte(buf, 0x18, (uint8_t)n);
  }
  if (n <= UINT16_MAX) {
    return cbor_buf_append_3byte(buf, 0x19, (uint16_t)n);
  }
  if (n <= UINT32_MAX) {
    return cbor_buf_append_5byte(buf, 0x1a, (uint32_t)n);
  }
  return cbor_buf_append_9byte(buf, 0x1b, n);
}


x86 assembly (clang, -O0):
<cbor_add_uint64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x17,-0x14(%rbp)
jg     117d <cbor_add_uint64+0x2d>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <cbor_buf_append_byte@plt>
mov    %eax,-0x4(%rbp)
jmp    1212 <cbor_add_uint64+0xc2>
mov    -0x14(%rbp),%eax
mov    0x2e51(%rip),%rcx
cmp    (%rcx),%eax
jg     11a8 <cbor_add_uint64+0x58>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x18,%esi
call   1070 <cbor_buf_append_2byte@plt>
mov    %eax,-0x4(%rbp)
jmp    1212 <cbor_add_uint64+0xc2>
mov    -0x14(%rbp),%eax
mov    0x2e1e(%rip),%rcx
cmp    (%rcx),%eax
jg     11d3 <cbor_add_uint64+0x83>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x19,%esi
call   1050 <cbor_buf_append_3byte@plt>
mov    %eax,-0x4(%rbp)
jmp    1212 <cbor_add_uint64+0xc2>
mov    -0x14(%rbp),%eax
mov    0x2e1b(%rip),%rcx
cmp    (%rcx),%eax
jg     11fe <cbor_add_uint64+0xae>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x1a,%esi
call   1030 <cbor_buf_append_5byte@plt>
mov    %eax,-0x4(%rbp)
jmp    1212 <cbor_add_uint64+0xc2>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x1b,%esi
call   1060 <cbor_buf_append_9byte@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cbor_add_uint64>:
mov    %esi,%edx
cmp    $0x17,%esi
jg     115e <cbor_add_uint64+0xe>
mov    %edx,%esi
jmp    1040 <cbor_buf_append_byte@plt>
mov    0x2e73(%rip),%rax
cmp    %edx,(%rax)
jge    1189 <cbor_add_uint64+0x39>
mov    0x2e60(%rip),%rax
cmp    %edx,(%rax)
jge    1193 <cbor_add_uint64+0x43>
mov    0x2e7d(%rip),%rax
cmp    %edx,(%rax)
jge    119d <cbor_add_uint64+0x4d>
mov    $0x1b,%esi
jmp    1060 <cbor_buf_append_9byte@plt>
mov    $0x18,%esi
jmp    1070 <cbor_buf_append_2byte@plt>
mov    $0x19,%esi
jmp    1050 <cbor_buf_append_3byte@plt>
mov    $0x1a,%esi
jmp    1030 <cbor_buf_append_5byte@plt>

LLVM IR (-O0):
%struct.cbor_buf = type { i32 }
@UINT8_MAX = global i32 0
@UINT16_MAX = global i32 0
@UINT32_MAX = global i32 0
define i32 @cbor_add_uint64(%struct.cbor_buf* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.cbor_buf*
%5 = alloca i32
store %struct.cbor_buf* %0, %struct.cbor_buf** %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
%7 = icmp sle i32 %6, 23
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load %struct.cbor_buf*, %struct.cbor_buf** %4
%10 = load i32, i32* %5
%11 = call i32 @cbor_buf_append_byte(%struct.cbor_buf* %9, i32 %10)
store i32 %11, i32* %3
br label %40
12: ; preds = %2
%13 = load i32, i32* %5
%14 = load i32, i32* @UINT8_MAX
%15 = icmp sle i32 %13, %14
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = load %struct.cbor_buf*, %struct.cbor_buf** %4
%18 = load i32, i32* %5
%19 = call i32 @cbor_buf_append_2byte(%struct.cbor_buf* %17, i32 24, i32 %18)
store i32 %19, i32* %3
br label %40
20: ; preds = %12
%21 = load i32, i32* %5
%22 = load i32, i32* @UINT16_MAX
%23 = icmp sle i32 %21, %22
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load %struct.cbor_buf*, %struct.cbor_buf** %4
%26 = load i32, i32* %5
%27 = call i32 @cbor_buf_append_3byte(%struct.cbor_buf* %25, i32 25, i32 %26)
store i32 %27, i32* %3
br label %40
28: ; preds = %20
%29 = load i32, i32* %5
%30 = load i32, i32* @UINT32_MAX
%31 = icmp sle i32 %29, %30
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = load %struct.cbor_buf*, %struct.cbor_buf** %4
%34 = load i32, i32* %5
%35 = call i32 @cbor_buf_append_5byte(%struct.cbor_buf* %33, i32 26, i32 %34)
store i32 %35, i32* %3
br label %40
36: ; preds = %28
%37 = load %struct.cbor_buf*, %struct.cbor_buf** %4
%38 = load i32, i32* %5
%39 = call i32 @cbor_buf_append_9byte(%struct.cbor_buf* %37, i32 27, i32 %38)
store i32 %39, i32* %3
br label %40
40: ; preds = %36, %32, %24, %16, %8
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
%struct.cbor_buf = type { i32 }
@UINT8_MAX = global i32 0
@UINT16_MAX = global i32 0
@UINT32_MAX = global i32 0
define i32 @cbor_add_uint64(%struct.cbor_buf* %0, i32 %1) {
%3 = icmp slt i32 %1, 24
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @cbor_buf_append_byte(%struct.cbor_buf* %0, i32 %1)
br label %23
6: ; preds = %2
%7 = load i32, i32* @UINT8_MAX
%8 = icmp slt i32 %7, %1
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i32 @cbor_buf_append_2byte(%struct.cbor_buf* %0, i32 24, i32 %1)
br label %23
11: ; preds = %6
%12 = load i32, i32* @UINT16_MAX
%13 = icmp slt i32 %12, %1
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = tail call i32 @cbor_buf_append_3byte(%struct.cbor_buf* %0, i32 25, i32 %1)
br label %23
16: ; preds = %11
%17 = load i32, i32* @UINT32_MAX
%18 = icmp slt i32 %17, %1
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = tail call i32 @cbor_buf_append_5byte(%struct.cbor_buf* %0, i32 26, i32 %1)
br label %23
21: ; preds = %16
%22 = tail call i32 @cbor_buf_append_9byte(%struct.cbor_buf* %0, i32 27, i32 %1)
br label %23
23: ; preds = %21, %19, %14, %9, %4
%24 = phi i32 [ %5, %4 ], [ %10, %9 ], [ %15, %14 ], [ %20, %19 ], [ %22, %21 ]
ret i32 %24
}