#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 */
typedef int wchar_t;

/* Variables and functions */
int *malloc(int);
int /*<<< orphan*/ swprintf(int *, int, char *, int);
scalar_t__ wcschr(int const *, int);
int wcslen(int const *);
wchar_t *_fatlegalize(const wchar_t *path, const wchar_t *illegal) {
  wchar_t *dst, *dscan, *scan;
  dst = malloc(wcslen(path) * sizeof(wchar_t) * 4);
  dscan = dst;
  for (scan = (wchar_t *)path; *scan; scan++)
    if (wcschr(illegal, *scan) || *scan < 32) {
      *dscan++ = L'[';
      swprintf(dscan, 4, L"%X", *scan);
      dscan += wcslen(dscan);
      *dscan++ = L']';
    } else {
      *dscan++ = *scan;
    }
  *dscan = '\0';
  return dst;
}


x86 assembly (clang, -O0):
<_fatlegalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <wcslen@plt>
cltq
shl    $0x2,%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpl   $0x0,(%rax)
je     1245 <_fatlegalize+0x105>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
call   1060 <wcschr@plt>
cmp    $0x0,%rax
jne    11b1 <_fatlegalize+0x71>
mov    -0x28(%rbp),%rax
cmpl   $0x20,(%rax)
jge    1218 <_fatlegalize+0xd8>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x20(%rbp)
movl   $0x5b,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
mov    $0x4,%esi
lea    0xe24(%rip),%rdx
call   1040 <swprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <wcslen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x20(%rbp)
movl   $0x5d,(%rax)
jmp    122f <_fatlegalize+0xef>
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x20(%rbp)
mov    %ecx,(%rax)
jmp    1234 <_fatlegalize+0xf4>
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
jmp    117e <_fatlegalize+0x3e>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_fatlegalize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <wcslen@plt>
shl    $0x4,%eax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    (%rbx),%esi
mov    %rax,%rbp
test   %esi,%esi
je     11dc <_fatlegalize+0x9c>
lea    0xe8d(%rip),%r12
mov    %r15,%rbp
jmp    11c3 <_fatlegalize+0x83>
nopl   0x0(%rax,%rax,1)
lea    0x4(%rbp),%r13
movl   $0x5b,0x0(%rbp)
mov    (%rbx),%ecx
mov    %r13,%rdi
mov    $0x4,%esi
mov    %r12,%rdx
call   1040 <swprintf@plt>
mov    %r13,%rdi
call   1030 <wcslen@plt>
cltq
movl   $0x5d,0x4(%rbp,%rax,4)
lea    0x4(%rbp,%rax,4),%rbp
add    $0x4,%rbp
mov    0x4(%rbx),%esi
add    $0x4,%rbx
test   %esi,%esi
je     11dc <_fatlegalize+0x9c>
mov    %r14,%rdi
call   1060 <wcschr@plt>
test   %rax,%rax
jne    1180 <_fatlegalize+0x40>
mov    (%rbx),%eax
cmp    $0x1f,%eax
jle    1180 <_fatlegalize+0x40>
mov    %eax,0x0(%rbp)
jmp    11b4 <_fatlegalize+0x74>
movl   $0x0,0x0(%rbp)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i32] [i32 37, i32 88, i32 0]
define i32* @_fatlegalize(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
store i32* %0, i32** %3
store i32* %1, i32** %4
%8 = load i32*, i32** %3
%9 = call i32 @wcslen(i32* %8)
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 4
%12 = mul i64 %11, 4
%13 = trunc i64 %12 to i32
%14 = call i32* @malloc(i32 %13)
store i32* %14, i32** %5
%15 = load i32*, i32** %5
store i32* %15, i32** %6
%16 = load i32*, i32** %3
store i32* %16, i32** %7
br label %17
17: ; preds = %51, %2
%18 = load i32*, i32** %7
%19 = load i32, i32* %18
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %54
21: ; preds = %17
%22 = load i32*, i32** %4
%23 = load i32*, i32** %7
%24 = load i32, i32* %23
%25 = call i64 @wcschr(i32* %22, i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %21
%28 = load i32*, i32** %7
%29 = load i32, i32* %28
%30 = icmp slt i32 %29, 32
br i1 %30, label %31, label %45
31: ; preds = %27, %21
%32 = load i32*, i32** %6
%33 = getelementptr inbounds i32, i32* %32, i32 1
store i32* %33, i32** %6
store i32 91, i32* %32
%34 = load i32*, i32** %6
%35 = load i32*, i32** %7
%36 = load i32, i32* %35
%37 = call i32 @swprintf(i32* %34, i32 4, i8* bitcast ([3 x i32]* @.str to i8*), i32 %36)
%38 = load i32*, i32** %6
%39 = call i32 @wcslen(i32* %38)
%40 = load i32*, i32** %6
%41 = sext i32 %39 to i64
%42 = getelementptr inbounds i32, i32* %40, i64 %41
store i32* %42, i32** %6
%43 = load i32*, i32** %6
%44 = getelementptr inbounds i32, i32* %43, i32 1
store i32* %44, i32** %6
store i32 93, i32* %43
br label %50
45: ; preds = %27
%46 = load i32*, i32** %7
%47 = load i32, i32* %46
%48 = load i32*, i32** %6
%49 = getelementptr inbounds i32, i32* %48, i32 1
store i32* %49, i32** %6
store i32 %47, i32* %48
br label %50
50: ; preds = %45, %31
br label %51
51: ; preds = %50
%52 = load i32*, i32** %7
%53 = getelementptr inbounds i32, i32* %52, i32 1
store i32* %53, i32** %7
br label %17
54: ; preds = %17
%55 = load i32*, i32** %6
store i32 0, i32* %55
%56 = load i32*, i32** %5
ret i32* %56
}

LLVM IR (-O2):
@.str = [3 x i32] [i32 37, i32 88, i32 0]
define i32* @_fatlegalize(i32* nocapture %0, i32* %1) {
%3 = tail call i32 @wcslen(i32* %0)
%4 = shl i32 %3, 4
%5 = tail call i32* @malloc(i32 %4)
%6 = load i32, i32* %0
%7 = icmp eq i32 %6, 0
br i1 %7, label %31, label %8
8: ; preds = %2, %25
%9 = phi i32 [ %29, %25 ], [ %6, %2 ]
%10 = phi i32* [ %28, %25 ], [ %0, %2 ]
%11 = phi i32* [ %27, %25 ], [ %5, %2 ]
%12 = tail call i64 @wcschr(i32* %1, i32 %9)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = load i32, i32* %10
%16 = icmp slt i32 %15, 32
br i1 %16, label %17, label %24
17: ; preds = %14, %8
%18 = getelementptr inbounds i32, i32* %11, i64 1
store i32 91, i32* %11
%19 = load i32, i32* %10
%20 = tail call i32 @swprintf(i32* %18, i32 4, i8* bitcast ([3 x i32]* @.str to i8*), i32 %19)
%21 = tail call i32 @wcslen(i32* %18)
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %18, i64 %22
store i32 93, i32* %23
br label %25
24: ; preds = %14
store i32 %15, i32* %11
br label %25
25: ; preds = %17, %24
%26 = phi i32* [ %23, %17 ], [ %11, %24 ]
%27 = getelementptr inbounds i32, i32* %26, i64 1
%28 = getelementptr inbounds i32, i32* %10, i64 1
%29 = load i32, i32* %28
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %8
31: ; preds = %25, %2
%32 = phi i32* [ %5, %2 ], [ %27, %25 ]
store i32 0, i32* %32
ret i32* %5
}