#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
unsigned int TextLengthFromBytePacked(unsigned int bytePackedLength,
                                      unsigned int bitPerChar,
                                      unsigned int lastByteLength) {
  if (bytePackedLength > 0xFFFFFFFF / (8 / bitPerChar)) {
    fprintf(stderr, "TextLengthFromBytePacked(): text length > 2^32!\n");
    exit(1);
  }
  return (bytePackedLength - 1) * (8 / bitPerChar) + lastByteLength;
}


x86 assembly (clang, -O0):
<TextLengthFromBytePacked>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x8,%eax
xor    %edx,%edx
divl   -0x8(%rbp)
mov    %eax,%ecx
mov    $0xffffffff,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jbe    1178 <TextLengthFromBytePacked+0x58>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    $0x8,%eax
xor    %edx,%edx
divl   -0x8(%rbp)
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
imul   %ecx,%eax
add    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TextLengthFromBytePacked>:
mov    %edx,%ecx
mov    $0x8,%eax
xor    %edx,%edx
div    %esi
mov    %eax,%esi
mul    %edi
jo     113c <TextLengthFromBytePacked+0x1c>
add    $0xffffffff,%edi
imul   %edi,%esi
add    %ecx,%esi
mov    %esi,%eax
ret
push   %rax
mov    0x2e9c(%rip),%rax
mov    (%rax),%edi
lea    0xeb3(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [49 x i8] c"TextLengthFromBytePacked(): text length > 2^32!\0A\00"
define i32 @TextLengthFromBytePacked(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %4
%8 = load i32, i32* %5
%9 = udiv i32 8, %8
%10 = udiv i32 -1, %9
%11 = icmp ugt i32 %7, %10
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %3
%17 = load i32, i32* %4
%18 = sub i32 %17, 1
%19 = load i32, i32* %5
%20 = udiv i32 8, %19
%21 = mul i32 %18, %20
%22 = load i32, i32* %6
%23 = add i32 %21, %22
ret i32 %23
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [49 x i8] c"TextLengthFromBytePacked(): text length > 2^32!\0A\00"
define i32 @TextLengthFromBytePacked(i32 %0, i32 %1, i32 %2) {
%4 = udiv i32 8, %1
%5 = tail call { i32, i1 } @llvm.umul.with.overflow.i32(i32 %4, i32 %0)
%6 = extractvalue { i32, i1 } %5, 1
br i1 %6, label %7, label %11
7: ; preds = %3
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %3
%12 = add i32 %0, -1
%13 = mul i32 %4, %12
%14 = add i32 %13, %2
ret i32 %14
}