#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*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
scalar_t__ strcat(char *, char *);
int strlen(char *);
char *undo_esc_char(char *s) {
  int i = 0;
  long j = 0;
  char c2 = '\0';
  char *sout;
  sout = (char *)malloc(strlen(s) * 5);
  sout[0] = '\0';
  do {
    c2 = s[i++];
    switch (c2) {
    case '\a':
      sout = (char *)strcat(sout, "\\a");
      break;
    case '\b':
      sout = (char *)strcat(sout, "\\b");
      break;
    case '\f':
      sout = (char *)strcat(sout, "\\f");
      break;
    case '\v':
      sout = (char *)strcat(sout, "\\v");
      break;
    case '\t':
      sout = (char *)strcat(sout, "\\t");
      break;
    case '\n':
      sout = (char *)strcat(sout, "\\n");
      break;
    case '\r':
      sout = (char *)strcat(sout, "\\r");
      break;
    default:
      j = strlen(sout);
      sout[j] = c2;
      sout[j + 1] = '\0';
      break;
    }
    if (i > 255) {
      printf("looktxt: warn : undo esc char : string too long\n");
      free(sout);
      return (NULL);
    }
  } while (c2 != '\0');
  return (sout);
}


x86 assembly (clang, -O0):
<undo_esc_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movb   $0x0,-0x21(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
imul   $0x5,%eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
mov    (%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
add    $0xfffffff9,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x6,%eax
ja     127a <undo_esc_char+0x12a>
mov    -0x38(%rbp),%rax
lea    0xe3e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x30(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1070 <strcat@plt>
mov    %rax,-0x30(%rbp)
jmp    12a4 <undo_esc_char+0x154>
mov    -0x30(%rbp),%rdi
lea    0xe30(%rip),%rsi
call   1070 <strcat@plt>
mov    %rax,-0x30(%rbp)
jmp    12a4 <undo_esc_char+0x154>
mov    -0x30(%rbp),%rdi
lea    0xe1a(%rip),%rsi
call   1070 <strcat@plt>
mov    %rax,-0x30(%rbp)
jmp    12a4 <undo_esc_char+0x154>
mov    -0x30(%rbp),%rdi
lea    0xe04(%rip),%rsi
call   1070 <strcat@plt>
mov    %rax,-0x30(%rbp)
jmp    12a4 <undo_esc_char+0x154>
mov    -0x30(%rbp),%rdi
lea    0xdee(%rip),%rsi
call   1070 <strcat@plt>
mov    %rax,-0x30(%rbp)
jmp    12a4 <undo_esc_char+0x154>
mov    -0x30(%rbp),%rdi
lea    0xdd8(%rip),%rsi
call   1070 <strcat@plt>
mov    %rax,-0x30(%rbp)
jmp    12a4 <undo_esc_char+0x154>
mov    -0x30(%rbp),%rdi
lea    0xdc2(%rip),%rsi
call   1070 <strcat@plt>
mov    %rax,-0x30(%rbp)
jmp    12a4 <undo_esc_char+0x154>
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
cltq
mov    %rax,-0x20(%rbp)
mov    -0x21(%rbp),%dl
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,0x1(%rax,%rcx,1)
cmpl   $0xff,-0x14(%rbp)
jle    12d3 <undo_esc_char+0x183>
lea    0xd79(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    12ed <undo_esc_char+0x19d>
jmp    12d8 <undo_esc_char+0x188>
movsbl -0x21(%rbp),%eax
cmp    $0x0,%eax
jne    118b <undo_esc_char+0x3b>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<undo_esc_char>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <strlen@plt>
lea    (%rax,%rax,4),%edi
call   1060 <malloc@plt>
mov    %rax,%r12
movb   $0x0,(%rax)
xor    %r14d,%r14d
lea    0xe85(%rip),%r13
lea    0xea3(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl (%rbx,%r14,1),%r15d
add    $0x1,%r14
mov    %r15d,%eax
add    $0xfffffff9,%eax
cmp    $0x6,%eax
ja     11ba <undo_esc_char+0x6a>
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
mov    %r12,%rdi
lea    0xe64(%rip),%rsi
jmp    1220 <undo_esc_char+0xd0>
mov    %r12,%rdi
call   1050 <strlen@plt>
cltq
mov    %r15b,(%r12,%rax,1)
movb   $0x0,0x1(%r12,%rax,1)
cmp    $0x100,%r14
jne    1231 <undo_esc_char+0xe1>
jmp    123c <undo_esc_char+0xec>
mov    %r12,%rdi
lea    0xe45(%rip),%rsi
jmp    1220 <undo_esc_char+0xd0>
mov    %r12,%rdi
lea    0xe3c(%rip),%rsi
jmp    1220 <undo_esc_char+0xd0>
mov    %r12,%rdi
mov    %rbp,%rsi
jmp    1220 <undo_esc_char+0xd0>
mov    %r12,%rdi
lea    0xe1c(%rip),%rsi
jmp    1220 <undo_esc_char+0xd0>
mov    %r12,%rdi
lea    0xe13(%rip),%rsi
jmp    1220 <undo_esc_char+0xd0>
mov    %r12,%rdi
lea    0xe13(%rip),%rsi
nopl   0x0(%rax,%rax,1)
call   1070 <strcat@plt>
mov    %rax,%r12
cmp    $0x100,%r14
je     123c <undo_esc_char+0xec>
test   %r15b,%r15b
jne    1190 <undo_esc_char+0x40>
jmp    1253 <undo_esc_char+0x103>
lea    0xdee(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\\a\00"
@.str.1 = [3 x i8] c"\\b\00"
@.str.2 = [3 x i8] c"\\f\00"
@.str.3 = [3 x i8] c"\\v\00"
@.str.4 = [3 x i8] c"\\t\00"
@.str.5 = [3 x i8] c"\\n\00"
@.str.6 = [3 x i8] c"\\r\00"
@.str.7 = [49 x i8] c"looktxt: warn : undo esc char : string too long\0A\00"
define i8* @undo_esc_char(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i8
%7 = alloca i8*
store i8* %0, i8** %3
store i32 0, i32* %4
store i64 0, i64* %5
store i8 0, i8* %6
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = mul nsw i32 %9, 5
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = getelementptr inbounds i8, i8* %13, i64 0
store i8 0, i8* %14
br label %15
15: ; preds = %72, %1
%16 = load i8*, i8** %3
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
%19 = sext i32 %17 to i64
%20 = getelementptr inbounds i8, i8* %16, i64 %19
%21 = load i8, i8* %20
store i8 %21, i8* %6
%22 = load i8, i8* %6
%23 = sext i8 %22 to i32
switch i32 %23, label %52 [
i32 7, label %24
i32 8, label %28
i32 12, label %32
i32 11, label %36
i32 9, label %40
i32 10, label %44
i32 13, label %48
]
24: ; preds = %15
%25 = load i8*, i8** %7
%26 = call i64 @strcat(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %7
br label %64
28: ; preds = %15
%29 = load i8*, i8** %7
%30 = call i64 @strcat(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%31 = inttoptr i64 %30 to i8*
store i8* %31, i8** %7
br label %64
32: ; preds = %15
%33 = load i8*, i8** %7
%34 = call i64 @strcat(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%35 = inttoptr i64 %34 to i8*
store i8* %35, i8** %7
br label %64
36: ; preds = %15
%37 = load i8*, i8** %7
%38 = call i64 @strcat(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%39 = inttoptr i64 %38 to i8*
store i8* %39, i8** %7
br label %64
40: ; preds = %15
%41 = load i8*, i8** %7
%42 = call i64 @strcat(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%43 = inttoptr i64 %42 to i8*
store i8* %43, i8** %7
br label %64
44: ; preds = %15
%45 = load i8*, i8** %7
%46 = call i64 @strcat(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%47 = inttoptr i64 %46 to i8*
store i8* %47, i8** %7
br label %64
48: ; preds = %15
%49 = load i8*, i8** %7
%50 = call i64 @strcat(i8* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%51 = inttoptr i64 %50 to i8*
store i8* %51, i8** %7
br label %64
52: ; preds = %15
%53 = load i8*, i8** %7
%54 = call i32 @strlen(i8* %53)
%55 = sext i32 %54 to i64
store i64 %55, i64* %5
%56 = load i8, i8* %6
%57 = load i8*, i8** %7
%58 = load i64, i64* %5
%59 = getelementptr inbounds i8, i8* %57, i64 %58
store i8 %56, i8* %59
%60 = load i8*, i8** %7
%61 = load i64, i64* %5
%62 = add nsw i64 %61, 1
%63 = getelementptr inbounds i8, i8* %60, i64 %62
store i8 0, i8* %63
br label %64
64: ; preds = %52, %48, %44, %40, %36, %32, %28, %24
%65 = load i32, i32* %4
%66 = icmp sgt i32 %65, 255
br i1 %66, label %67, label %71
67: ; preds = %64
%68 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0))
%69 = load i8*, i8** %7
%70 = call i32 @free(i8* %69)
store i8* null, i8** %2
br label %78
71: ; preds = %64
br label %72
72: ; preds = %71
%73 = load i8, i8* %6
%74 = sext i8 %73 to i32
%75 = icmp ne i32 %74, 0
br i1 %75, label %15, label %76
76: ; preds = %72
%77 = load i8*, i8** %7
store i8* %77, i8** %2
br label %78
78: ; preds = %76, %67
%79 = load i8*, i8** %2
ret i8* %79
}

LLVM IR (-O2):
@.str = [3 x i8] c"\\a\00"
@.str.1 = [3 x i8] c"\\b\00"
@.str.2 = [3 x i8] c"\\f\00"
@.str.3 = [3 x i8] c"\\v\00"
@.str.4 = [3 x i8] c"\\t\00"
@.str.5 = [3 x i8] c"\\n\00"
@.str.6 = [3 x i8] c"\\r\00"
@str = [48 x i8] c"looktxt: warn : undo esc char : string too long\00"
define i8* @undo_esc_char(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = mul nsw i32 %2, 5
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i8*
store i8 0, i8* %5
br label %6
6: ; preds = %46, %1
%7 = phi i64 [ %9, %46 ], [ 0, %1 ]
%8 = phi i8* [ %41, %46 ], [ %5, %1 ]
%9 = add nuw nsw i64 %7, 1
%10 = getelementptr inbounds i8, i8* %0, i64 %7
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
switch i32 %12, label %34 [
i32 7, label %13
i32 8, label %16
i32 12, label %19
i32 11, label %22
i32 9, label %25
i32 10, label %28
i32 13, label %31
]
13: ; preds = %6
%14 = tail call i64 @strcat(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%15 = inttoptr i64 %14 to i8*
br label %40
16: ; preds = %6
%17 = tail call i64 @strcat(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%18 = inttoptr i64 %17 to i8*
br label %40
19: ; preds = %6
%20 = tail call i64 @strcat(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%21 = inttoptr i64 %20 to i8*
br label %40
22: ; preds = %6
%23 = tail call i64 @strcat(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%24 = inttoptr i64 %23 to i8*
br label %40
25: ; preds = %6
%26 = tail call i64 @strcat(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%27 = inttoptr i64 %26 to i8*
br label %40
28: ; preds = %6
%29 = tail call i64 @strcat(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%30 = inttoptr i64 %29 to i8*
br label %40
31: ; preds = %6
%32 = tail call i64 @strcat(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%33 = inttoptr i64 %32 to i8*
br label %40
34: ; preds = %6
%35 = tail call i32 @strlen(i8* %8)
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %8, i64 %36
store i8 %11, i8* %37
%38 = add nsw i64 %36, 1
%39 = getelementptr inbounds i8, i8* %8, i64 %38
store i8 0, i8* %39
br label %40
40: ; preds = %34, %31, %28, %25, %22, %19, %16, %13
%41 = phi i8* [ %8, %34 ], [ %33, %31 ], [ %30, %28 ], [ %27, %25 ], [ %24, %22 ], [ %21, %19 ], [ %18, %16 ], [ %15, %13 ]
%42 = icmp eq i64 %7, 255
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str, i64 0, i64 0))
%45 = tail call i32 @free(i8* %41)
br label %48
46: ; preds = %40
%47 = icmp eq i8 %11, 0
br i1 %47, label %48, label %6
48: ; preds = %46, %43
%49 = phi i8* [ null, %43 ], [ %41, %46 ]
ret i8* %49
}