#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*/ Fatal_Error(char *);
char *Format_String(char *, int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
const char *Format_Len_String(const char *string, int len, int unicode) {
  char *data;
  const char *result;
  data = malloc(len + 1);
  if (!data)
    Fatal_Error("Out of memory!");
  memcpy(data, string, len);
  data[len] = '\0';
  result = Format_String(data, unicode);
  free(data);
  return result;
}


x86 assembly (clang, -O0):
<Format_Len_String>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1188 <Format_Len_String+0x38>
lea    0xe7d(%rip),%rdi
call   1040 <Fatal_Error@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1070 <Format_String@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Format_Len_String>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
lea    0x1(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    117b <Format_Len_String+0x2b>
lea    0xe8a(%rip),%rdi
call   1040 <Fatal_Error@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
movslq %ebp,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
mov    %r14d,%esi
call   1070 <Format_String@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Out of memory!\00"
define i8* @Format_Len_String(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %5
%10 = add nsw i32 %9, 1
%11 = call i8* @malloc(i32 %10)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = icmp ne i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %3
%15 = call i32 @Fatal_Error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %3
%17 = load i8*, i8** %7
%18 = load i8*, i8** %4
%19 = load i32, i32* %5
%20 = call i32 @memcpy(i8* %17, i8* %18, i32 %19)
%21 = load i8*, i8** %7
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 0, i8* %24
%25 = load i8*, i8** %7
%26 = load i32, i32* %6
%27 = call i8* @Format_String(i8* %25, i32 %26)
store i8* %27, i8** %8
%28 = load i8*, i8** %7
%29 = call i32 @free(i8* %28)
%30 = load i8*, i8** %8
ret i8* %30
}

LLVM IR (-O2):
@.str = [15 x i8] c"Out of memory!\00"
define i8* @Format_Len_String(i8* %0, i32 %1, i32 %2) {
%4 = add nsw i32 %1, 1
%5 = tail call i8* @malloc(i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @Fatal_Error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %3
%10 = tail call i32 @memcpy(i8* %5, i8* %0, i32 %1)
%11 = sext i32 %1 to i64
%12 = getelementptr inbounds i8, i8* %5, i64 %11
store i8 0, i8* %12
%13 = tail call i8* @Format_String(i8* %5, i32 %2)
%14 = tail call i32 @free(i8* %5)
ret i8* %13
}