#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 */

/* Variables and functions */
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, unsigned int);
unsigned char *cbor_write_type_size_bytes(unsigned char *data,
                                          unsigned int size, unsigned int type,
                                          unsigned int type_size,
                                          const unsigned char *bytes) {
  type <<= 5;
  if (type_size < 24) {
    if (size < 1 + type_size) {
      return data;
    }
    *data++ = (unsigned char)(type | type_size);
    memcpy(data, bytes, type_size);
    return data + type_size;
  } else if (type_size < 256) {
    if (size < 2 + type_size) {
      return data;
    }
    *data++ = (unsigned char)(type | 24);
    *data++ = (unsigned char)type_size;
    memcpy(data, bytes, type_size);
    return data + type_size;
  } else if (type_size < 65536) {
    if (size < 3 + type_size) {
      return data;
    }
    *data++ = (unsigned char)(type | 25);
    *data++ = (unsigned char)(type_size >> 8);
    *data++ = (unsigned char)type_size;
    memcpy(data, bytes, type_size);
    return data + type_size;
  } else {
    if (size < 5 + type_size) {
      return data;
    }
    *data++ = (unsigned char)(type | 26);
    *data++ = (unsigned char)(type_size >> 24);
    *data++ = (unsigned char)(type_size >> 16);
    *data++ = (unsigned char)(type_size >> 8);
    *data++ = (unsigned char)type_size;
    memcpy(data, bytes, type_size);
    return data + type_size;
  }
}


