#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;

/* Variables and functions */
uint8_t *SetLength(uint8_t *p_data, int i_length) {
  uint8_t *p = p_data;
  if (i_length < 128) {
    *p++ = i_length;
  } else if (i_length < 256) {
    *p++ = 0x80 | 0x1;
    *p++ = i_length;
  } else if (i_length < 65536) {
    *p++ = 0x80 | 0x2;
    *p++ = i_length >> 8;
    *p++ = i_length & 0xff;
  } else if (i_length < 16777216) {
    *p++ = 0x80 | 0x3;
    *p++ = i_length >> 16;
    *p++ = (i_length >> 8) & 0xff;
    *p++ = i_length & 0xff;
  } else {
    *p++ = 0x80 | 0x4;
    *p++ = i_length >> 24;
    *p++ = (i_length >> 16) & 0xff;
    *p++ = (i_length >> 8) & 0xff;
    *p++ = i_length & 0xff;
  }
  return p;
}


x86 assembly (clang, -O0):
<SetLength>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x80,-0xc(%rbp)
jge    1139 <SetLength+0x39>
mov    -0xc(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x18(%rbp)
mov    %ecx,(%rax)
jmp    12d0 <SetLength+0x1d0>
cmpl   $0x100,-0xc(%rbp)
jge    1174 <SetLength+0x74>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
movl   $0x81,(%rax)
mov    -0xc(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x18(%rbp)
mov    %ecx,(%rax)
jmp    12cb <SetLength+0x1cb>
cmpl   $0x10000,-0xc(%rbp)
jge    11cc <SetLength+0xcc>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
movl   $0x82,(%rax)
mov    -0xc(%rbp),%ecx
sar    $0x8,%ecx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x18(%rbp)
mov    %ecx,(%rax)
mov    -0xc(%rbp),%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x18(%rbp)
mov    %ecx,(%rax)
jmp    12c6 <SetLength+0x1c6>
cmpl   $0x1000000,-0xc(%rbp)
jge    1241 <SetLength+0x141>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
movl   $0x83,(%rax)
mov    -0xc(%rbp),%ecx
sar    $0x10,%ecx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x18(%rbp)
mov    %ecx,(%rax)
mov    -0xc(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x18(%rbp)
mov    %ecx,(%rax)
mov    -0xc(%rbp),%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x18(%rbp)
mov    %ecx,(%rax)
jmp    12c1 <SetLength+0x1c1>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
movl   $0x84,(%rax)
mov    -0xc(%rbp),%ecx
sar    $0x18,%ecx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x18(%rbp)
mov    %ecx,(%rax)
mov    -0xc(%rbp),%ecx
sar    $0x10,%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x18(%rbp)
mov    %ecx,(%rax)
mov    -0xc(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x18(%rbp)
mov    %ecx,(%rax)
mov    -0xc(%rbp),%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x18(%rbp)
mov    %ecx,(%rax)
jmp    12c6 <SetLength+0x1c6>
jmp    12cb <SetLength+0x1cb>
jmp    12d0 <SetLength+0x1d0>
mov    -0x18(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetLength>:
mov    %esi,%ecx
mov    %rdi,%rax
cmp    $0x7f,%esi
jg     1111 <SetLength+0x11>
mov    %ecx,(%rax)
add    $0x4,%rax
ret
cmp    $0xff,%ecx
ja     1127 <SetLength+0x27>
movl   $0x81,(%rax)
mov    %ecx,0x4(%rax)
add    $0x8,%rax
ret
cmp    $0xffff,%ecx
ja     1148 <SetLength+0x48>
movl   $0x82,(%rax)
mov    %ecx,%edx
shr    $0x8,%edx
mov    %edx,0x4(%rax)
movzbl %cl,%ecx
mov    %ecx,0x8(%rax)
add    $0xc,%rax
ret
cmp    $0xffffff,%ecx
ja     116f <SetLength+0x6f>
movl   $0x83,(%rax)
mov    %ecx,%edx
shr    $0x10,%edx
mov    %edx,0x4(%rax)
movzbl %ch,%edx
mov    %edx,0x8(%rax)
movzbl %cl,%ecx
mov    %ecx,0xc(%rax)
add    $0x10,%rax
ret
movl   $0x84,(%rax)
mov    %ecx,%edx
shr    $0x18,%edx
mov    %edx,0x4(%rax)
mov    %ecx,%edx
shr    $0x10,%edx
movzbl %dl,%edx
mov    %edx,0x8(%rax)
movzbl %ch,%edx
mov    %edx,0xc(%rax)
movzbl %cl,%ecx
mov    %ecx,0x10(%rax)
add    $0x14,%rax
ret

LLVM IR (-O0):
define i32* @SetLength(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32*
store i32* %0, i32** %3
store i32 %1, i32* %4
%6 = load i32*, i32** %3
store i32* %6, i32** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 128
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* %4
%11 = load i32*, i32** %5
%12 = getelementptr inbounds i32, i32* %11, i32 1
store i32* %12, i32** %5
store i32 %10, i32* %11
br label %79
13: ; preds = %2
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 256
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = load i32*, i32** %5
%18 = getelementptr inbounds i32, i32* %17, i32 1
store i32* %18, i32** %5
store i32 129, i32* %17
%19 = load i32, i32* %4
%20 = load i32*, i32** %5
%21 = getelementptr inbounds i32, i32* %20, i32 1
store i32* %21, i32** %5
store i32 %19, i32* %20
br label %78
22: ; preds = %13
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 65536
br i1 %24, label %25, label %36
25: ; preds = %22
%26 = load i32*, i32** %5
%27 = getelementptr inbounds i32, i32* %26, i32 1
store i32* %27, i32** %5
store i32 130, i32* %26
%28 = load i32, i32* %4
%29 = ashr i32 %28, 8
%30 = load i32*, i32** %5
%31 = getelementptr inbounds i32, i32* %30, i32 1
store i32* %31, i32** %5
store i32 %29, i32* %30
%32 = load i32, i32* %4
%33 = and i32 %32, 255
%34 = load i32*, i32** %5
%35 = getelementptr inbounds i32, i32* %34, i32 1
store i32* %35, i32** %5
store i32 %33, i32* %34
br label %77
36: ; preds = %22
%37 = load i32, i32* %4
%38 = icmp slt i32 %37, 16777216
br i1 %38, label %39, label %55
39: ; preds = %36
%40 = load i32*, i32** %5
%41 = getelementptr inbounds i32, i32* %40, i32 1
store i32* %41, i32** %5
store i32 131, i32* %40
%42 = load i32, i32* %4
%43 = ashr i32 %42, 16
%44 = load i32*, i32** %5
%45 = getelementptr inbounds i32, i32* %44, i32 1
store i32* %45, i32** %5
store i32 %43, i32* %44
%46 = load i32, i32* %4
%47 = ashr i32 %46, 8
%48 = and i32 %47, 255
%49 = load i32*, i32** %5
%50 = getelementptr inbounds i32, i32* %49, i32 1
store i32* %50, i32** %5
store i32 %48, i32* %49
%51 = load i32, i32* %4
%52 = and i32 %51, 255
%53 = load i32*, i32** %5
%54 = getelementptr inbounds i32, i32* %53, i32 1
store i32* %54, i32** %5
store i32 %52, i32* %53
br label %76
55: ; preds = %36
%56 = load i32*, i32** %5
%57 = getelementptr inbounds i32, i32* %56, i32 1
store i32* %57, i32** %5
store i32 132, i32* %56
%58 = load i32, i32* %4
%59 = ashr i32 %58, 24
%60 = load i32*, i32** %5
%61 = getelementptr inbounds i32, i32* %60, i32 1
store i32* %61, i32** %5
store i32 %59, i32* %60
%62 = load i32, i32* %4
%63 = ashr i32 %62, 16
%64 = and i32 %63, 255
%65 = load i32*, i32** %5
%66 = getelementptr inbounds i32, i32* %65, i32 1
store i32* %66, i32** %5
store i32 %64, i32* %65
%67 = load i32, i32* %4
%68 = ashr i32 %67, 8
%69 = and i32 %68, 255
%70 = load i32*, i32** %5
%71 = getelementptr inbounds i32, i32* %70, i32 1
store i32* %71, i32** %5
store i32 %69, i32* %70
%72 = load i32, i32* %4
%73 = and i32 %72, 255
%74 = load i32*, i32** %5
%75 = getelementptr inbounds i32, i32* %74, i32 1
store i32* %75, i32** %5
store i32 %73, i32* %74
br label %76
76: ; preds = %55, %39
br label %77
77: ; preds = %76, %25
br label %78
78: ; preds = %77, %16
br label %79
79: ; preds = %78, %9
%80 = load i32*, i32** %5
ret i32* %80
}

LLVM IR (-O2):
define i32* @SetLength(i32* writeonly %0, i32 %1) {
%3 = icmp slt i32 %1, 128
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = getelementptr inbounds i32, i32* %0, i64 1
store i32 %1, i32* %0
br label %41
6: ; preds = %2
%7 = icmp ult i32 %1, 256
br i1 %7, label %8, label %11
8: ; preds = %6
%9 = getelementptr inbounds i32, i32* %0, i64 1
store i32 129, i32* %0
%10 = getelementptr inbounds i32, i32* %0, i64 2
store i32 %1, i32* %9
br label %41
11: ; preds = %6
%12 = icmp ult i32 %1, 65536
br i1 %12, label %13, label %19
13: ; preds = %11
%14 = getelementptr inbounds i32, i32* %0, i64 1
store i32 130, i32* %0
%15 = lshr i32 %1, 8
%16 = getelementptr inbounds i32, i32* %0, i64 2
store i32 %15, i32* %14
%17 = and i32 %1, 255
%18 = getelementptr inbounds i32, i32* %0, i64 3
store i32 %17, i32* %16
br label %41
19: ; preds = %11
%20 = icmp ult i32 %1, 16777216
%21 = getelementptr inbounds i32, i32* %0, i64 1
br i1 %20, label %22, label %30
22: ; preds = %19
store i32 131, i32* %0
%23 = lshr i32 %1, 16
%24 = getelementptr inbounds i32, i32* %0, i64 2
store i32 %23, i32* %21
%25 = lshr i32 %1, 8
%26 = and i32 %25, 255
%27 = getelementptr inbounds i32, i32* %0, i64 3
store i32 %26, i32* %24
%28 = and i32 %1, 255
%29 = getelementptr inbounds i32, i32* %0, i64 4
store i32 %28, i32* %27
br label %41
30: ; preds = %19
store i32 132, i32* %0
%31 = lshr i32 %1, 24
%32 = getelementptr inbounds i32, i32* %0, i64 2
store i32 %31, i32* %21
%33 = lshr i32 %1, 16
%34 = and i32 %33, 255
%35 = getelementptr inbounds i32, i32* %0, i64 3
store i32 %34, i32* %32
%36 = lshr i32 %1, 8
%37 = and i32 %36, 255
%38 = getelementptr inbounds i32, i32* %0, i64 4
store i32 %37, i32* %35
%39 = and i32 %1, 255
%40 = getelementptr inbounds i32, i32* %0, i64 5
store i32 %39, i32* %38
br label %41
41: ; preds = %8, %22, %30, %13, %4
%42 = phi i32* [ %5, %4 ], [ %10, %8 ], [ %18, %13 ], [ %29, %22 ], [ %40, %30 ]
ret i32* %42
}