#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*/ isalnum(char const);
char *onion_low_scalar_malloc(int);
int /*<<< orphan*/ onion_quote(char const *, char *, int);
int strlen(char const *);
char *onion_quote_new(const char *str) {
  int i;
  int l = strlen(str);
  int nl = 1;
  for (i = 0; i < l; i++) {
    if (!isalnum(str[i]))
      nl += 3;
    else
      nl++;
  }
  char *ret = onion_low_scalar_malloc(nl);
  onion_quote(str, ret, nl);
  return ret;
}


x86 assembly (clang, -O0):
<onion_quote_new>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11b6 <onion_quote_new+0x76>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isalnum@plt>
cmp    $0x0,%eax
jne    119a <onion_quote_new+0x5a>
mov    -0x14(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x14(%rbp)
jmp    11a3 <onion_quote_new+0x63>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a8 <onion_quote_new+0x68>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1166 <onion_quote_new+0x26>
mov    -0x14(%rbp),%edi
call   1060 <onion_low_scalar_malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <onion_quote@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<onion_quote_new>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
jle    1184 <onion_quote_new+0x44>
mov    %eax,%r15d
mov    $0x1,%r12d
xor    %ebx,%ebx
nop
movsbl (%r14,%rbx,1),%edi
call   1040 <isalnum@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
lea    (%r12,%rcx,2),%r12d
add    $0x1,%r12d
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1160 <onion_quote_new+0x20>
jmp    118a <onion_quote_new+0x4a>
mov    $0x1,%r12d
mov    %r12d,%edi
call   1060 <onion_low_scalar_malloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rax,%rsi
mov    %r12d,%edx
call   1050 <onion_quote@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @onion_quote_new(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %4
store i32 1, i32* %5
store i32 0, i32* %3
br label %9
9: ; preds = %28, %1
%10 = load i32, i32* %3
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %31
13: ; preds = %9
%14 = load i8*, i8** %2
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = call i32 @isalnum(i8 signext %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %13
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 3
store i32 %23, i32* %5
br label %27
24: ; preds = %13
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %27
27: ; preds = %24, %21
br label %28
28: ; preds = %27
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
br label %9
31: ; preds = %9
%32 = load i32, i32* %5
%33 = call i8* @onion_low_scalar_malloc(i32 %32)
store i8* %33, i8** %6
%34 = load i8*, i8** %2
%35 = load i8*, i8** %6
%36 = load i32, i32* %5
%37 = call i32 @onion_quote(i8* %34, i8* %35, i32 %36)
%38 = load i8*, i8** %6
ret i8* %38
}

LLVM IR (-O2):
define i8* @onion_quote_new(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %17
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %15, %6 ]
%8 = phi i32 [ 1, %4 ], [ %14, %6 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %7
%10 = load i8, i8* %9
%11 = tail call i32 @isalnum(i8 signext %10)
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i32 3, i32 1
%14 = add nuw nsw i32 %13, %8
%15 = add nuw nsw i64 %7, 1
%16 = icmp eq i64 %15, %5
br i1 %16, label %17, label %6
17: ; preds = %6, %1
%18 = phi i32 [ 1, %1 ], [ %14, %6 ]
%19 = tail call i8* @onion_low_scalar_malloc(i32 %18)
%20 = tail call i32 @onion_quote(i8* %0, i8* %19, i32 %18)
ret i8* %19
}