#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 */
scalar_t__ in_alpha_class(char);
scalar_t__ in_class(char, char *);
scalar_t__ in_decimal_digit_class(char);
int needs_escapes(char *str, int n, unsigned flags) {
  char *c;
  int i;
  int val = 0;
  if (str) {
    for (i = 0, c = str; i < n; i++, c++) {
      if (in_alpha_class(*c))
        continue;
      if (in_decimal_digit_class(*c))
        continue;
      if (in_class(*c, "/._+:@~-"))
        continue;
      val = 1;
      break;
    }
  }
  return val;
}


x86 assembly (clang, -O0):
<needs_escapes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11f2 <needs_escapes+0xc2>
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ed <needs_escapes+0xbd>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1050 <in_alpha_class@plt>
cmp    $0x0,%rax
je     118a <needs_escapes+0x5a>
jmp    11d3 <needs_escapes+0xa3>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <in_decimal_digit_class@plt>
cmp    $0x0,%rax
je     11a5 <needs_escapes+0x75>
jmp    11d3 <needs_escapes+0xa3>
mov    -0x18(%rbp),%rax
lea    0xe50(%rip),%rsi
movsbl (%rax),%edi
call   1040 <in_class@plt>
cmp    $0x0,%rax
je     11c7 <needs_escapes+0x97>
jmp    11d3 <needs_escapes+0xa3>
movl   $0x1,-0x20(%rbp)
jmp    11ed <needs_escapes+0xbd>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1163 <needs_escapes+0x33>
jmp    11f2 <needs_escapes+0xc2>
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<needs_escapes>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
test   %rdi,%rdi
je     11a2 <needs_escapes+0x72>
test   %esi,%esi
jle    11a2 <needs_escapes+0x72>
mov    %rdi,%r12
mov    %esi,%r15d
xor    %ebx,%ebx
lea    0xeae(%rip),%r14
jmp    1169 <needs_escapes+0x39>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
cmp    %ebx,%r15d
je     11a0 <needs_escapes+0x70>
movsbl (%r12,%rbx,1),%edi
call   1050 <in_alpha_class@plt>
test   %rax,%rax
jne    1160 <needs_escapes+0x30>
movsbl (%r12,%rbx,1),%edi
call   1030 <in_decimal_digit_class@plt>
test   %rax,%rax
jne    1160 <needs_escapes+0x30>
movsbl (%r12,%rbx,1),%edi
mov    %r14,%rsi
call   1040 <in_class@plt>
test   %rax,%rax
jne    1160 <needs_escapes+0x30>
mov    $0x1,%eax
jmp    11a2 <needs_escapes+0x72>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"/._+:@~-\00"
define i32 @needs_escapes(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %9
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %43
12: ; preds = %3
store i32 0, i32* %8
%13 = load i8*, i8** %4
store i8* %13, i8** %7
br label %14
14: ; preds = %37, %12
%15 = load i32, i32* %8
%16 = load i32, i32* %5
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %42
18: ; preds = %14
%19 = load i8*, i8** %7
%20 = load i8, i8* %19
%21 = call i64 @in_alpha_class(i8 signext %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
br label %37
24: ; preds = %18
%25 = load i8*, i8** %7
%26 = load i8, i8* %25
%27 = call i64 @in_decimal_digit_class(i8 signext %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24
br label %37
30: ; preds = %24
%31 = load i8*, i8** %7
%32 = load i8, i8* %31
%33 = call i64 @in_class(i8 signext %32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %30
br label %37
36: ; preds = %30
store i32 1, i32* %9
br label %42
37: ; preds = %35, %29, %23
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
%40 = load i8*, i8** %7
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %7
br label %14
42: ; preds = %36, %14
br label %43
43: ; preds = %42, %3
%44 = load i32, i32* %9
ret i32 %44
}

LLVM IR (-O2):
@.str = [9 x i8] c"/._+:@~-\00"
define i32 @needs_escapes(i8* %0, i32 %1, i32 %2) {
%4 = icmp ne i8* %0, null
%5 = icmp sgt i32 %1, 0
%6 = and i1 %4, %5
br i1 %6, label %7, label %25
7: ; preds = %3, %21
%8 = phi i32 [ %22, %21 ], [ 0, %3 ]
%9 = phi i8* [ %23, %21 ], [ %0, %3 ]
%10 = load i8, i8* %9
%11 = tail call i64 @in_alpha_class(i8 signext %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %7
%14 = load i8, i8* %9
%15 = tail call i64 @in_decimal_digit_class(i8 signext %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i8, i8* %9
%19 = tail call i64 @in_class(i8 signext %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %17, %13, %7
%22 = add nuw nsw i32 %8, 1
%23 = getelementptr inbounds i8, i8* %9, i64 1
%24 = icmp eq i32 %22, %1
br i1 %24, label %25, label %7
25: ; preds = %21, %17, %3
%26 = phi i32 [ 0, %3 ], [ 0, %21 ], [ 1, %17 ]
ret i32 %26
}