#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*/ onion_c_quote(char const *, char *, int);
char *onion_low_scalar_malloc(int);
char *onion_c_quote_new(const char *str) {
  char *ret;
  int l = 3;
  const unsigned char *p = (const unsigned char *)str;
  while (*p != '\0') {
    if (*p == '\r' || *p == '"' || *p == '\\' || *p == '\t')
      l++;
    else if (*p == '\n')
      l += 4;
    else if (*p > 127)
      l += 4;
    l++;
    p++;
  }
  ret = onion_low_scalar_malloc(l);
  onion_c_quote(str, ret, l);
  return ret;
}


x86 assembly (clang, -O0):
<onion_c_quote_new>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x3,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
je     11f4 <onion_c_quote_new+0xd4>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xd,%eax
je     118b <onion_c_quote_new+0x6b>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x22,%eax
je     118b <onion_c_quote_new+0x6b>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x5c,%eax
je     118b <onion_c_quote_new+0x6b>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x9,%eax
jne    1199 <onion_c_quote_new+0x79>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11da <onion_c_quote_new+0xba>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xa,%eax
jne    11b7 <onion_c_quote_new+0x97>
mov    -0x14(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x14(%rbp)
jmp    11d5 <onion_c_quote_new+0xb5>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x7f,%eax
jle    11d0 <onion_c_quote_new+0xb0>
mov    -0x14(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x14(%rbp)
jmp    11d5 <onion_c_quote_new+0xb5>
jmp    11da <onion_c_quote_new+0xba>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    113b <onion_c_quote_new+0x1b>
mov    -0x14(%rbp),%edi
call   1040 <onion_low_scalar_malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <onion_c_quote@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<onion_c_quote_new>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x3,%ebx
lea    0xecc(%rip),%rax
mov    %rdi,%rcx
jmp    114a <onion_c_quote_new+0x2a>
nopl   0x0(%rax)
add    $0x1,%ebx
add    $0x1,%ebx
add    $0x1,%rcx
movzbl (%rcx),%edx
cmp    $0x22,%rdx
ja     1170 <onion_c_quote_new+0x50>
movslq (%rax,%rdx,4),%rsi
add    %rax,%rsi
jmp    *%rsi
add    $0x4,%ebx
jmp    1143 <onion_c_quote_new+0x23>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x5c,%dl
je     1140 <onion_c_quote_new+0x20>
lea    0x4(%rbx),%esi
test   %dl,%dl
cmovns %ebx,%esi
mov    %esi,%ebx
jmp    1143 <onion_c_quote_new+0x23>
mov    %ebx,%edi
call   1040 <onion_low_scalar_malloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rax,%rsi
mov    %ebx,%edx
call   1030 <onion_c_quote@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @onion_c_quote_new(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
store i32 3, i32* %4
%6 = load i8*, i8** %2
store i8* %6, i8** %5
br label %7
7: ; preds = %53, %1
%8 = load i8*, i8** %5
%9 = load i8, i8* %8
%10 = zext i8 %9 to i32
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %58
12: ; preds = %7
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = icmp eq i32 %15, 13
br i1 %16, label %32, label %17
17: ; preds = %12
%18 = load i8*, i8** %5
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = icmp eq i32 %20, 34
br i1 %21, label %32, label %22
22: ; preds = %17
%23 = load i8*, i8** %5
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = icmp eq i32 %25, 92
br i1 %26, label %32, label %27
27: ; preds = %22
%28 = load i8*, i8** %5
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = icmp eq i32 %30, 9
br i1 %31, label %32, label %35
32: ; preds = %27, %22, %17, %12
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %53
35: ; preds = %27
%36 = load i8*, i8** %5
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = icmp eq i32 %38, 10
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = load i32, i32* %4
%42 = add nsw i32 %41, 4
store i32 %42, i32* %4
br label %52
43: ; preds = %35
%44 = load i8*, i8** %5
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = icmp sgt i32 %46, 127
br i1 %47, label %48, label %51
48: ; preds = %43
%49 = load i32, i32* %4
%50 = add nsw i32 %49, 4
store i32 %50, i32* %4
br label %51
51: ; preds = %48, %43
br label %52
52: ; preds = %51, %40
br label %53
53: ; preds = %52, %32
%54 = load i32, i32* %4
%55 = add nsw i32 %54, 1
store i32 %55, i32* %4
%56 = load i8*, i8** %5
%57 = getelementptr inbounds i8, i8* %56, i32 1
store i8* %57, i8** %5
br label %7
58: ; preds = %7
%59 = load i32, i32* %4
%60 = call i8* @onion_low_scalar_malloc(i32 %59)
store i8* %60, i8** %3
%61 = load i8*, i8** %2
%62 = load i8*, i8** %3
%63 = load i32, i32* %4
%64 = call i32 @onion_c_quote(i8* %61, i8* %62, i32 %63)
%65 = load i8*, i8** %3
ret i8* %65
}

LLVM IR (-O2):
define i8* @onion_c_quote_new(i8* %0) {
br label %2
2: ; preds = %14, %1
%3 = phi i32 [ 3, %1 ], [ %16, %14 ]
%4 = phi i8* [ %0, %1 ], [ %17, %14 ]
%5 = load i8, i8* %4
switch i8 %5, label %10 [
i8 0, label %18
i8 13, label %6
i8 34, label %6
i8 92, label %6
i8 9, label %6
i8 10, label %8
]
6: ; preds = %2, %2, %2, %2
%7 = add nsw i32 %3, 1
br label %14
8: ; preds = %2
%9 = add nsw i32 %3, 4
br label %14
10: ; preds = %2
%11 = icmp slt i8 %5, 0
%12 = add nsw i32 %3, 4
%13 = select i1 %11, i32 %12, i32 %3
br label %14
14: ; preds = %10, %8, %6
%15 = phi i32 [ %7, %6 ], [ %9, %8 ], [ %13, %10 ]
%16 = add nsw i32 %15, 1
%17 = getelementptr inbounds i8, i8* %4, i64 1
br label %2
18: ; preds = %2
%19 = tail call i8* @onion_low_scalar_malloc(i32 %3)
%20 = tail call i32 @onion_c_quote(i8* %0, i8* %19, i32 %3)
ret i8* %19
}