#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 read_unknown_size(int, unsigned char *);
void read_length_and_offset(char object_info, int offset, unsigned char *data,
                            int *sub_length, int *sub_offset) {
  *sub_length = object_info;
  *sub_offset = 1;
  if (object_info == 15) {
    char int_type = data[offset + 1] >> 4;
    char int_info = data[offset + 1] & 15;
    int int_length = 1 << int_info;
    *sub_offset = 2 + int_length;
    *sub_length = read_unknown_size(int_length, &data[offset + 2]);
  }
}


x86 assembly (clang, -O0):
<read_length_and_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
movsbl -0x1(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
movsbl -0x1(%rbp),%eax
cmp    $0xf,%eax
jne    11b5 <read_length_and_offset+0xa5>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
sar    $0x4,%eax
mov    %al,-0x21(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
and    $0xf,%eax
mov    %al,-0x22(%rbp)
movsbl -0x22(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%ecx
add    $0x2,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%eax
add    $0x2,%eax
cltq
add    %rax,%rsi
call   1030 <read_unknown_size@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_length_and_offset>:
push   %rbx
mov    %edi,(%rcx)
movl   $0x1,(%r8)
cmp    $0xf,%dil
jne    1149 <read_length_and_offset+0x39>
mov    %rcx,%rbx
movslq %esi,%rax
mov    0x1(%rax,%rdx,1),%cl
and    $0xf,%cl
mov    $0x1,%edi
shl    %cl,%edi
lea    0x2(%rdi),%ecx
mov    %ecx,(%r8)
lea    (%rax,%rdx,1),%rsi
add    $0x2,%rsi
call   1030 <read_unknown_size@plt>
mov    %eax,(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
define void @read_length_and_offset(i8 signext %0, i32 %1, i8* %2, i32* %3, i32* %4) {
%6 = alloca i8
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i8
%12 = alloca i8
%13 = alloca i32
store i8 %0, i8* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32* %3, i32** %9
store i32* %4, i32** %10
%14 = load i8, i8* %6
%15 = sext i8 %14 to i32
%16 = load i32*, i32** %9
store i32 %15, i32* %16
%17 = load i32*, i32** %10
store i32 1, i32* %17
%18 = load i8, i8* %6
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 15
br i1 %20, label %21, label %54
21: ; preds = %5
%22 = load i8*, i8** %8
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = ashr i32 %28, 4
%30 = trunc i32 %29 to i8
store i8 %30, i8* %11
%31 = load i8*, i8** %8
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = and i32 %37, 15
%39 = trunc i32 %38 to i8
store i8 %39, i8* %12
%40 = load i8, i8* %12
%41 = sext i8 %40 to i32
%42 = shl i32 1, %41
store i32 %42, i32* %13
%43 = load i32, i32* %13
%44 = add nsw i32 2, %43
%45 = load i32*, i32** %10
store i32 %44, i32* %45
%46 = load i32, i32* %13
%47 = load i8*, i8** %8
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 2
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %47, i64 %50
%52 = call i32 @read_unknown_size(i32 %46, i8* %51)
%53 = load i32*, i32** %9
store i32 %52, i32* %53
br label %54
54: ; preds = %21, %5
ret void
}

LLVM IR (-O2):
define void @read_length_and_offset(i8 signext %0, i32 %1, i8* %2, i32* nocapture writeonly %3, i32* nocapture writeonly %4) {
%6 = sext i8 %0 to i32
store i32 %6, i32* %3
store i32 1, i32* %4
%7 = icmp eq i8 %0, 15
br i1 %7, label %8, label %21
8: ; preds = %5
%9 = add nsw i32 %1, 1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %2, i64 %10
%12 = load i8, i8* %11
%13 = and i8 %12, 15
%14 = zext i8 %13 to i32
%15 = shl nuw nsw i32 1, %14
%16 = add nuw nsw i32 %15, 2
store i32 %16, i32* %4
%17 = add nsw i32 %1, 2
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %2, i64 %18
%20 = tail call i32 @read_unknown_size(i32 %15, i8* %19)
store i32 %20, i32* %3
br label %21
21: ; preds = %8, %5
ret void
}