#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 */
struct stringbuf {
  int dummy;
};
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned char);
int /*<<< orphan*/ stringbuf_puts(struct stringbuf *, char *);
void __escape_one_char(struct stringbuf *result, unsigned char cc) {
  char buffer[6];
  if (cc == '\f') {
    stringbuf_puts(result, "\\f");
  } else if (cc == '\v') {
    stringbuf_puts(result, "\\v");
  } else if (cc == '\r') {
    stringbuf_puts(result, "\\r");
  } else if (cc == '\0') {
    stringbuf_puts(result, "\\0");
  } else {
    snprintf(buffer, sizeof(buffer), "\\%03o", cc);
    stringbuf_puts(result, buffer);
  }
}


x86 assembly (clang, -O0):
<__escape_one_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
cmp    $0xc,%eax
jne    1154 <__escape_one_char+0x34>
mov    -0x8(%rbp),%rdi
lea    0xeb6(%rip),%rsi
call   1030 <stringbuf_puts@plt>
jmp    11ef <__escape_one_char+0xcf>
movzbl -0x9(%rbp),%eax
cmp    $0xb,%eax
jne    1176 <__escape_one_char+0x56>
mov    -0x8(%rbp),%rdi
lea    0xe97(%rip),%rsi
call   1030 <stringbuf_puts@plt>
jmp    11ea <__escape_one_char+0xca>
movzbl -0x9(%rbp),%eax
cmp    $0xd,%eax
jne    1198 <__escape_one_char+0x78>
mov    -0x8(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1030 <stringbuf_puts@plt>
jmp    11e5 <__escape_one_char+0xc5>
movzbl -0x9(%rbp),%eax
cmp    $0x0,%eax
jne    11ba <__escape_one_char+0x9a>
mov    -0x8(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1030 <stringbuf_puts@plt>
jmp    11e0 <__escape_one_char+0xc0>
lea    -0xf(%rbp),%rdi
mov    $0x6,%esi
lea    0xe42(%rip),%rdx
movzbl -0x9(%rbp),%ecx
call   1040 <snprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0xf(%rbp),%rsi
call   1030 <stringbuf_puts@plt>
jmp    11e5 <__escape_one_char+0xc5>
jmp    11ea <__escape_one_char+0xca>
jmp    11ef <__escape_one_char+0xcf>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__escape_one_char>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
cmp    $0xd,%sil
ja     1148 <__escape_one_char+0x28>
mov    %esi,%eax
lea    0xeca(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xefb(%rip),%rsi
jmp    1191 <__escape_one_char+0x71>
movzbl %sil,%ecx
lea    0xef1(%rip),%rdx
lea    0x2(%rsp),%r14
mov    %r14,%rdi
mov    $0x6,%esi
call   1040 <snprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <stringbuf_puts@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xebc(%rip),%rsi
jmp    1191 <__escape_one_char+0x71>
lea    0xeb0(%rip),%rsi
jmp    1191 <__escape_one_char+0x71>
lea    0xead(%rip),%rsi
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <stringbuf_puts@plt>

LLVM IR (-O0):
%struct.stringbuf = type { i32 }
@.str = [3 x i8] c"\\f\00"
@.str.1 = [3 x i8] c"\\v\00"
@.str.2 = [3 x i8] c"\\r\00"
@.str.3 = [3 x i8] c"\\0\00"
@.str.4 = [6 x i8] c"\\%03o\00"
define void @__escape_one_char(%struct.stringbuf* %0, i8 zeroext %1) {
%3 = alloca %struct.stringbuf*
%4 = alloca i8
%5 = alloca [6 x i8]
store %struct.stringbuf* %0, %struct.stringbuf** %3
store i8 %1, i8* %4
%6 = load i8, i8* %4
%7 = zext i8 %6 to i32
%8 = icmp eq i32 %7, 12
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load %struct.stringbuf*, %struct.stringbuf** %3
%11 = call i32 @stringbuf_puts(%struct.stringbuf* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %43
12: ; preds = %2
%13 = load i8, i8* %4
%14 = zext i8 %13 to i32
%15 = icmp eq i32 %14, 11
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load %struct.stringbuf*, %struct.stringbuf** %3
%18 = call i32 @stringbuf_puts(%struct.stringbuf* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %42
19: ; preds = %12
%20 = load i8, i8* %4
%21 = zext i8 %20 to i32
%22 = icmp eq i32 %21, 13
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load %struct.stringbuf*, %struct.stringbuf** %3
%25 = call i32 @stringbuf_puts(%struct.stringbuf* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %41
26: ; preds = %19
%27 = load i8, i8* %4
%28 = zext i8 %27 to i32
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load %struct.stringbuf*, %struct.stringbuf** %3
%32 = call i32 @stringbuf_puts(%struct.stringbuf* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %40
33: ; preds = %26
%34 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%35 = load i8, i8* %4
%36 = call i32 @snprintf(i8* %34, i32 6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %35)
%37 = load %struct.stringbuf*, %struct.stringbuf** %3
%38 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%39 = call i32 @stringbuf_puts(%struct.stringbuf* %37, i8* %38)
br label %40
40: ; preds = %33, %30
br label %41
41: ; preds = %40, %23
br label %42
42: ; preds = %41, %16
br label %43
43: ; preds = %42, %9
ret void
}

LLVM IR (-O2):
%struct.stringbuf = type { i32 }
@.str = [3 x i8] c"\\f\00"
@.str.1 = [3 x i8] c"\\v\00"
@.str.2 = [3 x i8] c"\\r\00"
@.str.3 = [3 x i8] c"\\0\00"
@.str.4 = [6 x i8] c"\\%03o\00"
define void @__escape_one_char(%struct.stringbuf* %0, i8 zeroext %1) {
%3 = alloca [6 x i8]
%4 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
switch i8 %1, label %13 [
i8 12, label %5
i8 11, label %7
i8 13, label %9
i8 0, label %11
]
5: ; preds = %2
%6 = tail call i32 @stringbuf_puts(%struct.stringbuf* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %16
7: ; preds = %2
%8 = tail call i32 @stringbuf_puts(%struct.stringbuf* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %16
9: ; preds = %2
%10 = tail call i32 @stringbuf_puts(%struct.stringbuf* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %16
11: ; preds = %2
%12 = tail call i32 @stringbuf_puts(%struct.stringbuf* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %16
13: ; preds = %2
%14 = call i32 @snprintf(i8* %4, i32 6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %1)
%15 = call i32 @stringbuf_puts(%struct.stringbuf* %0, i8* %4)
br label %16
16: ; preds = %7, %11, %13, %9, %5
ret void
}