#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 */
char hex_to_dec(char);
int /*<<< orphan*/ memmove(char *, char *, scalar_t__);
char power(int, unsigned int);
scalar_t__ realloc(char *, scalar_t__);
scalar_t__ strlen(char *);
char *strstr(char *, char const *);
char *rewrite_unicode_to_ascii(char *str) {
  const char unicode_literal[] = "\\u00";
  if (strstr(str, unicode_literal)) {
    char *hit = strstr(str, unicode_literal);
    char val = 0;
    unsigned i;
    unsigned exp = 3;
    for (i = 2; i < 6; i++) {
      val += hex_to_dec(hit[i]) * power(16, exp);
      exp--;
    }
    hit[0] = val;
    memmove(hit + 1, hit + 6, strlen(hit + 6) + 1);
    str = (char *)realloc(str, strlen(str) + 1);
  }
  return str;
}


x86 assembly (clang, -O0):
<rewrite_unicode_to_ascii>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xe8e(%rip),%eax
mov    %eax,-0xd(%rbp)
mov    0xe89(%rip),%al
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0xd(%rbp),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     1275 <rewrite_unicode_to_ascii+0x115>
mov    -0x8(%rbp),%rdi
lea    -0xd(%rbp),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
movl   $0x3,-0x24(%rbp)
movl   $0x2,-0x20(%rbp)
cmpl   $0x6,-0x20(%rbp)
jae    120e <rewrite_unicode_to_ascii+0xae>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1050 <hex_to_dec@plt>
movsbl %al,%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%esi
mov    $0x10,%edi
call   1030 <power@plt>
mov    -0x28(%rbp),%ecx
movsbl %al,%eax
imul   %eax,%ecx
movsbl -0x19(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x19(%rbp)
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11b8 <rewrite_unicode_to_ascii+0x58>
mov    -0x19(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x6,%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1070 <memmove@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
call   1060 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rewrite_unicode_to_ascii>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe8f(%rip),%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     123d <rewrite_unicode_to_ascii+0xdd>
mov    %rax,%rbx
movsbl 0x2(%rax),%edi
call   1050 <hex_to_dec@plt>
mov    %eax,%ebp
mov    $0x10,%edi
mov    $0x3,%esi
call   1030 <power@plt>
mul    %bpl
mov    %eax,%ebp
movsbl 0x3(%rbx),%edi
call   1050 <hex_to_dec@plt>
mov    %eax,%r15d
mov    $0x10,%edi
mov    $0x2,%esi
call   1030 <power@plt>
mul    %r15b
mov    %eax,%r15d
add    %bpl,%r15b
movsbl 0x4(%rbx),%edi
call   1050 <hex_to_dec@plt>
mov    %eax,%ebp
mov    $0x10,%edi
mov    $0x1,%esi
call   1030 <power@plt>
mul    %bpl
mov    %eax,%ebp
add    %r15b,%bpl
movsbl 0x5(%rbx),%edi
call   1050 <hex_to_dec@plt>
mov    %eax,%r15d
mov    $0x10,%edi
xor    %esi,%esi
call   1030 <power@plt>
mul    %r15b
add    %bpl,%al
mov    %al,(%rbx)
lea    0x1(%rbx),%rbp
add    $0x6,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1070 <memmove@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rsi
mov    %r14,%rdi
call   1060 <realloc@plt>
mov    %rax,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.rewrite_unicode_to_ascii.unicode_literal = [5 x i8] c"\\u00\00"
define i8* @rewrite_unicode_to_ascii(i8* %0) {
%2 = alloca i8*
%3 = alloca [5 x i8]
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
%8 = bitcast [5 x i8]* %3 to i8*
%9 = load i8*, i8** %2
%10 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%11 = call i8* @strstr(i8* %9, i8* %10)
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %60
13: ; preds = %1
%14 = load i8*, i8** %2
%15 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%16 = call i8* @strstr(i8* %14, i8* %15)
store i8* %16, i8** %4
store i8 0, i8* %5
store i32 3, i32* %7
store i32 2, i32* %6
br label %17
17: ; preds = %38, %13
%18 = load i32, i32* %6
%19 = icmp ult i32 %18, 6
br i1 %19, label %20, label %41
20: ; preds = %17
%21 = load i8*, i8** %4
%22 = load i32, i32* %6
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = call signext i8 @hex_to_dec(i8 signext %25)
%27 = sext i8 %26 to i32
%28 = load i32, i32* %7
%29 = call signext i8 @power(i32 16, i32 %28)
%30 = sext i8 %29 to i32
%31 = mul nsw i32 %27, %30
%32 = load i8, i8* %5
%33 = sext i8 %32 to i32
%34 = add nsw i32 %33, %31
%35 = trunc i32 %34 to i8
store i8 %35, i8* %5
%36 = load i32, i32* %7
%37 = add i32 %36, -1
store i32 %37, i32* %7
br label %38
38: ; preds = %20
%39 = load i32, i32* %6
%40 = add i32 %39, 1
store i32 %40, i32* %6
br label %17
41: ; preds = %17
%42 = load i8, i8* %5
%43 = load i8*, i8** %4
%44 = getelementptr inbounds i8, i8* %43, i64 0
store i8 %42, i8* %44
%45 = load i8*, i8** %4
%46 = getelementptr inbounds i8, i8* %45, i64 1
%47 = load i8*, i8** %4
%48 = getelementptr inbounds i8, i8* %47, i64 6
%49 = load i8*, i8** %4
%50 = getelementptr inbounds i8, i8* %49, i64 6
%51 = call i64 @strlen(i8* %50)
%52 = add nsw i64 %51, 1
%53 = call i32 @memmove(i8* %46, i8* %48, i64 %52)
%54 = load i8*, i8** %2
%55 = load i8*, i8** %2
%56 = call i64 @strlen(i8* %55)
%57 = add nsw i64 %56, 1
%58 = call i64 @realloc(i8* %54, i64 %57)
%59 = inttoptr i64 %58 to i8*
store i8* %59, i8** %2
br label %60
60: ; preds = %41, %1
%61 = load i8*, i8** %2
ret i8* %61
}

LLVM IR (-O2):
@__const.rewrite_unicode_to_ascii.unicode_literal = [5 x i8] c"\\u00\00"
define i8* @rewrite_unicode_to_ascii(i8* %0) {
%2 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @__const.rewrite_unicode_to_ascii.unicode_literal, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %37, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %2, i64 2
%6 = load i8, i8* %5
%7 = tail call signext i8 @hex_to_dec(i8 signext %6)
%8 = tail call signext i8 @power(i32 16, i32 3)
%9 = mul i8 %8, %7
%10 = getelementptr inbounds i8, i8* %2, i64 3
%11 = load i8, i8* %10
%12 = tail call signext i8 @hex_to_dec(i8 signext %11)
%13 = tail call signext i8 @power(i32 16, i32 2)
%14 = mul i8 %13, %12
%15 = add i8 %14, %9
%16 = getelementptr inbounds i8, i8* %2, i64 4
%17 = load i8, i8* %16
%18 = tail call signext i8 @hex_to_dec(i8 signext %17)
%19 = tail call signext i8 @power(i32 16, i32 1)
%20 = mul i8 %19, %18
%21 = add i8 %20, %15
%22 = getelementptr inbounds i8, i8* %2, i64 5
%23 = load i8, i8* %22
%24 = tail call signext i8 @hex_to_dec(i8 signext %23)
%25 = tail call signext i8 @power(i32 16, i32 0)
%26 = mul i8 %25, %24
%27 = add i8 %26, %21
store i8 %27, i8* %2
%28 = getelementptr inbounds i8, i8* %2, i64 1
%29 = getelementptr inbounds i8, i8* %2, i64 6
%30 = tail call i64 @strlen(i8* %29)
%31 = add nsw i64 %30, 1
%32 = tail call i32 @memmove(i8* %28, i8* %29, i64 %31)
%33 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%34 = add nsw i64 %33, 1
%35 = tail call i64 @realloc(i8* %0, i64 %34)
%36 = inttoptr i64 %35 to i8*
br label %37
37: ; preds = %4, %1
%38 = phi i8* [ %36, %4 ], [ %0, %1 ]
ret i8* %38
}