#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*/ fb_hCharToUTF8(char const *, int, char *, int *);
char *malloc(int);
char *hToUTF8(const char *src, int chars, char *dst, int *bytes) {
  if (chars > 0) {
    if (dst == 0) {
      dst = malloc(chars * 2);
      if (dst == 0)
        return 0;
    }
    fb_hCharToUTF8(src, chars, dst, bytes);
  } else
    *bytes = 0;
  return dst;
}


x86 assembly (clang, -O0):
<hToUTF8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1191 <hToUTF8+0x71>
cmpq   $0x0,-0x20(%rbp)
jne    1178 <hToUTF8+0x58>
mov    -0x14(%rbp),%edi
shl    $0x1,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1173 <hToUTF8+0x53>
movq   $0x0,-0x8(%rbp)
jmp    11a3 <hToUTF8+0x83>
jmp    1178 <hToUTF8+0x58>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1040 <fb_hCharToUTF8@plt>
jmp    119b <hToUTF8+0x7b>
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hToUTF8>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbx
test   %esi,%esi
jle    1161 <hToUTF8+0x41>
mov    %esi,%r15d
mov    %rdi,%r12
test   %rbx,%rbx
jne    114e <hToUTF8+0x2e>
lea    (%r15,%r15,1),%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     116a <hToUTF8+0x4a>
mov    %r12,%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1040 <fb_hCharToUTF8@plt>
jmp    116c <hToUTF8+0x4c>
movl   $0x0,(%r14)
jmp    116c <hToUTF8+0x4c>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @hToUTF8(i8* %0, i32 %1, i8* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32* %3, i32** %9
%10 = load i32, i32* %7
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %29
12: ; preds = %4
%13 = load i8*, i8** %8
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = load i32, i32* %7
%17 = mul nsw i32 %16, 2
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %8
%19 = load i8*, i8** %8
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %15
store i8* null, i8** %5
br label %33
22: ; preds = %15
br label %23
23: ; preds = %22, %12
%24 = load i8*, i8** %6
%25 = load i32, i32* %7
%26 = load i8*, i8** %8
%27 = load i32*, i32** %9
%28 = call i32 @fb_hCharToUTF8(i8* %24, i32 %25, i8* %26, i32* %27)
br label %31
29: ; preds = %4
%30 = load i32*, i32** %9
store i32 0, i32* %30
br label %31
31: ; preds = %29, %23
%32 = load i8*, i8** %8
store i8* %32, i8** %5
br label %33
33: ; preds = %31, %21
%34 = load i8*, i8** %5
ret i8* %34
}

LLVM IR (-O2):
define i8* @hToUTF8(i8* %0, i32 %1, i8* %2, i32* %3) {
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %15
6: ; preds = %4
%7 = icmp eq i8* %2, null
br i1 %7, label %8, label %12
8: ; preds = %6
%9 = shl nuw nsw i32 %1, 1
%10 = tail call i8* @malloc(i32 %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %16, label %12
12: ; preds = %8, %6
%13 = phi i8* [ %10, %8 ], [ %2, %6 ]
%14 = tail call i32 @fb_hCharToUTF8(i8* %0, i32 %1, i8* %13, i32* %3)
br label %16
15: ; preds = %4
store i32 0, i32* %3
br label %16
16: ; preds = %12, %15, %8
%17 = phi i8* [ null, %8 ], [ %13, %12 ], [ %2, %15 ]
ret i8* %17
}