x86 assembly (clang, -O0):
<cbor_write_type_size_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x18(%rbp),%eax
shl    $0x5,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x18,-0x1c(%rbp)
jae    1196 <cbor_write_type_size_bytes+0x86>
mov    -0x14(%rbp),%eax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jae    115a <cbor_write_type_size_bytes+0x4a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    135f <cbor_write_type_size_bytes+0x24f>
mov    -0x18(%rbp),%eax
or     -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    135f <cbor_write_type_size_bytes+0x24f>
cmpl   $0x100,-0x1c(%rbp)
jae    1213 <cbor_write_type_size_bytes+0x103>
mov    -0x14(%rbp),%eax
mov    -0x1c(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jae    11c1 <cbor_write_type_size_bytes+0xb1>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    135f <cbor_write_type_size_bytes+0x24f>
mov    -0x18(%rbp),%eax
or     $0x18,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    135f <cbor_write_type_size_bytes+0x24f>
cmpl   $0x10000,-0x1c(%rbp)
jae    12a9 <cbor_write_type_size_bytes+0x199>
mov    -0x14(%rbp),%eax
mov    -0x1c(%rbp),%ecx
add    $0x3,%ecx
cmp    %ecx,%eax
jae    123e <cbor_write_type_size_bytes+0x12e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    135f <cbor_write_type_size_bytes+0x24f>
mov    -0x18(%rbp),%eax
or     $0x19,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
shr    $0x8,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    135f <cbor_write_type_size_bytes+0x24f>
mov    -0x14(%rbp),%eax
mov    -0x1c(%rbp),%ecx
add    $0x5,%ecx
cmp    %ecx,%eax
jae    12c7 <cbor_write_type_size_bytes+0x1b7>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    135f <cbor_write_type_size_bytes+0x24f>
mov    -0x18(%rbp),%eax
or     $0x1a,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
shr    $0x18,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
shr    $0x10,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
shr    $0x8,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cbor_write_type_size_bytes>:
push   %rbp
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %rdi,%rbp
shl    $0x5,%edx
cmp    $0x17,%ecx
ja     1134 <cbor_write_type_size_bytes+0x24>
cmp    %esi,%ebx
jae    11b9 <cbor_write_type_size_bytes+0xa9>
or     %ebx,%edx
mov    $0x1,%ecx
mov    %rbp,%rax
jmp    11a2 <cbor_write_type_size_bytes+0x92>
cmp    $0xff,%ebx
ja     1154 <cbor_write_type_size_bytes+0x44>
lea    0x2(%rbx),%eax
cmp    %esi,%eax
ja     11b9 <cbor_write_type_size_bytes+0xa9>
or     $0x18,%dl
lea    0x1(%rbp),%rax
mov    %dl,0x0(%rbp)
mov    $0x2,%ecx
jmp    11a0 <cbor_write_type_size_bytes+0x90>
cmp    $0xffff,%ebx
ja     1177 <cbor_write_type_size_bytes+0x67>
lea    0x3(%rbx),%eax
cmp    %esi,%eax
ja     11b9 <cbor_write_type_size_bytes+0xa9>
or     $0x19,%dl
mov    %dl,0x0(%rbp)
lea    0x2(%rbp),%rax
mov    %bh,0x1(%rbp)
mov    $0x3,%ecx
jmp    11a0 <cbor_write_type_size_bytes+0x90>
lea    0x5(%rbx),%eax
cmp    %esi,%eax
ja     11b9 <cbor_write_type_size_bytes+0xa9>
or     $0x1a,%dl
mov    %dl,0x0(%rbp)
mov    %ebx,%eax
shr    $0x18,%eax
mov    %al,0x1(%rbp)
mov    %ebx,%eax
shr    $0x10,%eax
mov    %al,0x2(%rbp)
lea    0x4(%rbp),%rax
mov    %bh,0x3(%rbp)
mov    $0x5,%ecx
mov    %ebx,%edx
add    %rcx,%rbp
mov    %dl,(%rax)
mov    %rbp,%rdi
mov    %r8,%rsi
mov    %ebx,%edx
call   1030 <memcpy@plt>
mov    %ebx,%eax
add    %rax,%rbp
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i8* @cbor_write_type_size_bytes(i8* %0, i32 %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i8* %4, i8** %11
%12 = load i32, i32* %9
%13 = shl i32 %12, 5
store i32 %13, i32* %9
%14 = load i32, i32* %10
%15 = icmp ult i32 %14, 24
br i1 %15, label %16, label %38
16: ; preds = %5
%17 = load i32, i32* %8
%18 = load i32, i32* %10
%19 = add i32 1, %18
%20 = icmp ult i32 %17, %19
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = load i8*, i8** %7
store i8* %22, i8** %6
br label %139
23: ; preds = %16
%24 = load i32, i32* %9
%25 = load i32, i32* %10
%26 = or i32 %24, %25
%27 = trunc i32 %26 to i8
%28 = load i8*, i8** %7
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %7
store i8 %27, i8* %28
%30 = load i8*, i8** %7
%31 = load i8*, i8** %11
%32 = load i32, i32* %10
%33 = call i32 @memcpy(i8* %30, i8* %31, i32 %32)
%34 = load i8*, i8** %7
%35 = load i32, i32* %10
%36 = zext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8* %37, i8** %6
br label %139
38: ; preds = %5
%39 = load i32, i32* %10
%40 = icmp ult i32 %39, 256
br i1 %40, label %41, label %66
41: ; preds = %38
%42 = load i32, i32* %8
%43 = load i32, i32* %10
%44 = add i32 2, %43
%45 = icmp ult i32 %42, %44
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = load i8*, i8** %7
store i8* %47, i8** %6
br label %139
48: ; preds = %41
%49 = load i32, i32* %9
%50 = or i32 %49, 24
%51 = trunc i32 %50 to i8
%52 = load i8*, i8** %7
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %7
store i8 %51, i8* %52
%54 = load i32, i32* %10
%55 = trunc i32 %54 to i8
%56 = load i8*, i8** %7
%57 = getelementptr inbounds i8, i8* %56, i32 1
store i8* %57, i8** %7
store i8 %55, i8* %56
%58 = load i8*, i8** %7
%59 = load i8*, i8** %11
%60 = load i32, i32* %10
%61 = call i32 @memcpy(i8* %58, i8* %59, i32 %60)
%62 = load i8*, i8** %7
%63 = load i32, i32* %10
%64 = zext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
store i8* %65, i8** %6
br label %139
66: ; preds = %38
%67 = load i32, i32* %10
%68 = icmp ult i32 %67, 65536
br i1 %68, label %69, label %99
69: ; preds = %66
%70 = load i32, i32* %8
%71 = load i32, i32* %10
%72 = add i32 3, %71
%73 = icmp ult i32 %70, %72
br i1 %73, label %74, label %76
74: ; preds = %69
%75 = load i8*, i8** %7
store i8* %75, i8** %6
br label %139
76: ; preds = %69
%77 = load i32, i32* %9
%78 = or i32 %77, 25
%79 = trunc i32 %78 to i8
%80 = load i8*, i8** %7
%81 = getelementptr inbounds i8, i8* %80, i32 1
store i8* %81, i8** %7
store i8 %79, i8* %80
%82 = load i32, i32* %10
%83 = lshr i32 %82, 8
%84 = trunc i32 %83 to i8
%85 = load i8*, i8** %7
%86 = getelementptr inbounds i8, i8* %85, i32 1
store i8* %86, i8** %7
store i8 %84, i8* %85
%87 = load i32, i32* %10
%88 = trunc i32 %87 to i8
%89 = load i8*, i8** %7
%90 = getelementptr inbounds i8, i8* %89, i32 1
store i8* %90, i8** %7
store i8 %88, i8* %89
%91 = load i8*, i8** %7
%92 = load i8*, i8** %11
%93 = load i32, i32* %10
%94 = call i32 @memcpy(i8* %91, i8* %92, i32 %93)
%95 = load i8*, i8** %7
%96 = load i32, i32* %10
%97 = zext i32 %96 to i64
%98 = getelementptr inbounds i8, i8* %95, i64 %97
store i8* %98, i8** %6
br label %139
99: ; preds = %66
%100 = load i32, i32* %8
%101 = load i32, i32* %10
%102 = add i32 5, %101
%103 = icmp ult i32 %100, %102
br i1 %103, label %104, label %106
104: ; preds = %99
%105 = load i8*, i8** %7
store i8* %105, i8** %6
br label %139
106: ; preds = %99
%107 = load i32, i32* %9
%108 = or i32 %107, 26
%109 = trunc i32 %108 to i8
%110 = load i8*, i8** %7
%111 = getelementptr inbounds i8, i8* %110, i32 1
store i8* %111, i8** %7
store i8 %109, i8* %110
%112 = load i32, i32* %10
%113 = lshr i32 %112, 24
%114 = trunc i32 %113 to i8
%115 = load i8*, i8** %7
%116 = getelementptr inbounds i8, i8* %115, i32 1
store i8* %116, i8** %7
store i8 %114, i8* %115
%117 = load i32, i32* %10
%118 = lshr i32 %117, 16
%119 = trunc i32 %118 to i8
%120 = load i8*, i8** %7
%121 = getelementptr inbounds i8, i8* %120, i32 1
store i8* %121, i8** %7
store i8 %119, i8* %120
%122 = load i32, i32* %10
%123 = lshr i32 %122, 8
%124 = trunc i32 %123 to i8
%125 = load i8*, i8** %7
%126 = getelementptr inbounds i8, i8* %125, i32 1
store i8* %126, i8** %7
store i8 %124, i8* %125
%127 = load i32, i32* %10
%128 = trunc i32 %127 to i8
%129 = load i8*, i8** %7
%130 = getelementptr inbounds i8, i8* %129, i32 1
store i8* %130, i8** %7
store i8 %128, i8* %129
%131 = load i8*, i8** %7
%132 = load i8*, i8** %11
%133 = load i32, i32* %10
%134 = call i32 @memcpy(i8* %131, i8* %132, i32 %133)
%135 = load i8*, i8** %7
%136 = load i32, i32* %10
%137 = zext i32 %136 to i64
%138 = getelementptr inbounds i8, i8* %135, i64 %137
store i8* %138, i8** %6
br label %139
139: ; preds = %106, %104, %76, %74, %48, %46, %23, %21
%140 = load i8*, i8** %6
ret i8* %140
}

LLVM IR (-O2):
define i8* @cbor_write_type_size_bytes(i8* %0, i32 %1, i32 %2, i32 %3, i8* %4) {
%6 = shl i32 %2, 5
%7 = icmp ult i32 %3, 24
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = icmp ult i32 %3, %1
br i1 %9, label %10, label %58
10: ; preds = %8
%11 = or i32 %6, %3
br label %49
12: ; preds = %5
%13 = icmp ult i32 %3, 256
br i1 %13, label %14, label %21
14: ; preds = %12
%15 = add nuw nsw i32 %3, 2
%16 = icmp ugt i32 %15, %1
br i1 %16, label %58, label %17
17: ; preds = %14
%18 = trunc i32 %6 to i8
%19 = or i8 %18, 24
%20 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %19, i8* %0
br label %49
21: ; preds = %12
%22 = icmp ult i32 %3, 65536
br i1 %22, label %23, label %33
23: ; preds = %21
%24 = add nuw nsw i32 %3, 3
%25 = icmp ugt i32 %24, %1
br i1 %25, label %58, label %26
26: ; preds = %23
%27 = trunc i32 %6 to i8
%28 = or i8 %27, 25
%29 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %28, i8* %0
%30 = lshr i32 %3, 8
%31 = trunc i32 %30 to i8
%32 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %31, i8* %29
br label %49
33: ; preds = %21
%34 = add i32 %3, 5
%35 = icmp ugt i32 %34, %1
br i1 %35, label %58, label %36
36: ; preds = %33
%37 = trunc i32 %6 to i8
%38 = or i8 %37, 26
%39 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %38, i8* %0
%40 = lshr i32 %3, 24
%41 = trunc i32 %40 to i8
%42 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %41, i8* %39
%43 = lshr i32 %3, 16
%44 = trunc i32 %43 to i8
%45 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %44, i8* %42
%46 = lshr i32 %3, 8
%47 = trunc i32 %46 to i8
%48 = getelementptr inbounds i8, i8* %0, i64 4
store i8 %47, i8* %45
br label %49
49: ; preds = %10, %17, %26, %36
%50 = phi i32 [ %11, %10 ], [ %3, %17 ], [ %3, %26 ], [ %3, %36 ]
%51 = phi i64 [ 1, %10 ], [ 2, %17 ], [ 3, %26 ], [ 5, %36 ]
%52 = phi i8* [ %0, %10 ], [ %20, %17 ], [ %32, %26 ], [ %48, %36 ]
%53 = trunc i32 %50 to i8
%54 = getelementptr inbounds i8, i8* %0, i64 %51
store i8 %53, i8* %52
%55 = tail call i32 @memcpy(i8* %54, i8* %4, i32 %3)
%56 = zext i32 %3 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
br label %58
58: ; preds = %49, %33, %23, %14, %8
%59 = phi i8* [ %0, %8 ], [ %0, %14 ], [ %0, %23 ], [ %0, %33 ], [ %57, %49 ]
ret i8* %59
}