#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 c_unescape_char_ptr(char *, char **);
int /*<<< orphan*/ free(char *);
char *strdup(char *);
char *c_unescape_str(char *str) {
  char ch;
  char *buf;
  char *src;
  char *dst;
  if (str == NULL || (buf = strdup(str)) == NULL)
    return (NULL);
  src = buf;
  dst = str;
  while ((ch = *(src++)) != 0) {
    if (ch == '\\')
      ch = c_unescape_char_ptr(src, &src);
    *(dst++) = ch;
  }
  *dst = 0;
  free(buf);
  return (str);
}


x86 assembly (clang, -O0):
<c_unescape_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     115e <c_unescape_str+0x2e>
mov    -0x10(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    116b <c_unescape_str+0x3b>
movq   $0x0,-0x8(%rbp)
jmp    11e9 <c_unescape_str+0xb9>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
mov    (%rax),%al
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     11d1 <c_unescape_str+0xa1>
movsbl -0x11(%rbp),%eax
cmp    $0x5c,%eax
jne    11b8 <c_unescape_str+0x88>
mov    -0x28(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <c_unescape_char_ptr@plt>
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%cl
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
mov    %cl,(%rax)
jmp    117b <c_unescape_str+0x4b>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_unescape_str>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1195 <c_unescape_str+0x65>
mov    %rdi,%r15
call   1050 <strdup@plt>
test   %rax,%rax
je     1195 <c_unescape_str+0x65>
mov    %rax,%r14
mov    %rsp,%r12
mov    %r15,%rbx
jmp    1175 <c_unescape_str+0x45>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rsi
call   1040 <c_unescape_char_ptr@plt>
mov    (%rsp),%rdi
mov    %al,(%rbx)
add    $0x1,%rbx
mov    %rdi,%rax
lea    0x1(%rax),%rdi
mov    %rdi,(%rsp)
movzbl (%rax),%eax
cmp    $0x5c,%al
je     1160 <c_unescape_str+0x30>
test   %al,%al
jne    116c <c_unescape_str+0x3c>
movb   $0x0,(%rbx)
mov    %r14,%rdi
call   1030 <free@plt>
jmp    1198 <c_unescape_str+0x68>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @c_unescape_str(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %14, label %10
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i8* @strdup(i8* %11)
store i8* %12, i8** %5
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %10, %1
store i8* null, i8** %2
br label %40
15: ; preds = %10
%16 = load i8*, i8** %5
store i8* %16, i8** %6
%17 = load i8*, i8** %3
store i8* %17, i8** %7
br label %18
18: ; preds = %31, %15
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %6
%21 = load i8, i8* %19
store i8 %21, i8* %4
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %35
24: ; preds = %18
%25 = load i8, i8* %4
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 92
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i8*, i8** %6
%30 = call signext i8 @c_unescape_char_ptr(i8* %29, i8** %6)
store i8 %30, i8* %4
br label %31
31: ; preds = %28, %24
%32 = load i8, i8* %4
%33 = load i8*, i8** %7
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %7
store i8 %32, i8* %33
br label %18
35: ; preds = %18
%36 = load i8*, i8** %7
store i8 0, i8* %36
%37 = load i8*, i8** %5
%38 = call i32 @free(i8* %37)
%39 = load i8*, i8** %3
store i8* %39, i8** %2
br label %40
40: ; preds = %35, %14
%41 = load i8*, i8** %2
ret i8* %41
}

LLVM IR (-O2):
define i8* @c_unescape_str(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %22, label %5
5: ; preds = %1
%6 = tail call i8* @strdup(i8* %0)
%7 = icmp eq i8* %6, null
br i1 %7, label %22, label %8
8: ; preds = %5, %16
%9 = phi i8* [ %17, %16 ], [ %6, %5 ]
%10 = phi i8* [ %19, %16 ], [ %0, %5 ]
%11 = getelementptr inbounds i8, i8* %9, i64 1
store i8* %11, i8** %2
%12 = load i8, i8* %9
switch i8 %12, label %16 [
i8 0, label %20
i8 92, label %13
]
13: ; preds = %8
%14 = call signext i8 @c_unescape_char_ptr(i8* %11, i8** %2)
%15 = load i8*, i8** %2
br label %16
16: ; preds = %8, %13
%17 = phi i8* [ %15, %13 ], [ %11, %8 ]
%18 = phi i8 [ %14, %13 ], [ %12, %8 ]
%19 = getelementptr inbounds i8, i8* %10, i64 1
store i8 %18, i8* %10
br label %8
20: ; preds = %8
store i8 0, i8* %10
%21 = call i32 @free(i8* %6)
br label %22
22: ; preds = %1, %5, %20
%23 = phi i8* [ %0, %20 ], [ null, %5 ], [ null, %1 ]
ret i8* %23
}