#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 */
unsigned char *c_postgresql_copy_escape_text(const unsigned char *in,
                                             size_t in_size,
                                             unsigned char *out) {
  while (in_size-- > 0) {
    unsigned char c = *in++;
    switch (c) {
    case '\t':
      *out++ = '\\';
      *out++ = 't';
      break;
    case '\n':
      *out++ = '\\';
      *out++ = 'n';
      break;
    case '\r':
      *out++ = '\\';
      *out++ = 'r';
      break;
    case '\\':
      *out++ = '\\';
      *out++ = '\\';
      break;
    default:
      *out++ = c;
    }
  }
  return out;
}


x86 assembly (clang, -O0):
<c_postgresql_copy_escape_text>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
cmp    $0x0,%rax
jbe    1242 <c_postgresql_copy_escape_text+0x142>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movzbl -0x19(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x9,%eax
je     1185 <c_postgresql_copy_escape_text+0x85>
jmp    1152 <c_postgresql_copy_escape_text+0x52>
mov    -0x20(%rbp),%eax
sub    $0xa,%eax
je     11ae <c_postgresql_copy_escape_text+0xae>
jmp    1163 <c_postgresql_copy_escape_text+0x63>
mov    -0x20(%rbp),%eax
sub    $0xd,%eax
je     11d7 <c_postgresql_copy_escape_text+0xd7>
jmp    1174 <c_postgresql_copy_escape_text+0x74>
mov    -0x20(%rbp),%eax
sub    $0x5c,%eax
je     1200 <c_postgresql_copy_escape_text+0x100>
jmp    1229 <c_postgresql_copy_escape_text+0x129>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5c,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x74,(%rax)
jmp    123d <c_postgresql_copy_escape_text+0x13d>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5c,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x6e,(%rax)
jmp    123d <c_postgresql_copy_escape_text+0x13d>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5c,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x72,(%rax)
jmp    123d <c_postgresql_copy_escape_text+0x13d>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5c,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5c,(%rax)
jmp    123d <c_postgresql_copy_escape_text+0x13d>
mov    -0x19(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1110 <c_postgresql_copy_escape_text+0x10>
mov    -0x18(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_postgresql_copy_escape_text>:
mov    %rdx,%rax
test   %rsi,%rsi
je     118b <c_postgresql_copy_escape_text+0x8b>
xor    %ecx,%ecx
jmp    1129 <c_postgresql_copy_escape_text+0x29>
mov    %dl,(%rax)
add    $0x1,%rax
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rcx
cmp    %rcx,%rsi
je     118b <c_postgresql_copy_escape_text+0x8b>
movzbl (%rdi,%rcx,1),%edx
cmp    $0xc,%dl
jg     1150 <c_postgresql_copy_escape_text+0x50>
cmp    $0x9,%dl
je     1170 <c_postgresql_copy_escape_text+0x70>
cmp    $0xa,%dl
jne    1110 <c_postgresql_copy_escape_text+0x10>
movw   $0x6e5c,(%rax)
add    $0x2,%rax
jmp    1120 <c_postgresql_copy_escape_text+0x20>
nopw   0x0(%rax,%rax,1)
cmp    $0xd,%dl
je     1180 <c_postgresql_copy_escape_text+0x80>
cmp    $0x5c,%dl
jne    1110 <c_postgresql_copy_escape_text+0x10>
movw   $0x5c5c,(%rax)
add    $0x2,%rax
jmp    1120 <c_postgresql_copy_escape_text+0x20>
cs nopw 0x0(%rax,%rax,1)
nop
movw   $0x745c,(%rax)
add    $0x2,%rax
jmp    1120 <c_postgresql_copy_escape_text+0x20>
nopl   0x0(%rax,%rax,1)
movw   $0x725c,(%rax)
add    $0x2,%rax
jmp    1120 <c_postgresql_copy_escape_text+0x20>
ret

LLVM IR (-O0):
define i8* @c_postgresql_copy_escape_text(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
br label %8
8: ; preds = %42, %3
%9 = load i64, i64* %5
%10 = add i64 %9, -1
store i64 %10, i64* %5
%11 = icmp ugt i64 %9, 0
br i1 %11, label %12, label %43
12: ; preds = %8
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %4
%15 = load i8, i8* %13
store i8 %15, i8* %7
%16 = load i8, i8* %7
%17 = zext i8 %16 to i32
switch i32 %17, label %38 [
i32 9, label %18
i32 10, label %23
i32 13, label %28
i32 92, label %33
]
18: ; preds = %12
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %6
store i8 92, i8* %19
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %6
store i8 116, i8* %21
br label %42
23: ; preds = %12
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %6
store i8 92, i8* %24
%26 = load i8*, i8** %6
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %6
store i8 110, i8* %26
br label %42
28: ; preds = %12
%29 = load i8*, i8** %6
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %6
store i8 92, i8* %29
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %6
store i8 114, i8* %31
br label %42
33: ; preds = %12
%34 = load i8*, i8** %6
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %6
store i8 92, i8* %34
%36 = load i8*, i8** %6
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %6
store i8 92, i8* %36
br label %42
38: ; preds = %12
%39 = load i8, i8* %7
%40 = load i8*, i8** %6
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %6
store i8 %39, i8* %40
br label %42
42: ; preds = %38, %33, %28, %23, %18
br label %8
43: ; preds = %8
%44 = load i8*, i8** %6
ret i8* %44
}

LLVM IR (-O2):
define i8* @c_postgresql_copy_escape_text(i8* nocapture %0, i64 %1, i8* writeonly %2) {
%4 = icmp eq i64 %1, 0
br i1 %4, label %29, label %5
5: ; preds = %3, %26
%6 = phi i64 [ %9, %26 ], [ %1, %3 ]
%7 = phi i8* [ %10, %26 ], [ %0, %3 ]
%8 = phi i8* [ %27, %26 ], [ %2, %3 ]
%9 = add i64 %6, -1
%10 = getelementptr inbounds i8, i8* %7, i64 1
%11 = load i8, i8* %7
switch i8 %11, label %24 [
i8 9, label %12
i8 10, label %15
i8 13, label %18
i8 92, label %21
]
12: ; preds = %5
%13 = getelementptr inbounds i8, i8* %8, i64 1
store i8 92, i8* %8
%14 = getelementptr inbounds i8, i8* %8, i64 2
store i8 116, i8* %13
br label %26
15: ; preds = %5
%16 = getelementptr inbounds i8, i8* %8, i64 1
store i8 92, i8* %8
%17 = getelementptr inbounds i8, i8* %8, i64 2
store i8 110, i8* %16
br label %26
18: ; preds = %5
%19 = getelementptr inbounds i8, i8* %8, i64 1
store i8 92, i8* %8
%20 = getelementptr inbounds i8, i8* %8, i64 2
store i8 114, i8* %19
br label %26
21: ; preds = %5
%22 = getelementptr inbounds i8, i8* %8, i64 1
store i8 92, i8* %8
%23 = getelementptr inbounds i8, i8* %8, i64 2
store i8 92, i8* %22
br label %26
24: ; preds = %5
%25 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %11, i8* %8
br label %26
26: ; preds = %24, %21, %18, %15, %12
%27 = phi i8* [ %25, %24 ], [ %23, %21 ], [ %20, %18 ], [ %17, %15 ], [ %14, %12 ]
%28 = icmp eq i64 %9, 0
br i1 %28, label %29, label %5
29: ; preds = %26, %3
%30 = phi i8* [ %2, %3 ], [ %27, %26 ]
ret i8* %30
}