#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 strlen(char const *);
int /*<<< orphan*/ write(int, char *, int);
void esc_write(int fd, const char *s) {
  char buf[64];
  {
    int j = 0;
    int l = strlen(s);
    while (j < l) {
      int i = 0;
      while (i < 63 && j < l) {
        switch (s[j]) {
        case ',':
        case '\\':
          buf[i++] = '\\';
        default:
          buf[i++] = s[j++];
          break;
        }
      }
      write(fd, buf, i);
    }
  }
}


x86 assembly (clang, -O0):
<esc_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x58(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x58(%rbp),%eax
jge    11ff <esc_write+0xdf>
movl   $0x0,-0x5c(%rbp)
xor    %eax,%eax
cmpl   $0x3f,-0x5c(%rbp)
mov    %al,-0x5d(%rbp)
jge    1170 <esc_write+0x50>
mov    -0x54(%rbp),%eax
cmp    -0x58(%rbp),%eax
setl   %al
mov    %al,-0x5d(%rbp)
mov    -0x5d(%rbp),%al
test   $0x1,%al
jne    1180 <esc_write+0x60>
jmp    11eb <esc_write+0xcb>
mov    -0x10(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x64(%rbp)
sub    $0x2c,%eax
je     11ae <esc_write+0x8e>
jmp    119d <esc_write+0x7d>
mov    -0x64(%rbp),%eax
sub    $0x5c,%eax
jne    11c0 <esc_write+0xa0>
jmp    11ae <esc_write+0x8e>
mov    -0x5c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x5c(%rbp)
cltq
movb   $0x5c,-0x50(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
mov    -0x54(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x54(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x5c(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x5c(%rbp)
cltq
mov    %cl,-0x50(%rbp,%rax,1)
jmp    1155 <esc_write+0x35>
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    -0x5c(%rbp),%edx
call   1030 <write@plt>
jmp    1142 <esc_write+0x22>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<esc_write>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r13
mov    %edi,%r14d
mov    %rsi,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11ac <esc_write+0x8c>
mov    %eax,%r12d
mov    %eax,%ebp
xor    %ebx,%ebx
mov    %rsp,%r15
jmp    1162 <esc_write+0x42>
nopl   0x0(%rax)
xor    %edx,%edx
mov    %r14d,%edi
mov    %r15,%rsi
call   1030 <write@plt>
cmp    %r12d,%ebx
jge    11ac <esc_write+0x8c>
cmp    %r12d,%ebx
jge    1150 <esc_write+0x30>
movslq %ebx,%rax
add    $0x1,%rax
xor    %edx,%edx
movzbl -0x1(%r13,%rax,1),%ecx
movsbl %cl,%esi
cmp    $0x5c,%esi
je     1183 <esc_write+0x63>
cmp    $0x2c,%esi
jne    118d <esc_write+0x6d>
movslq %edx,%rsi
add    $0x1,%edx
movb   $0x5c,(%rsp,%rsi,1)
movslq %edx,%rsi
add    $0x1,%edx
mov    %cl,(%rsp,%rsi,1)
add    $0x1,%ebx
cmp    $0x3d,%esi
jg     1152 <esc_write+0x32>
lea    0x1(%rax),%rcx
cmp    %rbp,%rax
mov    %rcx,%rax
jl     1170 <esc_write+0x50>
jmp    1152 <esc_write+0x32>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @esc_write(i32 %0, i8* %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @strlen(i8* %1)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %40
7: ; preds = %2
%8 = zext i32 %5 to i64
br label %9
9: ; preds = %7, %35
%10 = phi i32 [ %36, %35 ], [ 0, %7 ]
%11 = icmp slt i32 %10, %5
br i1 %11, label %12, label %35
12: ; preds = %9
%13 = sext i32 %10 to i64
br label %14
14: ; preds = %12, %24
%15 = phi i64 [ %13, %12 ], [ %26, %24 ]
%16 = phi i32 [ 0, %12 ], [ %27, %24 ]
%17 = getelementptr inbounds i8, i8* %1, i64 %15
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
switch i32 %19, label %24 [
i32 44, label %20
i32 92, label %20
]
20: ; preds = %14, %14
%21 = add nsw i32 %16, 1
%22 = sext i32 %16 to i64
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 %22
store i8 92, i8* %23
br label %24
24: ; preds = %14, %20
%25 = phi i32 [ %16, %14 ], [ %21, %20 ]
%26 = add nsw i64 %15, 1
%27 = add nsw i32 %25, 1
%28 = sext i32 %25 to i64
%29 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 %28
store i8 %18, i8* %29
%30 = icmp slt i32 %25, 62
%31 = icmp slt i64 %26, %8
%32 = select i1 %30, i1 %31, i1 false
br i1 %32, label %14, label %33
33: ; preds = %24
%34 = trunc i64 %26 to i32
br label %35
35: ; preds = %33, %9
%36 = phi i32 [ %10, %9 ], [ %34, %33 ]
%37 = phi i32 [ 0, %9 ], [ %27, %33 ]
%38 = call i32 @write(i32 %0, i8* %4, i32 %37)
%39 = icmp slt i32 %36, %5
br i1 %39, label %9, label %40
40: ; preds = %35, %2
ret void
}