#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 */
struct mp_buf {
  int dummy;
};

/* Variables and functions */
int ENOMEM;
int /*<<< orphan*/ mp_byte(struct mp_buf *, int);
int /*<<< orphan*/ mp_ensure_bytes(struct mp_buf *, int);
int /*<<< orphan*/ mp_u16(struct mp_buf *, int);
int /*<<< orphan*/ mp_u32(struct mp_buf *, int);
int mp_start_array(struct mp_buf *buf, int len) {
  if (len < 16) {
    if (!mp_ensure_bytes(buf, 1))
      return -ENOMEM;
    mp_byte(buf, 0x90 | len);
  } else if (len < 65536) {
    if (!mp_ensure_bytes(buf, 3))
      return -ENOMEM;
    mp_byte(buf, 0xDC);
    mp_u16(buf, len);
  } else {
    if (!mp_ensure_bytes(buf, 5))
      return -ENOMEM;
    mp_byte(buf, 0xDD);
    mp_u32(buf, len);
  }
  return 0;
}


x86 assembly (clang, -O0):
<mp_start_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jge    119a <mp_start_array+0x5a>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1040 <mp_ensure_bytes@plt>
cmp    $0x0,%eax
jne    1183 <mp_start_array+0x43>
xor    %eax,%eax
mov    0x2e67(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1240 <mp_start_array+0x100>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
or     $0x90,%esi
call   1050 <mp_byte@plt>
jmp    1239 <mp_start_array+0xf9>
cmpl   $0x10000,-0x14(%rbp)
jge    11f0 <mp_start_array+0xb0>
mov    -0x10(%rbp),%rdi
mov    $0x3,%esi
call   1040 <mp_ensure_bytes@plt>
cmp    $0x0,%eax
jne    11d1 <mp_start_array+0x91>
xor    %eax,%eax
mov    0x2e19(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1240 <mp_start_array+0x100>
mov    -0x10(%rbp),%rdi
mov    $0xdc,%esi
call   1050 <mp_byte@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <mp_u16@plt>
jmp    1234 <mp_start_array+0xf4>
mov    -0x10(%rbp),%rdi
mov    $0x5,%esi
call   1040 <mp_ensure_bytes@plt>
cmp    $0x0,%eax
jne    121a <mp_start_array+0xda>
xor    %eax,%eax
mov    0x2dd0(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1240 <mp_start_array+0x100>
mov    -0x10(%rbp),%rdi
mov    $0xdd,%esi
call   1050 <mp_byte@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <mp_u32@plt>
jmp    1239 <mp_start_array+0xf9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mp_start_array>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
cmp    $0xf,%esi
jg     116e <mp_start_array+0x2e>
mov    $0x1,%esi
call   1040 <mp_ensure_bytes@plt>
test   %eax,%eax
je     11c6 <mp_start_array+0x86>
or     $0x90,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <mp_byte@plt>
jmp    11c2 <mp_start_array+0x82>
cmp    $0xffff,%ebx
ja     119d <mp_start_array+0x5d>
mov    $0x3,%esi
call   1040 <mp_ensure_bytes@plt>
test   %eax,%eax
je     11c6 <mp_start_array+0x86>
mov    %r14,%rdi
mov    $0xdc,%esi
call   1050 <mp_byte@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <mp_u16@plt>
jmp    11c2 <mp_start_array+0x82>
mov    $0x5,%esi
call   1040 <mp_ensure_bytes@plt>
test   %eax,%eax
je     11c6 <mp_start_array+0x86>
mov    %r14,%rdi
mov    $0xdd,%esi
call   1050 <mp_byte@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <mp_u32@plt>
xor    %eax,%eax
jmp    11d1 <mp_start_array+0x91>
mov    0x2e13(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.mp_buf = type { i32 }
@ENOMEM = global i32 0
define i32 @mp_start_array(%struct.mp_buf* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.mp_buf*
%5 = alloca i32
store %struct.mp_buf* %0, %struct.mp_buf** %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
%7 = icmp slt i32 %6, 16
br i1 %7, label %8, label %20
8: ; preds = %2
%9 = load %struct.mp_buf*, %struct.mp_buf** %4
%10 = call i32 @mp_ensure_bytes(%struct.mp_buf* %9, i32 1)
%11 = icmp ne i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = load i32, i32* @ENOMEM
%14 = sub nsw i32 0, %13
store i32 %14, i32* %3
br label %51
15: ; preds = %8
%16 = load %struct.mp_buf*, %struct.mp_buf** %4
%17 = load i32, i32* %5
%18 = or i32 144, %17
%19 = call i32 @mp_byte(%struct.mp_buf* %16, i32 %18)
br label %50
20: ; preds = %2
%21 = load i32, i32* %5
%22 = icmp slt i32 %21, 65536
br i1 %22, label %23, label %36
23: ; preds = %20
%24 = load %struct.mp_buf*, %struct.mp_buf** %4
%25 = call i32 @mp_ensure_bytes(%struct.mp_buf* %24, i32 3)
%26 = icmp ne i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %23
%28 = load i32, i32* @ENOMEM
%29 = sub nsw i32 0, %28
store i32 %29, i32* %3
br label %51
30: ; preds = %23
%31 = load %struct.mp_buf*, %struct.mp_buf** %4
%32 = call i32 @mp_byte(%struct.mp_buf* %31, i32 220)
%33 = load %struct.mp_buf*, %struct.mp_buf** %4
%34 = load i32, i32* %5
%35 = call i32 @mp_u16(%struct.mp_buf* %33, i32 %34)
br label %49
36: ; preds = %20
%37 = load %struct.mp_buf*, %struct.mp_buf** %4
%38 = call i32 @mp_ensure_bytes(%struct.mp_buf* %37, i32 5)
%39 = icmp ne i32 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %36
%41 = load i32, i32* @ENOMEM
%42 = sub nsw i32 0, %41
store i32 %42, i32* %3
br label %51
43: ; preds = %36
%44 = load %struct.mp_buf*, %struct.mp_buf** %4
%45 = call i32 @mp_byte(%struct.mp_buf* %44, i32 221)
%46 = load %struct.mp_buf*, %struct.mp_buf** %4
%47 = load i32, i32* %5
%48 = call i32 @mp_u32(%struct.mp_buf* %46, i32 %47)
br label %49
49: ; preds = %43, %30
br label %50
50: ; preds = %49, %15
store i32 0, i32* %3
br label %51
51: ; preds = %50, %40, %27, %12
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
%struct.mp_buf = type { i32 }
@ENOMEM = global i32 0
define i32 @mp_start_array(%struct.mp_buf* %0, i32 %1) {
%3 = icmp slt i32 %1, 16
br i1 %3, label %4, label %13
4: ; preds = %2
%5 = tail call i32 @mp_ensure_bytes(%struct.mp_buf* %0, i32 1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = load i32, i32* @ENOMEM
%9 = sub nsw i32 0, %8
br label %33
10: ; preds = %4
%11 = or i32 %1, 144
%12 = tail call i32 @mp_byte(%struct.mp_buf* %0, i32 %11)
br label %33
13: ; preds = %2
%14 = icmp ult i32 %1, 65536
br i1 %14, label %15, label %24
15: ; preds = %13
%16 = tail call i32 @mp_ensure_bytes(%struct.mp_buf* %0, i32 3)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* @ENOMEM
%20 = sub nsw i32 0, %19
br label %33
21: ; preds = %15
%22 = tail call i32 @mp_byte(%struct.mp_buf* %0, i32 220)
%23 = tail call i32 @mp_u16(%struct.mp_buf* %0, i32 %1)
br label %33
24: ; preds = %13
%25 = tail call i32 @mp_ensure_bytes(%struct.mp_buf* %0, i32 5)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32, i32* @ENOMEM
%29 = sub nsw i32 0, %28
br label %33
30: ; preds = %24
%31 = tail call i32 @mp_byte(%struct.mp_buf* %0, i32 221)
%32 = tail call i32 @mp_u32(%struct.mp_buf* %0, i32 %1)
br label %33
33: ; preds = %10, %30, %21, %27, %18, %7
%34 = phi i32 [ %9, %7 ], [ %20, %18 ], [ %29, %27 ], [ 0, %21 ], [ 0, %30 ], [ 0, %10 ]
ret i32 %34
}