#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*/ logMallocError();
size_t makeUtf8FromWchars(unsigned char const *, unsigned int, char *, size_t);
char *strdup(char *);
char *getUtf8FromWchars(const unsigned char *characters, unsigned int count,
                        size_t *length) {
  size_t size = (count * (((32) < 8) ? 1 : (((32) + 3) / 5))) + 1;
  char buffer[size];
  size_t len = makeUtf8FromWchars(characters, count, buffer, size);
  char *text = strdup(buffer);
  if (!text) {
    logMallocError();
  } else if (length) {
    *length = len;
  }
  return text;
}


x86 assembly (clang, -O0):
<getUtf8FromWchars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%ecx
mov    %ecx,%eax
shl    $0x3,%eax
sub    %ecx,%eax
add    $0x1,%eax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x48(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rcx
call   1030 <makeUtf8FromWchars@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,-0x38(%rbp)
call   1050 <strdup@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11b3 <getUtf8FromWchars+0x83>
mov    $0x0,%al
call   1040 <logMallocError@plt>
jmp    11ce <getUtf8FromWchars+0x9e>
cmpq   $0x0,-0x18(%rbp)
je     11c9 <getUtf8FromWchars+0x99>
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    11ce <getUtf8FromWchars+0x9e>
mov    -0x40(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getUtf8FromWchars>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
lea    0x0(,%rsi,8),%ecx
sub    %esi,%ecx
add    $0x1,%ecx
lea    0xf(%rcx),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdx
call   1030 <makeUtf8FromWchars@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1050 <strdup@plt>
mov    %rax,%rbx
test   %rax,%rax
je     117f <getUtf8FromWchars+0x4f>
test   %r14,%r14
je     1186 <getUtf8FromWchars+0x56>
mov    %r15,(%r14)
jmp    1186 <getUtf8FromWchars+0x56>
xor    %eax,%eax
call   1040 <logMallocError@plt>
mov    %rbx,%rax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @getUtf8FromWchars(i8* %0, i32 %1, i64* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i64* %2, i64** %6
%12 = load i32, i32* %5
%13 = mul i32 %12, 7
%14 = add i32 %13, 1
%15 = zext i32 %14 to i64
store i64 %15, i64* %7
%16 = load i64, i64* %7
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %8
%18 = alloca i8, i64 %16
store i64 %16, i64* %9
%19 = load i8*, i8** %4
%20 = load i32, i32* %5
%21 = load i64, i64* %7
%22 = call i64 @makeUtf8FromWchars(i8* %19, i32 %20, i8* %18, i64 %21)
store i64 %22, i64* %10
%23 = call i8* @strdup(i8* %18)
store i8* %23, i8** %11
%24 = load i8*, i8** %11
%25 = icmp ne i8* %24, null
br i1 %25, label %28, label %26
26: ; preds = %3
%27 = call i32 (...) @logMallocError()
br label %35
28: ; preds = %3
%29 = load i64*, i64** %6
%30 = icmp ne i64* %29, null
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i64, i64* %10
%33 = load i64*, i64** %6
store i64 %32, i64* %33
br label %34
34: ; preds = %31, %28
br label %35
35: ; preds = %34, %26
%36 = load i8*, i8** %11
%37 = load i8*, i8** %8
ret i8* %36
}

LLVM IR (-O2):
define noalias i8* @getUtf8FromWchars(i8* %0, i32 %1, i64* writeonly %2) {
%4 = mul i32 %1, 7
%5 = add i32 %4, 1
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = call i64 @makeUtf8FromWchars(i8* %0, i32 %1, i8* %7, i64 %6)
%9 = call i8* @strdup(i8* %7)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = call i32 (...) @logMallocError()
br label %16
13: ; preds = %3
%14 = icmp eq i64* %2, null
br i1 %14, label %16, label %15
15: ; preds = %13
store i64 %8, i64* %2
br label %16
16: ; preds = %13, %15, %11
ret i8* %9
}