#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 toupper(int);
char *unicode_alloc_upper(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",
        187, "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",
      189);
  memset(unicode, 0, unicode_length);
  for (i = 0; i < strlen(string); i++) {
    unicode[(i * 2)] = toupper((int)string[i]);
  }
  return unicode;
}


x86 assembly (clang, -O0):
<unicode_alloc_upper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <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   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jae    11d1 <unicode_alloc_upper+0x71>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
lea    0xe6b(%rip),%rdx
mov    $0xbb,%ecx
lea    0xee3(%rip),%r8
call   1080 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x20(%rbp),%rdi
lea    0xe48(%rip),%rsi
mov    $0xbd,%edx
call   1070 <safe_malloc_internal@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
xor    %esi,%esi
call   1060 <memset@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
jae    1255 <unicode_alloc_upper+0xf5>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <toupper@plt>
mov    %al,%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    1201 <unicode_alloc_upper+0xa1>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unicode_alloc_upper>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
call   1050 <strlen@plt>
lea    (%rax,%rax,1),%r15
add    $0x2,%r15
cmp    %rax,%r15
jb     11fe <unicode_alloc_upper+0x9e>
lea    0xe9c(%rip),%rsi
mov    %r15,%rdi
mov    $0xbd,%edx
call   1070 <safe_malloc_internal@plt>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1060 <memset@plt>
movsbl (%r12),%edi
test   %edi,%edi
je     11ef <unicode_alloc_upper+0x8f>
call   1040 <toupper@plt>
mov    %al,(%r14)
mov    %r12,%rdi
call   1050 <strlen@plt>
cmp    $0x2,%rax
jb     11ef <unicode_alloc_upper+0x8f>
mov    $0x1,%ebx
nopl   0x0(%rax)
movsbl (%r12,%rbx,1),%edi
call   1040 <toupper@plt>
mov    %al,(%r14,%rbx,2)
add    $0x1,%rbx
mov    %r12,%rdi
call   1050 <strlen@plt>
cmp    %rax,%rbx
jb     11d0 <unicode_alloc_upper+0x70>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
lea    0xdf2(%rip),%rsi
lea    0xe0f(%rip),%rdx
lea    0xe8c(%rip),%r8
mov    $0xbb,%ecx
call   1080 <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_upper(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 187, 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 189)
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 = %40, %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 %43
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 = sext i8 %33 to i32
%35 = call signext i8 @toupper(i32 %34)
%36 = load i8*, i8** %4
%37 = load i64, i64* %3
%38 = mul i64 %37, 2
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 %35, i8* %39
br label %40
40: ; preds = %29
%41 = load i64, i64* %3
%42 = add i64 %41, 1
store i64 %42, i64* %3
br label %24
43: ; preds = %24
%44 = load i8*, i8** %4
ret i8* %44
}

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_upper(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 187, 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 189)
%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 %31, label %15
15: ; preds = %10
%16 = sext i8 %13 to i32
%17 = tail call signext i8 @toupper(i32 %16)
store i8 %17, i8* %11
%18 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%19 = icmp ugt i64 %18, 1
br i1 %19, label %20, label %31
20: ; preds = %15, %20
%21 = phi i64 [ %28, %20 ], [ 1, %15 ]
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = tail call signext i8 @toupper(i32 %24)
%26 = shl i64 %21, 1
%27 = getelementptr inbounds i8, i8* %11, i64 %26
store i8 %25, i8* %27
%28 = add nuw i64 %21, 1
%29 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%30 = icmp ult i64 %28, %29
br i1 %30, label %20, label %31
31: ; preds = %20, %15, %10
ret i8* %11
}