#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 *malloc(int);
int /*<<< orphan*/ printf(char *, char);
int strlen(char const *);
char *parse_sep(const char *str) {
  char *outstr = malloc((strlen(str) + 1) * sizeof(char));
  char *out = outstr;
  bool escape = false;
  char c = 0;
  while ((c = *str++) != '\0') {
    if (escape) {
      escape = false;
      switch (c) {
      case 'n':
        *out++ = '\n';
        break;
      case 't':
        *out++ = '\t';
        break;
      case '\\':
        *out++ = '\\';
        break;
      default:
        printf("Warning -- unknown escape character '%c'.\n", c);
        break;
      }
    } else {
      escape = (c == '\\');
      if (!escape)
        *out++ = c;
    }
  }
  *out = '\0';
  return outstr;
}


x86 assembly (clang, -O0):
<parse_sep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movb   $0x0,-0x1d(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x1d(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     1268 <parse_sep+0x138>
cmpl   $0x0,-0x1c(%rbp)
je     122e <parse_sep+0xfe>
movl   $0x0,-0x1c(%rbp)
movsbl -0x1d(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x5c,%eax
je     1202 <parse_sep+0xd2>
jmp    11b2 <parse_sep+0x82>
mov    -0x24(%rbp),%eax
sub    $0x6e,%eax
je     11d4 <parse_sep+0xa4>
jmp    11c3 <parse_sep+0x93>
mov    -0x24(%rbp),%eax
sub    $0x74,%eax
je     11eb <parse_sep+0xbb>
jmp    1219 <parse_sep+0xe9>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0xa,(%rax)
jmp    1229 <parse_sep+0xf9>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x9,(%rax)
jmp    1229 <parse_sep+0xf9>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5c,(%rax)
jmp    1229 <parse_sep+0xf9>
lea    0xde0(%rip),%rdi
movsbl -0x1d(%rbp),%esi
call   1040 <printf@plt>
jmp    1263 <parse_sep+0x133>
movsbl -0x1d(%rbp),%eax
cmp    $0x5c,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    125e <parse_sep+0x12e>
mov    -0x1d(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1263 <parse_sep+0x133>
jmp    116c <parse_sep+0x3c>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_sep>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    0x1(%rax),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    (%rbx),%cl
mov    %rax,%r12
test   %cl,%cl
je     11c1 <parse_sep+0x91>
add    $0x1,%rbx
xor    %eax,%eax
lea    0xe9f(%rip),%r15
mov    %r14,%r12
jmp    117c <parse_sep+0x4c>
movb   $0x5c,(%r12)
add    $0x1,%r12
xor    %eax,%eax
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
je     11c1 <parse_sep+0x91>
test   %eax,%eax
je     11a0 <parse_sep+0x70>
movsbl %cl,%esi
cmp    $0x5c,%esi
je     1166 <parse_sep+0x36>
cmp    $0x74,%esi
je     11b0 <parse_sep+0x80>
cmp    $0x6e,%esi
jne    11b7 <parse_sep+0x87>
movb   $0xa,(%r12)
jmp    116b <parse_sep+0x3b>
nopl   0x0(%rax)
mov    $0x1,%eax
cmp    $0x5c,%cl
je     1171 <parse_sep+0x41>
mov    %cl,(%r12)
jmp    116b <parse_sep+0x3b>
movb   $0x9,(%r12)
jmp    116b <parse_sep+0x3b>
mov    %r15,%rdi
call   1040 <printf@plt>
jmp    116f <parse_sep+0x3f>
movb   $0x0,(%r12)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [43 x i8] c"Warning -- unknown escape character '%c'.\0A\00"
define i8* @parse_sep(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = add nsw i32 %8, 1
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 1
%12 = trunc i64 %11 to i32
%13 = call i8* @malloc(i32 %12)
store i8* %13, i8** %3
%14 = load i8*, i8** %3
store i8* %14, i8** %4
store i32 0, i32* %5
store i8 0, i8* %6
br label %15
15: ; preds = %52, %1
%16 = load i8*, i8** %2
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %2
%18 = load i8, i8* %16
store i8 %18, i8* %6
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %53
21: ; preds = %15
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %40
24: ; preds = %21
store i32 0, i32* %5
%25 = load i8, i8* %6
%26 = sext i8 %25 to i32
switch i32 %26, label %36 [
i32 110, label %27
i32 116, label %30
i32 92, label %33
]
27: ; preds = %24
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %4
store i8 10, i8* %28
br label %39
30: ; preds = %24
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %4
store i8 9, i8* %31
br label %39
33: ; preds = %24
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %4
store i8 92, i8* %34
br label %39
36: ; preds = %24
%37 = load i8, i8* %6
%38 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8 signext %37)
br label %39
39: ; preds = %36, %33, %30, %27
br label %52
40: ; preds = %21
%41 = load i8, i8* %6
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 92
%44 = zext i1 %43 to i32
store i32 %44, i32* %5
%45 = load i32, i32* %5
%46 = icmp ne i32 %45, 0
br i1 %46, label %51, label %47
47: ; preds = %40
%48 = load i8, i8* %6
%49 = load i8*, i8** %4
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %4
store i8 %48, i8* %49
br label %51
51: ; preds = %47, %40
br label %52
52: ; preds = %51, %39
br label %15
53: ; preds = %15
%54 = load i8*, i8** %4
store i8 0, i8* %54
%55 = load i8*, i8** %3
ret i8* %55
}

LLVM IR (-O2):
@.str = [43 x i8] c"Warning -- unknown escape character '%c'.\0A\00"
define noalias i8* @parse_sep(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 1
%4 = tail call i8* @malloc(i32 %3)
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %33, label %7
7: ; preds = %1, %28
%8 = phi i8 [ %31, %28 ], [ %5, %1 ]
%9 = phi i8* [ %12, %28 ], [ %0, %1 ]
%10 = phi i32 [ %30, %28 ], [ 0, %1 ]
%11 = phi i8* [ %29, %28 ], [ %4, %1 ]
%12 = getelementptr inbounds i8, i8* %9, i64 1
%13 = icmp eq i32 %10, 0
br i1 %13, label %24, label %14
14: ; preds = %7
%15 = sext i8 %8 to i32
switch i32 %15, label %22 [
i32 110, label %16
i32 116, label %18
i32 92, label %20
]
16: ; preds = %14
%17 = getelementptr inbounds i8, i8* %11, i64 1
store i8 10, i8* %11
br label %28
18: ; preds = %14
%19 = getelementptr inbounds i8, i8* %11, i64 1
store i8 9, i8* %11
br label %28
20: ; preds = %14
%21 = getelementptr inbounds i8, i8* %11, i64 1
store i8 92, i8* %11
br label %28
22: ; preds = %14
%23 = tail call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8 signext %8)
br label %28
24: ; preds = %7
%25 = icmp eq i8 %8, 92
br i1 %25, label %28, label %26
26: ; preds = %24
%27 = getelementptr inbounds i8, i8* %11, i64 1
store i8 %8, i8* %11
br label %28
28: ; preds = %24, %26, %16, %18, %20, %22
%29 = phi i8* [ %11, %22 ], [ %21, %20 ], [ %19, %18 ], [ %17, %16 ], [ %11, %24 ], [ %27, %26 ]
%30 = phi i32 [ 0, %22 ], [ 0, %20 ], [ 0, %18 ], [ 0, %16 ], [ 1, %24 ], [ 0, %26 ]
%31 = load i8, i8* %12
%32 = icmp eq i8 %31, 0
br i1 %32, label %33, label %7
33: ; preds = %28, %1
%34 = phi i8* [ %4, %1 ], [ %29, %28 ]
store i8 0, i8* %34
ret i8* %4
}