#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ _checked_write(int, int *, size_t);
void _write_escaped(int fd, const uint8_t *buffer, size_t buffer_size) {
  uint8_t out[(64U)];
  size_t buffered = 0;
  while (buffer_size--) {
    uint8_t c = *(buffer++);
    switch (c) {
    case 0xc0U:
      out[buffered++] = (0xdbU);
      if (buffered >= (64U)) {
        _checked_write(fd, out, buffered);
        buffered = 0;
      };
      out[buffered++] = (0xdcU);
      if (buffered >= (64U)) {
        _checked_write(fd, out, buffered);
        buffered = 0;
      };
      break;
    case 0xdbU:
      out[buffered++] = (0xdbU);
      if (buffered >= (64U)) {
        _checked_write(fd, out, buffered);
        buffered = 0;
      };
      out[buffered++] = (0xddU);
      if (buffered >= (64U)) {
        _checked_write(fd, out, buffered);
        buffered = 0;
      };
      break;
    default:
      out[buffered++] = (c);
      if (buffered >= (64U)) {
        _checked_write(fd, out, buffered);
        buffered = 0;
      };
      break;
    }
  }
  out[buffered++] = 0xc0U;
  _checked_write(fd, out, buffered);
}


x86 assembly (clang, -O0):
<_write_escaped>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x128(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
cmp    $0x0,%rax
je     1334 <_write_escaped+0x224>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%eax
mov    %eax,-0x12c(%rbp)
mov    -0x12c(%rbp),%eax
mov    %eax,-0x130(%rbp)
sub    $0xc0,%eax
je     1193 <_write_escaped+0x83>
jmp    117d <_write_escaped+0x6d>
mov    -0x130(%rbp),%eax
sub    $0xdb,%eax
je     1236 <_write_escaped+0x126>
jmp    12d9 <_write_escaped+0x1c9>
mov    -0x128(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x128(%rbp)
movl   $0xdb,-0x120(%rbp,%rax,4)
cmpq   $0x40,-0x128(%rbp)
40
jb     11e2 <_write_escaped+0xd2>
mov    -0x4(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    -0x128(%rbp),%rdx
call   1030 <_checked_write@plt>
movq   $0x0,-0x128(%rbp)
mov    -0x128(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x128(%rbp)
movl   $0xdc,-0x120(%rbp,%rax,4)
cmpq   $0x40,-0x128(%rbp)
40
jb     1231 <_write_escaped+0x121>
mov    -0x4(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    -0x128(%rbp),%rdx
call   1030 <_checked_write@plt>
movq   $0x0,-0x128(%rbp)
jmp    132f <_write_escaped+0x21f>
mov    -0x128(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x128(%rbp)
movl   $0xdb,-0x120(%rbp,%rax,4)
cmpq   $0x40,-0x128(%rbp)
40
jb     1285 <_write_escaped+0x175>
mov    -0x4(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    -0x128(%rbp),%rdx
call   1030 <_checked_write@plt>
movq   $0x0,-0x128(%rbp)
mov    -0x128(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x128(%rbp)
movl   $0xdd,-0x120(%rbp,%rax,4)
cmpq   $0x40,-0x128(%rbp)
40
jb     12d4 <_write_escaped+0x1c4>
mov    -0x4(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    -0x128(%rbp),%rdx
call   1030 <_checked_write@plt>
movq   $0x0,-0x128(%rbp)
jmp    132f <_write_escaped+0x21f>
mov    -0x12c(%rbp),%ecx
mov    -0x128(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x128(%rbp)
mov    %ecx,-0x120(%rbp,%rax,4)
cmpq   $0x40,-0x128(%rbp)
40
jb     132a <_write_escaped+0x21a>
mov    -0x4(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    -0x128(%rbp),%rdx
call   1030 <_checked_write@plt>
movq   $0x0,-0x128(%rbp)
jmp    132f <_write_escaped+0x21f>
jmp    1131 <_write_escaped+0x21>
mov    -0x128(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x128(%rbp)
movl   $0xc0,-0x120(%rbp,%rax,4)
mov    -0x4(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    -0x128(%rbp),%rdx
call   1030 <_checked_write@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_write_escaped>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %edi,%r14d
test   %rdx,%rdx
je     1208 <_write_escaped+0xf8>
mov    %rdx,%rbx
mov    %rsi,%r12
xor    %ebp,%ebp
mov    %rsp,%r15
xor    %edx,%edx
jmp    115a <_write_escaped+0x4a>
nopw   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %r15,%rsi
call   1030 <_checked_write@plt>
xor    %edx,%edx
add    $0x1,%rbp
cmp    %rbp,%rbx
je     120a <_write_escaped+0xfa>
mov    (%r12,%rbp,4),%eax
cmp    $0xdb,%eax
je     1190 <_write_escaped+0x80>
cmp    $0xc0,%eax
jne    11c0 <_write_escaped+0xb0>
lea    0x1(%rdx),%rax
movl   $0xdb,(%rsp,%rdx,4)
cmp    $0x40,%rax
jae    11d2 <_write_escaped+0xc2>
movl   $0xdc,0x4(%rsp,%rdx,4)
jmp    11a9 <_write_escaped+0x99>
nopw   0x0(%rax,%rax,1)
lea    0x1(%rdx),%rax
movl   $0xdb,(%rsp,%rdx,4)
cmp    $0x40,%rax
jae    11e9 <_write_escaped+0xd9>
movl   $0xdd,0x4(%rsp,%rdx,4)
add    $0x2,%rdx
cmp    $0x40,%rdx
jb     114d <_write_escaped+0x3d>
jmp    1140 <_write_escaped+0x30>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,(%rsp,%rdx,4)
add    $0x1,%rdx
cmp    $0x40,%rdx
jb     114d <_write_escaped+0x3d>
jmp    1140 <_write_escaped+0x30>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %rax,%rdx
call   1030 <_checked_write@plt>
movl   $0xdc,(%rsp)
jmp    11fe <_write_escaped+0xee>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %rax,%rdx
call   1030 <_checked_write@plt>
movl   $0xdd,(%rsp)
mov    $0x1,%edx
jmp    114d <_write_escaped+0x3d>
xor    %edx,%edx
movl   $0xc0,(%rsp,%rdx,4)
add    $0x1,%rdx
mov    %rsp,%rsi
mov    %r14d,%edi
call   1030 <_checked_write@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @_write_escaped(i32 %0, i32* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i64
%7 = alloca [64 x i32]
%8 = alloca i64
%9 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i64 %2, i64* %6
store i64 0, i64* %8
br label %10
10: ; preds = %78, %3
%11 = load i64, i64* %6
%12 = add i64 %11, -1
store i64 %12, i64* %6
%13 = icmp ne i64 %11, 0
br i1 %13, label %14, label %79
14: ; preds = %10
%15 = load i32*, i32** %5
%16 = getelementptr inbounds i32, i32* %15, i32 1
store i32* %16, i32** %5
%17 = load i32, i32* %15
store i32 %17, i32* %9
%18 = load i32, i32* %9
switch i32 %18, label %65 [
i32 192, label %19
i32 219, label %42
]
19: ; preds = %14
%20 = load i64, i64* %8
%21 = add i64 %20, 1
store i64 %21, i64* %8
%22 = getelementptr inbounds [64 x i32], [64 x i32]* %7, i64 0, i64 %20
store i32 219, i32* %22
%23 = load i64, i64* %8
%24 = icmp uge i64 %23, 64
br i1 %24, label %25, label %30
25: ; preds = %19
%26 = load i32, i32* %4
%27 = getelementptr inbounds [64 x i32], [64 x i32]* %7, i64 0, i64 0
%28 = load i64, i64* %8
%29 = call i32 @_checked_write(i32 %26, i32* %27, i64 %28)
store i64 0, i64* %8
br label %30
30: ; preds = %25, %19
%31 = load i64, i64* %8
%32 = add i64 %31, 1
store i64 %32, i64* %8
%33 = getelementptr inbounds [64 x i32], [64 x i32]* %7, i64 0, i64 %31
store i32 220, i32* %33
%34 = load i64, i64* %8
%35 = icmp uge i64 %34, 64
br i1 %35, label %36, label %41
36: ; preds = %30
%37 = load i32, i32* %4
%38 = getelementptr inbounds [64 x i32], [64 x i32]* %7, i64 0, i64 0
%39 = load i64, i64* %8
%40 = call i32 @_checked_write(i32 %37, i32* %38, i64 %39)
store i64 0, i64* %8
br label %41
41: ; preds = %36, %30
br label %78
42: ; preds = %14
%43 = load i64, i64* %8
%44 = add i64 %43, 1
store i64 %44, i64* %8
%45 = getelementptr inbounds [64 x i32], [64 x i32]* %7, i64 0, i64 %43
store i32 219, i32* %45
%46 = load i64, i64* %8
%47 = icmp uge i64 %46, 64
br i1 %47, label %48, label %53
48: ; preds = %42
%49 = load i32, i32* %4
%50 = getelementptr inbounds [64 x i32], [64 x i32]* %7, i64 0, i64 0
%51 = load i64, i64* %8
%52 = call i32 @_checked_write(i32 %49, i32* %50, i64 %51)
store i64 0, i64* %8
br label %53
53: ; preds = %48, %42
%54 = load i64, i64* %8
%55 = add i64 %54, 1
store i64 %55, i64* %8
%56 = getelementptr inbounds [64 x i32], [64 x i32]* %7, i64 0, i64 %54
store i32 221, i32* %56
%57 = load i64, i64* %8
%58 = icmp uge i64 %57, 64
br i1 %58, label %59, label %64
59: ; preds = %53
%60 = load i32, i32* %4
%61 = getelementptr inbounds [64 x i32], [64 x i32]* %7, i64 0, i64 0
%62 = load i64, i64* %8
%63 = call i32 @_checked_write(i32 %60, i32* %61, i64 %62)
store i64 0, i64* %8
br label %64
64: ; preds = %59, %53
br label %78
65: ; preds = %14
%66 = load i32, i32* %9
%67 = load i64, i64* %8
%68 = add i64 %67, 1
store i64 %68, i64* %8
%69 = getelementptr inbounds [64 x i32], [64 x i32]* %7, i64 0, i64 %67
store i32 %66, i32* %69
%70 = load i64, i64* %8
%71 = icmp uge i64 %70, 64
br i1 %71, label %72, label %77
72: ; preds = %65
%73 = load i32, i32* %4
%74 = getelementptr inbounds [64 x i32], [64 x i32]* %7, i64 0, i64 0
%75 = load i64, i64* %8
%76 = call i32 @_checked_write(i32 %73, i32* %74, i64 %75)
store i64 0, i64* %8
br label %77
77: ; preds = %72, %65
br label %78
78: ; preds = %77, %64, %41
br label %10
79: ; preds = %10
%80 = load i64, i64* %8
%81 = add i64 %80, 1
store i64 %81, i64* %8
%82 = getelementptr inbounds [64 x i32], [64 x i32]* %7, i64 0, i64 %80
store i32 192, i32* %82
%83 = load i32, i32* %4
%84 = getelementptr inbounds [64 x i32], [64 x i32]* %7, i64 0, i64 0
%85 = load i64, i64* %8
%86 = call i32 @_checked_write(i32 %83, i32* %84, i64 %85)
ret void
}

LLVM IR (-O2):
define void @_write_escaped(i32 %0, i32* nocapture %1, i64 %2) {
%4 = alloca [64 x i32]
%5 = bitcast [64 x i32]* %4 to i8*
%6 = icmp eq i64 %2, 0
br i1 %6, label %49, label %7
7: ; preds = %3
%8 = getelementptr inbounds [64 x i32], [64 x i32]* %4, i64 0, i64 0
br label %9
9: ; preds = %7, %46
%10 = phi i64 [ %2, %7 ], [ %13, %46 ]
%11 = phi i32* [ %1, %7 ], [ %14, %46 ]
%12 = phi i64 [ 0, %7 ], [ %47, %46 ]
%13 = add i64 %10, -1
%14 = getelementptr inbounds i32, i32* %11, i64 1
%15 = load i32, i32* %11
switch i32 %15, label %40 [
i32 192, label %16
i32 219, label %28
]
16: ; preds = %9
%17 = add i64 %12, 1
%18 = getelementptr inbounds [64 x i32], [64 x i32]* %4, i64 0, i64 %12
store i32 219, i32* %18
%19 = icmp ugt i64 %17, 63
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @_checked_write(i32 %0, i32* %8, i64 %17)
store i32 220, i32* %8
br label %46
22: ; preds = %16
%23 = add nsw i64 %12, 2
%24 = getelementptr inbounds [64 x i32], [64 x i32]* %4, i64 0, i64 %17
store i32 220, i32* %24
%25 = icmp ugt i64 %23, 63
br i1 %25, label %26, label %46
26: ; preds = %22
%27 = call i32 @_checked_write(i32 %0, i32* %8, i64 %23)
br label %46
28: ; preds = %9
%29 = add i64 %12, 1
%30 = getelementptr inbounds [64 x i32], [64 x i32]* %4, i64 0, i64 %12
store i32 219, i32* %30
%31 = icmp ugt i64 %29, 63
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 @_checked_write(i32 %0, i32* %8, i64 %29)
store i32 221, i32* %8
br label %46
34: ; preds = %28
%35 = add nsw i64 %12, 2
%36 = getelementptr inbounds [64 x i32], [64 x i32]* %4, i64 0, i64 %29
store i32 221, i32* %36
%37 = icmp ugt i64 %35, 63
br i1 %37, label %38, label %46
38: ; preds = %34
%39 = call i32 @_checked_write(i32 %0, i32* %8, i64 %35)
br label %46
40: ; preds = %9
%41 = add i64 %12, 1
%42 = getelementptr inbounds [64 x i32], [64 x i32]* %4, i64 0, i64 %12
store i32 %15, i32* %42
%43 = icmp ugt i64 %41, 63
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 @_checked_write(i32 %0, i32* %8, i64 %41)
br label %46
46: ; preds = %32, %20, %40, %44, %34, %38, %22, %26
%47 = phi i64 [ 0, %44 ], [ %41, %40 ], [ 0, %38 ], [ %35, %34 ], [ 0, %26 ], [ %23, %22 ], [ 1, %20 ], [ 1, %32 ]
%48 = icmp eq i64 %13, 0
br i1 %48, label %49, label %9
49: ; preds = %46, %3
%50 = phi i64 [ 0, %3 ], [ %47, %46 ]
%51 = add nuw nsw i64 %50, 1
%52 = getelementptr inbounds [64 x i32], [64 x i32]* %4, i64 0, i64 %50
store i32 192, i32* %52
%53 = getelementptr inbounds [64 x i32], [64 x i32]* %4, i64 0, i64 0
%54 = call i32 @_checked_write(i32 %0, i32* %53, i64 %51)
ret void
}