#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 buffer {
  int dummy;
};

/* Variables and functions */
int buffer_append(struct buffer *, char);
int buffer_append_str(struct buffer *, char *, int);
int encode_nonprint(struct buffer *, char);
int /*<<< orphan*/ isprint(char);
int encode_character(struct buffer *output, char c) {
  switch (c) {
  case '\b':
    return buffer_append_str(output, "\\b", 2);
  case '\f':
    return buffer_append_str(output, "\\f", 2);
  case '\n':
    return buffer_append_str(output, "\\n", 2);
  case '\r':
    return buffer_append_str(output, "\\r", 2);
  case '\t':
    return buffer_append_str(output, "\\t", 2);
  case '\\':
    return buffer_append_str(output, "\\\\", 2);
  case '"':
    return buffer_append_str(output, "\\\"", 2);
  default:
    return isprint(c) ? buffer_append(output, c) : encode_nonprint(output, c);
  }
}


x86 assembly (clang, -O0):
<encode_character>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x8,%eax
je     11cd <encode_character+0x8d>
jmp    1167 <encode_character+0x27>
mov    -0x18(%rbp),%eax
sub    $0x9,%eax
je     1241 <encode_character+0x101>
jmp    1178 <encode_character+0x38>
mov    -0x18(%rbp),%eax
sub    $0xa,%eax
je     1207 <encode_character+0xc7>
jmp    1189 <encode_character+0x49>
mov    -0x18(%rbp),%eax
sub    $0xc,%eax
je     11ea <encode_character+0xaa>
jmp    119a <encode_character+0x5a>
mov    -0x18(%rbp),%eax
sub    $0xd,%eax
je     1224 <encode_character+0xe4>
jmp    11ab <encode_character+0x6b>
mov    -0x18(%rbp),%eax
sub    $0x22,%eax
je     127b <encode_character+0x13b>
jmp    11bc <encode_character+0x7c>
mov    -0x18(%rbp),%eax
sub    $0x5c,%eax
je     125e <encode_character+0x11e>
jmp    1298 <encode_character+0x158>
mov    -0x10(%rbp),%rdi
lea    0xe28(%rip),%rsi
mov    $0x2,%edx
call   1030 <buffer_append_str@plt>
mov    %eax,-0x4(%rbp)
jmp    12d5 <encode_character+0x195>
mov    -0x10(%rbp),%rdi
lea    0xe0e(%rip),%rsi
mov    $0x2,%edx
call   1030 <buffer_append_str@plt>
mov    %eax,-0x4(%rbp)
jmp    12d5 <encode_character+0x195>
mov    -0x10(%rbp),%rdi
lea    0xdf4(%rip),%rsi
mov    $0x2,%edx
call   1030 <buffer_append_str@plt>
mov    %eax,-0x4(%rbp)
jmp    12d5 <encode_character+0x195>
mov    -0x10(%rbp),%rdi
lea    0xdda(%rip),%rsi
mov    $0x2,%edx
call   1030 <buffer_append_str@plt>
mov    %eax,-0x4(%rbp)
jmp    12d5 <encode_character+0x195>
mov    -0x10(%rbp),%rdi
lea    0xdc0(%rip),%rsi
mov    $0x2,%edx
call   1030 <buffer_append_str@plt>
mov    %eax,-0x4(%rbp)
jmp    12d5 <encode_character+0x195>
mov    -0x10(%rbp),%rdi
lea    0xda6(%rip),%rsi
mov    $0x2,%edx
call   1030 <buffer_append_str@plt>
mov    %eax,-0x4(%rbp)
jmp    12d5 <encode_character+0x195>
mov    -0x10(%rbp),%rdi
lea    0xd8c(%rip),%rsi
mov    $0x2,%edx
call   1030 <buffer_append_str@plt>
mov    %eax,-0x4(%rbp)
jmp    12d5 <encode_character+0x195>
movsbl -0x11(%rbp),%edi
call   1060 <isprint@plt>
cmp    $0x0,%eax
je     12bf <encode_character+0x17f>
mov    -0x10(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1050 <buffer_append@plt>
mov    %eax,-0x1c(%rbp)
jmp    12cf <encode_character+0x18f>
mov    -0x10(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1040 <encode_nonprint@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encode_character>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    -0x8(%rsi),%eax
cmp    $0x1a,%eax
ja     1167 <encode_character+0x27>
lea    0xeab(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xf07(%rip),%rsi
jmp    11bf <encode_character+0x7f>
cmp    $0x5c,%esi
jne    1175 <encode_character+0x35>
lea    0xf08(%rip),%rsi
jmp    11bf <encode_character+0x7f>
movsbl %sil,%ebp
mov    %ebp,%edi
call   1060 <isprint@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
add    $0x8,%rsp
test   %eax,%eax
je     11d2 <encode_character+0x92>
pop    %rbx
pop    %rbp
jmp    1050 <buffer_append@plt>
lea    0xedd(%rip),%rsi
jmp    11bf <encode_character+0x7f>
lea    0xece(%rip),%rsi
jmp    11bf <encode_character+0x7f>
lea    0xec2(%rip),%rsi
jmp    11bf <encode_character+0x7f>
lea    0xebf(%rip),%rsi
jmp    11bf <encode_character+0x7f>
lea    0xebf(%rip),%rsi
mov    %rbx,%rdi
mov    $0x2,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <buffer_append_str@plt>
pop    %rbx
pop    %rbp
jmp    1040 <encode_nonprint@plt>

LLVM IR (-O0):
%struct.buffer = type { i32 }
@.str = [3 x i8] c"\\b\00"
@.str.1 = [3 x i8] c"\\f\00"
@.str.2 = [3 x i8] c"\\n\00"
@.str.3 = [3 x i8] c"\\r\00"
@.str.4 = [3 x i8] c"\\t\00"
@.str.5 = [3 x i8] c"\\\\\00"
@.str.6 = [3 x i8] c"\\\22\00"
define i32 @encode_character(%struct.buffer* %0, i8 signext %1) {
%3 = alloca i32
%4 = alloca %struct.buffer*
%5 = alloca i8
store %struct.buffer* %0, %struct.buffer** %4
store i8 %1, i8* %5
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
switch i32 %7, label %29 [
i32 8, label %8
i32 12, label %11
i32 10, label %14
i32 13, label %17
i32 9, label %20
i32 92, label %23
i32 34, label %26
]
8: ; preds = %2
%9 = load %struct.buffer*, %struct.buffer** %4
%10 = call i32 @buffer_append_str(%struct.buffer* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
store i32 %10, i32* %3
br label %43
11: ; preds = %2
%12 = load %struct.buffer*, %struct.buffer** %4
%13 = call i32 @buffer_append_str(%struct.buffer* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
store i32 %13, i32* %3
br label %43
14: ; preds = %2
%15 = load %struct.buffer*, %struct.buffer** %4
%16 = call i32 @buffer_append_str(%struct.buffer* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
store i32 %16, i32* %3
br label %43
17: ; preds = %2
%18 = load %struct.buffer*, %struct.buffer** %4
%19 = call i32 @buffer_append_str(%struct.buffer* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
store i32 %19, i32* %3
br label %43
20: ; preds = %2
%21 = load %struct.buffer*, %struct.buffer** %4
%22 = call i32 @buffer_append_str(%struct.buffer* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
store i32 %22, i32* %3
br label %43
23: ; preds = %2
%24 = load %struct.buffer*, %struct.buffer** %4
%25 = call i32 @buffer_append_str(%struct.buffer* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
store i32 %25, i32* %3
br label %43
26: ; preds = %2
%27 = load %struct.buffer*, %struct.buffer** %4
%28 = call i32 @buffer_append_str(%struct.buffer* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 2)
store i32 %28, i32* %3
br label %43
29: ; preds = %2
%30 = load i8, i8* %5
%31 = call i32 @isprint(i8 signext %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load %struct.buffer*, %struct.buffer** %4
%35 = load i8, i8* %5
%36 = call i32 @buffer_append(%struct.buffer* %34, i8 signext %35)
br label %41
37: ; preds = %29
%38 = load %struct.buffer*, %struct.buffer** %4
%39 = load i8, i8* %5
%40 = call i32 @encode_nonprint(%struct.buffer* %38, i8 signext %39)
br label %41
41: ; preds = %37, %33
%42 = phi i32 [ %36, %33 ], [ %40, %37 ]
store i32 %42, i32* %3
br label %43
43: ; preds = %41, %26, %23, %20, %17, %14, %11, %8
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
%struct.buffer = type { i32 }
@.str = [3 x i8] c"\\b\00"
@.str.1 = [3 x i8] c"\\f\00"
@.str.2 = [3 x i8] c"\\n\00"
@.str.3 = [3 x i8] c"\\r\00"
@.str.4 = [3 x i8] c"\\t\00"
@.str.5 = [3 x i8] c"\\\\\00"
@.str.6 = [3 x i8] c"\\\22\00"
define i32 @encode_character(%struct.buffer* %0, i8 signext %1) {
%3 = sext i8 %1 to i32
switch i32 %3, label %18 [
i32 8, label %4
i32 12, label %6
i32 10, label %8
i32 13, label %10
i32 9, label %12
i32 92, label %14
i32 34, label %16
]
4: ; preds = %2
%5 = tail call i32 @buffer_append_str(%struct.buffer* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
br label %25
6: ; preds = %2
%7 = tail call i32 @buffer_append_str(%struct.buffer* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
br label %25
8: ; preds = %2
%9 = tail call i32 @buffer_append_str(%struct.buffer* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
br label %25
10: ; preds = %2
%11 = tail call i32 @buffer_append_str(%struct.buffer* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
br label %25
12: ; preds = %2
%13 = tail call i32 @buffer_append_str(%struct.buffer* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
br label %25
14: ; preds = %2
%15 = tail call i32 @buffer_append_str(%struct.buffer* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
br label %25
16: ; preds = %2
%17 = tail call i32 @buffer_append_str(%struct.buffer* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 2)
br label %25
18: ; preds = %2
%19 = tail call i32 @isprint(i8 signext %1)
%20 = icmp eq i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = tail call i32 @buffer_append(%struct.buffer* %0, i8 signext %1)
br label %25
23: ; preds = %18
%24 = tail call i32 @encode_nonprint(%struct.buffer* %0, i8 signext %1)
br label %25
25: ; preds = %21, %23, %16, %14, %12, %10, %8, %6, %4
%26 = phi i32 [ %17, %16 ], [ %15, %14 ], [ %13, %12 ], [ %11, %10 ], [ %9, %8 ], [ %7, %6 ], [ %5, %4 ], [ %22, %21 ], [ %24, %23 ]
ret i32 %26
}