#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_bytea(const unsigned char *in,
                                              size_t in_size,
                                              unsigned char *out) {
  while (in_size-- > 0) {
    unsigned char c = *in++;
    if (c == '\\') {
      *out++ = '\\';
      *out++ = '\\';
      *out++ = '\\';
      *out++ = '\\';
    } else if (c >= 32 && c <= 126) {
      *out++ = c;
    } else {
      *out++ = '\\';
      *out++ = '\\';
      *out++ = '0' + ((c >> 6) & 0x7);
      *out++ = '0' + ((c >> 3) & 0x7);
      *out++ = '0' + (c & 0x7);
    }
  }
  return out;
}


x86 assembly (clang, -O0):
<c_postgresql_copy_escape_bytea>:
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    1255 <c_postgresql_copy_escape_bytea+0x155>
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
cmp    $0x5c,%eax
jne    1197 <c_postgresql_copy_escape_bytea+0x97>
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)
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    1250 <c_postgresql_copy_escape_bytea+0x150>
movzbl -0x19(%rbp),%eax
cmp    $0x20,%eax
jl     11ca <c_postgresql_copy_escape_bytea+0xca>
movzbl -0x19(%rbp),%eax
cmp    $0x7e,%eax
jg     11ca <c_postgresql_copy_escape_bytea+0xca>
mov    -0x19(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    124b <c_postgresql_copy_escape_bytea+0x14b>
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)
movzbl -0x19(%rbp),%eax
sar    $0x6,%eax
and    $0x7,%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
movzbl -0x19(%rbp),%eax
sar    $0x3,%eax
and    $0x7,%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
movzbl -0x19(%rbp),%eax
and    $0x7,%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1250 <c_postgresql_copy_escape_bytea+0x150>
jmp    1110 <c_postgresql_copy_escape_bytea+0x10>
mov    -0x18(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_postgresql_copy_escape_bytea>:
mov    %rdx,%rax
test   %rsi,%rsi
je     1172 <c_postgresql_copy_escape_bytea+0x72>
xor    %ecx,%ecx
jmp    1123 <c_postgresql_copy_escape_bytea+0x23>
nopl   0x0(%rax)
movl   $0x5c5c5c5c,(%rax)
add    $0x4,%rax
add    $0x1,%rcx
cmp    %rcx,%rsi
je     1172 <c_postgresql_copy_escape_bytea+0x72>
movzbl (%rdi,%rcx,1),%r8d
cmp    $0x5c,%r8b
je     1110 <c_postgresql_copy_escape_bytea+0x10>
lea    -0x20(%r8),%edx
cmp    $0x5e,%dl
ja     1140 <c_postgresql_copy_escape_bytea+0x40>
mov    %r8b,(%rax)
add    $0x1,%rax
jmp    111a <c_postgresql_copy_escape_bytea+0x1a>
movw   $0x5c5c,(%rax)
mov    %r8d,%edx
shr    $0x6,%dl
or     $0x30,%dl
mov    %dl,0x2(%rax)
mov    %r8d,%edx
shr    $0x3,%dl
and    $0x7,%dl
or     $0x30,%dl
mov    %dl,0x3(%rax)
and    $0x7,%r8b
or     $0x30,%r8b
mov    %r8b,0x4(%rax)
add    $0x5,%rax
jmp    111a <c_postgresql_copy_escape_bytea+0x1a>
ret

LLVM IR (-O0):
define i8* @c_postgresql_copy_escape_bytea(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 = %69, %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 %70
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
%18 = icmp eq i32 %17, 92
br i1 %18, label %19, label %28
19: ; preds = %12
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %6
store i8 92, i8* %20
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %6
store i8 92, i8* %22
%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 92, i8* %26
br label %69
28: ; preds = %12
%29 = load i8, i8* %7
%30 = zext i8 %29 to i32
%31 = icmp sge i32 %30, 32
br i1 %31, label %32, label %40
32: ; preds = %28
%33 = load i8, i8* %7
%34 = zext i8 %33 to i32
%35 = icmp sle i32 %34, 126
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = load i8, i8* %7
%38 = load i8*, i8** %6
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %6
store i8 %37, i8* %38
br label %68
40: ; preds = %32, %28
%41 = load i8*, i8** %6
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %6
store i8 92, i8* %41
%43 = load i8*, i8** %6
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %6
store i8 92, i8* %43
%45 = load i8, i8* %7
%46 = zext i8 %45 to i32
%47 = ashr i32 %46, 6
%48 = and i32 %47, 7
%49 = add nsw i32 48, %48
%50 = trunc i32 %49 to i8
%51 = load i8*, i8** %6
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %6
store i8 %50, i8* %51
%53 = load i8, i8* %7
%54 = zext i8 %53 to i32
%55 = ashr i32 %54, 3
%56 = and i32 %55, 7
%57 = add nsw i32 48, %56
%58 = trunc i32 %57 to i8
%59 = load i8*, i8** %6
%60 = getelementptr inbounds i8, i8* %59, i32 1
store i8* %60, i8** %6
store i8 %58, i8* %59
%61 = load i8, i8* %7
%62 = zext i8 %61 to i32
%63 = and i32 %62, 7
%64 = add nsw i32 48, %63
%65 = trunc i32 %64 to i8
%66 = load i8*, i8** %6
%67 = getelementptr inbounds i8, i8* %66, i32 1
store i8* %67, i8** %6
store i8 %65, i8* %66
br label %68
68: ; preds = %40, %36
br label %69
69: ; preds = %68, %19
br label %8
70: ; preds = %8
%71 = load i8*, i8** %6
ret i8* %71
}

LLVM IR (-O2):
define i8* @c_postgresql_copy_escape_bytea(i8* nocapture %0, i64 %1, i8* writeonly %2) {
%4 = icmp eq i64 %1, 0
br i1 %4, label %36, label %5
5: ; preds = %3, %33
%6 = phi i64 [ %9, %33 ], [ %1, %3 ]
%7 = phi i8* [ %10, %33 ], [ %0, %3 ]
%8 = phi i8* [ %34, %33 ], [ %2, %3 ]
%9 = add i64 %6, -1
%10 = getelementptr inbounds i8, i8* %7, i64 1
%11 = load i8, i8* %7
%12 = icmp eq i8 %11, 92
br i1 %12, label %13, label %16
13: ; preds = %5
%14 = getelementptr inbounds i8, i8* %8, i64 4
%15 = bitcast i8* %8 to i32*
store i32 1549556828, i32* %15
br label %33
16: ; preds = %5
%17 = add i8 %11, -32
%18 = icmp ult i8 %17, 95
%19 = getelementptr inbounds i8, i8* %8, i64 1
br i1 %18, label %20, label %21
20: ; preds = %16
store i8 %11, i8* %8
br label %33
21: ; preds = %16
store i8 92, i8* %8
%22 = getelementptr inbounds i8, i8* %8, i64 2
store i8 92, i8* %19
%23 = lshr i8 %11, 6
%24 = or i8 %23, 48
%25 = getelementptr inbounds i8, i8* %8, i64 3
store i8 %24, i8* %22
%26 = lshr i8 %11, 3
%27 = and i8 %26, 7
%28 = or i8 %27, 48
%29 = getelementptr inbounds i8, i8* %8, i64 4
store i8 %28, i8* %25
%30 = and i8 %11, 7
%31 = or i8 %30, 48
%32 = getelementptr inbounds i8, i8* %8, i64 5
store i8 %31, i8* %29
br label %33
33: ; preds = %20, %21, %13
%34 = phi i8* [ %14, %13 ], [ %19, %20 ], [ %32, %21 ]
%35 = icmp eq i64 %9, 0
br i1 %35, label %36, label %5
36: ; preds = %33, %3
%37 = phi i8* [ %2, %3 ], [ %34, %33 ]
ret i8* %37
}