#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, unsigned int);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
scalar_t__ isalnum(char);
void write_escaped_char(FILE *out, char c) {
  if (isalnum(c)) {
    fputc(c, out);
    return;
  }
  switch (c) {
  case ' ':
  case '_':
    fputc(c, out);
    break;
  case '\n':
    fputs("\\n", out);
    break;
  case '\r':
    fputs("\\r", out);
    break;
  case '\t':
    fputs("\\t", out);
    break;
  default:
    fprintf(out, "\\x%02X", (unsigned int)(unsigned char)c);
    break;
  }
}


x86 assembly (clang, -O0):
<write_escaped_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%rax
je     1179 <write_escaped_char+0x39>
mov    -0x9(%rbp),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
jmp    1239 <write_escaped_char+0xf9>
movsbl -0x9(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x9,%eax
je     1210 <write_escaped_char+0xd0>
jmp    118e <write_escaped_char+0x4e>
mov    -0x10(%rbp),%eax
sub    $0xa,%eax
je     11e6 <write_escaped_char+0xa6>
jmp    119f <write_escaped_char+0x5f>
mov    -0x10(%rbp),%eax
sub    $0xd,%eax
je     11fb <write_escaped_char+0xbb>
jmp    11b0 <write_escaped_char+0x70>
mov    -0x10(%rbp),%eax
sub    $0x20,%eax
je     11d2 <write_escaped_char+0x92>
jmp    11c1 <write_escaped_char+0x81>
mov    -0x10(%rbp),%eax
sub    $0x5f,%eax
jne    1225 <write_escaped_char+0xe5>
jmp    11d2 <write_escaped_char+0x92>
mov    -0x9(%rbp),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
jmp    1239 <write_escaped_char+0xf9>
mov    -0x8(%rbp),%rsi
lea    0xe0f(%rip),%rdi
call   1040 <fputs@plt>
jmp    1239 <write_escaped_char+0xf9>
mov    -0x8(%rbp),%rsi
lea    0xdfd(%rip),%rdi
call   1040 <fputs@plt>
jmp    1239 <write_escaped_char+0xf9>
mov    -0x8(%rbp),%rsi
lea    0xdeb(%rip),%rdi
call   1040 <fputs@plt>
jmp    1239 <write_escaped_char+0xf9>
mov    -0x8(%rbp),%rdi
movzbl -0x9(%rbp),%edx
lea    0xdd5(%rip),%rsi
call   1060 <fprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_escaped_char>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %esi,%edi
call   1030 <isalnum@plt>
test   %rax,%rax
je     1166 <write_escaped_char+0x26>
movsbl %bpl,%edi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <fputc@plt>
movsbl %bpl,%edi
lea    -0x9(%rdi),%eax
cmp    $0x17,%eax
ja     118b <write_escaped_char+0x4b>
lea    0xe87(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xedd(%rip),%rdi
jmp    11bb <write_escaped_char+0x7b>
cmp    $0x5f,%edi
jne    1192 <write_escaped_char+0x52>
jmp    1158 <write_escaped_char+0x18>
movzbl %bpl,%edx
lea    0xecc(%rip),%rsi
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <fprintf@plt>
lea    0xeae(%rip),%rdi
jmp    11bb <write_escaped_char+0x7b>
lea    0xea8(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <fwrite@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"\\n\00"
@.str.1 = [3 x i8] c"\\r\00"
@.str.2 = [3 x i8] c"\\t\00"
@.str.3 = [7 x i8] c"\\x%02X\00"
define void @write_escaped_char(i32* %0, i8 signext %1) {
%3 = alloca i32*
%4 = alloca i8
store i32* %0, i32** %3
store i8 %1, i8* %4
%5 = load i8, i8* %4
%6 = call i64 @isalnum(i8 signext %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i8, i8* %4
%10 = load i32*, i32** %3
%11 = call i32 @fputc(i8 signext %9, i32* %10)
br label %33
12: ; preds = %2
%13 = load i8, i8* %4
%14 = sext i8 %13 to i32
switch i32 %14, label %28 [
i32 32, label %15
i32 95, label %15
i32 10, label %19
i32 13, label %22
i32 9, label %25
]
15: ; preds = %12, %12
%16 = load i8, i8* %4
%17 = load i32*, i32** %3
%18 = call i32 @fputc(i8 signext %16, i32* %17)
br label %33
19: ; preds = %12
%20 = load i32*, i32** %3
%21 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %20)
br label %33
22: ; preds = %12
%23 = load i32*, i32** %3
%24 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %23)
br label %33
25: ; preds = %12
%26 = load i32*, i32** %3
%27 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %26)
br label %33
28: ; preds = %12
%29 = load i32*, i32** %3
%30 = load i8, i8* %4
%31 = zext i8 %30 to i32
%32 = call i32 @fprintf(i32* %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %8, %28, %25, %22, %19, %15
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"\\n\00"
@.str.1 = [3 x i8] c"\\r\00"
@.str.2 = [3 x i8] c"\\t\00"
@.str.3 = [7 x i8] c"\\x%02X\00"
define void @write_escaped_char(i32* nocapture %0, i8 signext %1) {
%3 = tail call i64 @isalnum(i8 signext %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @fputc(i8 signext %1, i32* %0)
br label %20
7: ; preds = %2
%8 = sext i8 %1 to i32
switch i32 %8, label %17 [
i32 32, label %9
i32 95, label %9
i32 10, label %11
i32 13, label %13
i32 9, label %15
]
9: ; preds = %7, %7
%10 = tail call i32 @fputc(i8 signext %1, i32* %0)
br label %20
11: ; preds = %7
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64 2, i64 1, i32* %0)
br label %20
13: ; preds = %7
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64 2, i64 1, i32* %0)
br label %20
15: ; preds = %7
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64 2, i64 1, i32* %0)
br label %20
17: ; preds = %7
%18 = zext i8 %1 to i32
%19 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %5, %17, %15, %13, %11, %9
ret void
}