#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);
char *software_uni2ext(char const *, unsigned int const);
void OLE_parse_uni_software_entry(const char *buffer, const unsigned int size,
                                  const unsigned int offset, const char **ext) {
  if (offset >= size - 8) {
    return;
  }
  {
    const unsigned int offset_soft = offset + 8;
    const unsigned int count = get32u(buffer, offset + 4);
    unsigned int count2;
    if (count == 0 || count > size / 2) {
      return;
    }
    count2 = 2 * count;
    if (count2 > size - offset_soft) {
      return;
    }
    *ext = software_uni2ext(&buffer[offset_soft], count);
  }
}


x86 assembly (clang, -O0):
<OLE_parse_uni_software_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
mov    -0xc(%rbp),%ecx
sub    $0x8,%ecx
cmp    %ecx,%eax
jb     114c <OLE_parse_uni_software_entry+0x2c>
jmp    11c2 <OLE_parse_uni_software_entry+0xa2>
mov    -0x10(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
add    $0x4,%esi
call   1040 <get32u@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1182 <OLE_parse_uni_software_entry+0x62>
mov    -0x20(%rbp),%eax
mov    -0xc(%rbp),%ecx
shr    $0x1,%ecx
cmp    %ecx,%eax
jbe    1187 <OLE_parse_uni_software_entry+0x67>
jmp    11c2 <OLE_parse_uni_software_entry+0xa2>
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
cmp    %ecx,%eax
jbe    11a6 <OLE_parse_uni_software_entry+0x86>
jmp    11c2 <OLE_parse_uni_software_entry+0xa2>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    %rax,%rdi
mov    -0x20(%rbp),%esi
call   1030 <software_uni2ext@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OLE_parse_uni_software_entry>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
lea    -0x8(%rbx),%eax
cmp    %edx,%eax
jbe    1170 <OLE_parse_uni_software_entry+0x50>
mov    %rcx,%r14
mov    %edx,%r12d
mov    %rdi,%r15
lea    0x4(%r12),%esi
call   1040 <get32u@plt>
mov    %ebx,%ecx
shr    %ecx
lea    -0x1(%rax),%edx
cmp    %ecx,%edx
jae    1170 <OLE_parse_uni_software_entry+0x50>
add    $0x8,%r12d
lea    (%rax,%rax,1),%ecx
sub    %r12d,%ebx
cmp    %ebx,%ecx
ja     1170 <OLE_parse_uni_software_entry+0x50>
mov    %r12d,%ecx
add    %rcx,%r15
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <software_uni2ext@plt>
mov    %rax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @OLE_parse_uni_software_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 i32
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 = load i32, i32* %6
%14 = sub i32 %13, 8
%15 = icmp uge i32 %12, %14
br i1 %15, label %16, label %17
16: ; preds = %4
br label %49
17: ; preds = %4
%18 = load i32, i32* %7
%19 = add i32 %18, 8
store i32 %19, i32* %9
%20 = load i8*, i8** %5
%21 = load i32, i32* %7
%22 = add i32 %21, 4
%23 = call i32 @get32u(i8* %20, i32 %22)
store i32 %23, i32* %10
%24 = load i32, i32* %10
%25 = icmp eq i32 %24, 0
br i1 %25, label %31, label %26
26: ; preds = %17
%27 = load i32, i32* %10
%28 = load i32, i32* %6
%29 = udiv i32 %28, 2
%30 = icmp ugt i32 %27, %29
br i1 %30, label %31, label %32
31: ; preds = %26, %17
br label %49
32: ; preds = %26
%33 = load i32, i32* %10
%34 = mul i32 2, %33
store i32 %34, i32* %11
%35 = load i32, i32* %11
%36 = load i32, i32* %6
%37 = load i32, i32* %9
%38 = sub i32 %36, %37
%39 = icmp ugt i32 %35, %38
br i1 %39, label %40, label %41
40: ; preds = %32
br label %49
41: ; preds = %32
%42 = load i8*, i8** %5
%43 = load i32, i32* %9
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i32, i32* %10
%47 = call i8* @software_uni2ext(i8* %45, i32 %46)
%48 = load i8**, i8*** %8
store i8* %47, i8** %48
br label %49
49: ; preds = %41, %40, %31, %16
ret void
}

LLVM IR (-O2):
define void @OLE_parse_uni_software_entry(i8* %0, i32 %1, i32 %2, i8** nocapture writeonly %3) {
%5 = add i32 %1, -8
%6 = icmp ugt i32 %5, %2
br i1 %6, label %7, label %22
7: ; preds = %4
%8 = add i32 %2, 8
%9 = add i32 %2, 4
%10 = tail call i32 @get32u(i8* %0, i32 %9)
%11 = lshr i32 %1, 1
%12 = add i32 %10, -1
%13 = icmp ult i32 %12, %11
br i1 %13, label %14, label %22
14: ; preds = %7
%15 = shl i32 %10, 1
%16 = sub i32 %1, %8
%17 = icmp ugt i32 %15, %16
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = zext i32 %8 to i64
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = tail call i8* @software_uni2ext(i8* %20, i32 %10)
store i8* %21, i8** %3
br label %22
22: ; preds = %18, %7, %14, %4
ret void
}