#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
void csv_escape(char *in, char *out) {
  char *t, *orig;
  int cnt = 0;
  t = out;
  orig = in;
  while (*in) {
    if (*in == '"')
      *out++ = '"';
    if ((unsigned char)*in < 32) {
      in++;
      cnt++;
    } else
      *out++ = *in++;
    *out = '\0';
  }
  if (cnt)
    fprintf(stderr, "Bad File: %s\n", orig);
}


x86 assembly (clang, -O0):
<csv_escape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11be <csv_escape+0xae>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    1166 <csv_escape+0x56>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x22,(%rax)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x20,%eax
jge    1190 <csv_escape+0x80>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b2 <csv_escape+0xa2>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    1137 <csv_escape+0x27>
cmpl   $0x0,-0x24(%rbp)
je     11e1 <csv_escape+0xd1>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe24(%rip),%rsi
call   1030 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<csv_escape>:
mov    %rdi,%r8
xor    %eax,%eax
mov    %rdi,%rcx
jmp    112d <csv_escape+0x1d>
nopw   0x0(%rax,%rax,1)
mov    %dl,(%rsi)
add    $0x1,%rsi
add    $0x1,%rcx
movb   $0x0,(%rsi)
movzbl (%rcx),%edx
cmp    $0x22,%dl
je     1140 <csv_escape+0x30>
test   %dl,%dl
je     1154 <csv_escape+0x44>
cmp    $0x1f,%dl
ja     1120 <csv_escape+0x10>
jmp    114f <csv_escape+0x3f>
movb   $0x22,(%rsi)
add    $0x1,%rsi
movzbl (%rcx),%edx
cmp    $0x1f,%dl
ja     1120 <csv_escape+0x10>
add    $0x1,%eax
jmp    1126 <csv_escape+0x16>
test   %eax,%eax
je     1170 <csv_escape+0x60>
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
lea    0xe98(%rip),%rsi
mov    %r8,%rdx
jmp    1030 <fprintf@plt>
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [14 x i8] c"Bad File: %s\0A\00"
define void @csv_escape(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %7
%8 = load i8*, i8** %4
store i8* %8, i8** %5
%9 = load i8*, i8** %3
store i8* %9, i8** %6
br label %10
10: ; preds = %38, %2
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %40
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 34
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
store i8 34, i8* %20
br label %22
22: ; preds = %19, %14
%23 = load i8*, i8** %3
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = icmp slt i32 %25, 32
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %3
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %38
32: ; preds = %22
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %3
%35 = load i8, i8* %33
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %4
store i8 %35, i8* %36
br label %38
38: ; preds = %32, %27
%39 = load i8*, i8** %4
store i8 0, i8* %39
br label %10
40: ; preds = %10
%41 = load i32, i32* %7
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %6
%46 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %43, %40
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [14 x i8] c"Bad File: %s\0A\00"
define void @csv_escape(i8* %0, i8* nocapture writeonly %1) {
br label %3
3: ; preds = %19, %2
%4 = phi i8* [ %1, %2 ], [ %20, %19 ]
%5 = phi i8* [ %0, %2 ], [ %22, %19 ]
%6 = phi i32 [ 0, %2 ], [ %21, %19 ]
%7 = load i8, i8* %5
switch i8 %7, label %11 [
i8 0, label %23
i8 34, label %8
]
8: ; preds = %3
%9 = getelementptr inbounds i8, i8* %4, i64 1
store i8 34, i8* %4
%10 = load i8, i8* %5
br label %11
11: ; preds = %3, %8
%12 = phi i8 [ %7, %3 ], [ %10, %8 ]
%13 = phi i8* [ %4, %3 ], [ %9, %8 ]
%14 = icmp ult i8 %12, 32
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = add nsw i32 %6, 1
br label %19
17: ; preds = %11
%18 = getelementptr inbounds i8, i8* %13, i64 1
store i8 %12, i8* %13
br label %19
19: ; preds = %17, %15
%20 = phi i8* [ %13, %15 ], [ %18, %17 ]
%21 = phi i32 [ %16, %15 ], [ %6, %17 ]
%22 = getelementptr inbounds i8, i8* %5, i64 1
store i8 0, i8* %20
br label %3
23: ; preds = %3
%24 = icmp eq i32 %6, 0
br i1 %24, label %28, label %25
25: ; preds = %23
%26 = load i32, i32* @stderr
%27 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %28
28: ; preds = %25, %23
ret void
}