#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_array(struct cbor_buf *buf, uint64_t size) {
  if (size <= 23) {
    return cbor_buf_append_byte(buf, (uint8_t)(0x80 | size));
  }
  if (size < UINT8_MAX) {
    return cbor_buf_append_2byte(buf, 0x98, (uint8_t)size);
  }
  if (size < UINT16_MAX) {
    return cbor_buf_append_3byte(buf, 0x99, (uint16_t)size);
  }
  if (size < UINT32_MAX) {
    return cbor_buf_append_5byte(buf, 0x9a, (uint32_t)size);
  }
  return cbor_buf_append_9byte(buf, 0x9b, size);
}


x86 assembly (clang, -O0):
<cbor_add_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x17,-0x14(%rbp)
jg     1183 <cbor_add_array+0x33>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
or     $0x80,%esi
call   1040 <cbor_buf_append_byte@plt>
mov    %eax,-0x4(%rbp)
jmp    1218 <cbor_add_array+0xc8>
mov    -0x14(%rbp),%eax
mov    0x2e4b(%rip),%rcx
cmp    (%rcx),%eax
jge    11ae <cbor_add_array+0x5e>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x98,%esi
call   1070 <cbor_buf_append_2byte@plt>
mov    %eax,-0x4(%rbp)
jmp    1218 <cbor_add_array+0xc8>
mov    -0x14(%rbp),%eax
mov    0x2e18(%rip),%rcx
cmp    (%rcx),%eax
jge    11d9 <cbor_add_array+0x89>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x99,%esi
call   1050 <cbor_buf_append_3byte@plt>
mov    %eax,-0x4(%rbp)
jmp    1218 <cbor_add_array+0xc8>
mov    -0x14(%rbp),%eax
mov    0x2e15(%rip),%rcx
cmp    (%rcx),%eax
jge    1204 <cbor_add_array+0xb4>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x9a,%esi
call   1030 <cbor_buf_append_5byte@plt>
mov    %eax,-0x4(%rbp)
jmp    1218 <cbor_add_array+0xc8>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x9b,%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_array>:
mov    %esi,%edx
cmp    $0x17,%esi
jg     1164 <cbor_add_array+0x14>
or     $0x80,%edx
mov    %edx,%esi
jmp    1040 <cbor_buf_append_byte@plt>
mov    0x2e6d(%rip),%rax
cmp    %edx,(%rax)
jle    1179 <cbor_add_array+0x29>
mov    $0x98,%esi
jmp    1070 <cbor_buf_append_2byte@plt>
mov    0x2e50(%rip),%rax
cmp    %edx,(%rax)
jle    118e <cbor_add_array+0x3e>
mov    $0x99,%esi
jmp    1050 <cbor_buf_append_3byte@plt>
mov    0x2e63(%rip),%rax
cmp    %edx,(%rax)
jle    11a3 <cbor_add_array+0x53>
mov    $0x9a,%esi
jmp    1030 <cbor_buf_append_5byte@plt>
mov    $0x9b,%esi
jmp    1060 <cbor_buf_append_9byte@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_array(%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 %13
8: ; preds = %2
%9 = load %struct.cbor_buf*, %struct.cbor_buf** %4
%10 = load i32, i32* %5
%11 = or i32 128, %10
%12 = call i32 @cbor_buf_append_byte(%struct.cbor_buf* %9, i32 %11)
store i32 %12, i32* %3
br label %41
13: ; preds = %2
%14 = load i32, i32* %5
%15 = load i32, i32* @UINT8_MAX
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load %struct.cbor_buf*, %struct.cbor_buf** %4
%19 = load i32, i32* %5
%20 = call i32 @cbor_buf_append_2byte(%struct.cbor_buf* %18, i32 152, i32 %19)
store i32 %20, i32* %3
br label %41
21: ; preds = %13
%22 = load i32, i32* %5
%23 = load i32, i32* @UINT16_MAX
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load %struct.cbor_buf*, %struct.cbor_buf** %4
%27 = load i32, i32* %5
%28 = call i32 @cbor_buf_append_3byte(%struct.cbor_buf* %26, i32 153, i32 %27)
store i32 %28, i32* %3
br label %41
29: ; preds = %21
%30 = load i32, i32* %5
%31 = load i32, i32* @UINT32_MAX
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load %struct.cbor_buf*, %struct.cbor_buf** %4
%35 = load i32, i32* %5
%36 = call i32 @cbor_buf_append_5byte(%struct.cbor_buf* %34, i32 154, i32 %35)
store i32 %36, i32* %3
br label %41
37: ; preds = %29
%38 = load %struct.cbor_buf*, %struct.cbor_buf** %4
%39 = load i32, i32* %5
%40 = call i32 @cbor_buf_append_9byte(%struct.cbor_buf* %38, i32 155, i32 %39)
store i32 %40, i32* %3
br label %41
41: ; preds = %37, %33, %25, %17, %8
%42 = load i32, i32* %3
ret i32 %42
}

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_array(%struct.cbor_buf* %0, i32 %1) {
%3 = icmp slt i32 %1, 24
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = or i32 %1, 128
%6 = tail call i32 @cbor_buf_append_byte(%struct.cbor_buf* %0, i32 %5)
br label %24
7: ; preds = %2
%8 = load i32, i32* @UINT8_MAX
%9 = icmp sgt i32 %8, %1
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @cbor_buf_append_2byte(%struct.cbor_buf* %0, i32 152, i32 %1)
br label %24
12: ; preds = %7
%13 = load i32, i32* @UINT16_MAX
%14 = icmp sgt i32 %13, %1
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @cbor_buf_append_3byte(%struct.cbor_buf* %0, i32 153, i32 %1)
br label %24
17: ; preds = %12
%18 = load i32, i32* @UINT32_MAX
%19 = icmp sgt i32 %18, %1
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @cbor_buf_append_5byte(%struct.cbor_buf* %0, i32 154, i32 %1)
br label %24
22: ; preds = %17
%23 = tail call i32 @cbor_buf_append_9byte(%struct.cbor_buf* %0, i32 155, i32 %1)
br label %24
24: ; preds = %22, %20, %15, %10, %4
%25 = phi i32 [ %6, %4 ], [ %11, %10 ], [ %16, %15 ], [ %21, %20 ], [ %23, %22 ]
ret i32 %25
}