#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 */
unsigned int get32u(char const *, unsigned int const);
int /*<<< orphan*/ memcpy(char *, char const *, unsigned int const);
void OLE_parse_title_entry(const char *buffer, const unsigned int size,
                           const unsigned int offset, char *title) {
  if (offset + 8 > size) {
    return;
  }
  {
    const unsigned int count = get32u(buffer, offset + 4);
    const unsigned int offset_tmp = offset + 8;
    const char *src = (const char *)buffer;
    if (count <= 1 || count > size) {
      return;
    }
    if (offset_tmp + count > size) {
      return;
    }
    if (count < 1024) {
      memcpy(title, &src[offset_tmp], count);
      title[count] = '\0';
    } else {
      memcpy(title, &src[offset_tmp], 1023);
      title[1023] = '\0';
    }
  }
}


x86 assembly (clang, -O0):
<OLE_parse_title_entry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x8,%eax
cmp    -0xc(%rbp),%eax
jbe    114a <OLE_parse_title_entry+0x2a>
jmp    11f2 <OLE_parse_title_entry+0xd2>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
add    $0x4,%esi
call   1040 <get32u@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jbe    1183 <OLE_parse_title_entry+0x63>
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jbe    1188 <OLE_parse_title_entry+0x68>
jmp    11f2 <OLE_parse_title_entry+0xd2>
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jbe    119c <OLE_parse_title_entry+0x7c>
jmp    11f2 <OLE_parse_title_entry+0xd2>
cmpl   $0x400,-0x1c(%rbp)
jae    11cf <OLE_parse_title_entry+0xaf>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%eax
add    %rax,%rsi
mov    -0x1c(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
jmp    11f2 <OLE_parse_title_entry+0xd2>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%eax
add    %rax,%rsi
mov    $0x3ff,%edx
call   1030 <memcpy@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,0x3ff(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OLE_parse_title_entry>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0x8(%rdx),%ebx
cmp    %esi,%ebx
ja     118a <OLE_parse_title_entry+0x6a>
mov    %rcx,%r14
mov    %esi,%ebp
mov    %rdi,%r15
add    $0x4,%edx
mov    %edx,%esi
call   1040 <get32u@plt>
cmp    $0x2,%eax
jb     118a <OLE_parse_title_entry+0x6a>
mov    %eax,%r12d
cmp    %ebp,%eax
ja     118a <OLE_parse_title_entry+0x6a>
lea    (%r12,%rbx,1),%eax
cmp    %ebp,%eax
ja     118a <OLE_parse_title_entry+0x6a>
mov    %ebx,%eax
add    %rax,%r15
mov    %r14,%rdi
mov    %r15,%rsi
cmp    $0x3ff,%r12d
ja     1176 <OLE_parse_title_entry+0x56>
mov    %r12d,%edx
call   1030 <memcpy@plt>
mov    %r12d,%eax
jmp    1185 <OLE_parse_title_entry+0x65>
mov    $0x3ff,%edx
call   1030 <memcpy@plt>
mov    $0x3ff,%eax
movb   $0x0,(%r14,%rax,1)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @OLE_parse_title_entry(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%12 = load i32, i32* %7
%13 = add i32 %12, 8
%14 = load i32, i32* %6
%15 = icmp ugt i32 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %4
br label %63
17: ; preds = %4
%18 = load i8*, i8** %5
%19 = load i32, i32* %7
%20 = add i32 %19, 4
%21 = call i32 @get32u(i8* %18, i32 %20)
store i32 %21, i32* %9
%22 = load i32, i32* %7
%23 = add i32 %22, 8
store i32 %23, i32* %10
%24 = load i8*, i8** %5
store i8* %24, i8** %11
%25 = load i32, i32* %9
%26 = icmp ule i32 %25, 1
br i1 %26, label %31, label %27
27: ; preds = %17
%28 = load i32, i32* %9
%29 = load i32, i32* %6
%30 = icmp ugt i32 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %27, %17
br label %63
32: ; preds = %27
%33 = load i32, i32* %10
%34 = load i32, i32* %9
%35 = add i32 %33, %34
%36 = load i32, i32* %6
%37 = icmp ugt i32 %35, %36
br i1 %37, label %38, label %39
38: ; preds = %32
br label %63
39: ; preds = %32
%40 = load i32, i32* %9
%41 = icmp ult i32 %40, 1024
br i1 %41, label %42, label %54
42: ; preds = %39
%43 = load i8*, i8** %8
%44 = load i8*, i8** %11
%45 = load i32, i32* %10
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i32, i32* %9
%49 = call i32 @memcpy(i8* %43, i8* %47, i32 %48)
%50 = load i8*, i8** %8
%51 = load i32, i32* %9
%52 = zext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
store i8 0, i8* %53
br label %63
54: ; preds = %39
%55 = load i8*, i8** %8
%56 = load i8*, i8** %11
%57 = load i32, i32* %10
%58 = zext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = call i32 @memcpy(i8* %55, i8* %59, i32 1023)
%61 = load i8*, i8** %8
%62 = getelementptr inbounds i8, i8* %61, i64 1023
store i8 0, i8* %62
br label %63
63: ; preds = %16, %31, %38, %54, %42
ret void
}

LLVM IR (-O2):
define void @OLE_parse_title_entry(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = add i32 %2, 8
%6 = icmp ugt i32 %5, %1
br i1 %6, label %28, label %7
7: ; preds = %4
%8 = add i32 %2, 4
%9 = tail call i32 @get32u(i8* %0, i32 %8)
%10 = icmp ult i32 %9, 2
%11 = icmp ugt i32 %9, %1
%12 = or i1 %10, %11
%13 = add i32 %9, %5
%14 = icmp ugt i32 %13, %1
%15 = or i1 %12, %14
br i1 %15, label %28, label %16
16: ; preds = %7
%17 = icmp ult i32 %9, 1024
%18 = zext i32 %5 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
br i1 %17, label %20, label %23
20: ; preds = %16
%21 = tail call i32 @memcpy(i8* %3, i8* %19, i32 %9)
%22 = zext i32 %9 to i64
br label %25
23: ; preds = %16
%24 = tail call i32 @memcpy(i8* %3, i8* %19, i32 1023)
br label %25
25: ; preds = %20, %23
%26 = phi i64 [ 1023, %23 ], [ %22, %20 ]
%27 = getelementptr inbounds i8, i8* %3, i64 %26
store i8 0, i8* %27
br label %28
28: ; preds = %25, %7, %4
ret void
}