#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*/ abort();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, size_t);
char *safe_malloc_internal(size_t, char *, int);
int /*<<< orphan*/ stderr;
size_t strlen(char const *);
char *unicode_alloc(const char *string) {
  size_t i;
  char *unicode;
  size_t unicode_length = (strlen(string) + 1) * 2;
  if (unicode_length < strlen(string)) {
    fprintf(
        stderr, "Unrecoverable error in %s(%d): %s\n\n",
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/iagox86/nbtool/refs/heads/master/memory.c",
        167, "Overflow.");
    abort();
  };
  unicode = safe_malloc_internal(
      unicode_length,
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/iagox86/nbtool/refs/heads/master/memory.c",
      169);
  memset(unicode, 0, unicode_length);
  for (i = 0; i < strlen(string); i++) {
    unicode[(i * 2)] = string[i];
  }
  return unicode;
}


x86 assembly (clang, -O0):
<unicode_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
shl    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jae    11c1 <unicode_alloc+0x71>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
lea    0xe7b(%rip),%rdx
mov    $0xa7,%ecx
lea    0xef3(%rip),%r8
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x20(%rbp),%rdi
lea    0xe58(%rip),%rsi
mov    $0xa9,%edx
call   1060 <safe_malloc_internal@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
xor    %esi,%esi
call   1050 <memset@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
jae    123d <unicode_alloc+0xed>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
shl    $0x1,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11f1 <unicode_alloc+0xa1>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unicode_alloc>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
call   1040 <strlen@plt>
lea    (%rax,%rax,1),%r15
add    $0x2,%r15
cmp    %rax,%r15
jb     11d9 <unicode_alloc+0x89>
lea    0xeb0(%rip),%rsi
mov    %r15,%rdi
mov    $0xa9,%edx
call   1060 <safe_malloc_internal@plt>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1050 <memset@plt>
mov    (%r12),%al
test   %al,%al
je     11ca <unicode_alloc+0x7a>
mov    %al,(%r14)
mov    %r12,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%rax
jb     11ca <unicode_alloc+0x7a>
mov    $0x1,%ebx
nop
movzbl (%r12,%rbx,1),%eax
mov    %al,(%r14,%rbx,2)
add    $0x1,%rbx
mov    %r12,%rdi
call   1040 <strlen@plt>
cmp    %rax,%rbx
jb     11b0 <unicode_alloc+0x60>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
lea    0xe34(%rip),%rdx
lea    0xeb1(%rip),%r8
mov    $0xa7,%ecx
call   1070 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"Unrecoverable error in %s(%d): %s\0A\0A\00"
@.str.1 = [132 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/iagox86/nbtool/refs/heads/master/memory.c\00"
@.str.2 = [10 x i8] c"Overflow.\00"
define i8* @unicode_alloc(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
%8 = add i64 %7, 1
%9 = mul i64 %8, 2
store i64 %9, i64* %5
%10 = load i64, i64* %5
%11 = load i8*, i8** %2
%12 = call i64 @strlen(i8* %11)
%13 = icmp ult i64 %10, %12
br i1 %13, label %14, label %18
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.1, i64 0, i64 0), i32 167, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 (...) @abort()
unreachable
18: ; preds = %1
%19 = load i64, i64* %5
%20 = call i8* @safe_malloc_internal(i64 %19, i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.1, i64 0, i64 0), i32 169)
store i8* %20, i8** %4
%21 = load i8*, i8** %4
%22 = load i64, i64* %5
%23 = call i32 @memset(i8* %21, i32 0, i64 %22)
store i64 0, i64* %3
br label %24
24: ; preds = %38, %18
%25 = load i64, i64* %3
%26 = load i8*, i8** %2
%27 = call i64 @strlen(i8* %26)
%28 = icmp ult i64 %25, %27
br i1 %28, label %29, label %41
29: ; preds = %24
%30 = load i8*, i8** %2
%31 = load i64, i64* %3
%32 = getelementptr inbounds i8, i8* %30, i64 %31
%33 = load i8, i8* %32
%34 = load i8*, i8** %4
%35 = load i64, i64* %3
%36 = mul i64 %35, 2
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 %33, i8* %37
br label %38
38: ; preds = %29
%39 = load i64, i64* %3
%40 = add i64 %39, 1
store i64 %40, i64* %3
br label %24
41: ; preds = %24
%42 = load i8*, i8** %4
ret i8* %42
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"Unrecoverable error in %s(%d): %s\0A\0A\00"
@.str.1 = [132 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/iagox86/nbtool/refs/heads/master/memory.c\00"
@.str.2 = [10 x i8] c"Overflow.\00"
define i8* @unicode_alloc(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = shl i64 %2, 1
%4 = add i64 %3, 2
%5 = icmp ult i64 %4, %2
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.1, i64 0, i64 0), i32 167, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 (...) @abort()
unreachable
10: ; preds = %1
%11 = tail call i8* @safe_malloc_internal(i64 %4, i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.1, i64 0, i64 0), i32 169)
%12 = tail call i32 @memset(i8* %11, i32 0, i64 %4)
%13 = load i8, i8* %0
%14 = icmp eq i8 %13, 0
br i1 %14, label %27, label %15
15: ; preds = %10
store i8 %13, i8* %11
%16 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%17 = icmp ugt i64 %16, 1
br i1 %17, label %18, label %27
18: ; preds = %15, %18
%19 = phi i64 [ %24, %18 ], [ 1, %15 ]
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = load i8, i8* %20
%22 = shl i64 %19, 1
%23 = getelementptr inbounds i8, i8* %11, i64 %22
store i8 %21, i8* %23
%24 = add nuw i64 %19, 1
%25 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%26 = icmp ult i64 %24, %25
br i1 %26, label %18, label %27
27: ; preds = %18, %15, %10
ret i8* %11
}