#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 EOF;
int fprintf(int /*<<< orphan*/ *, char *, unsigned char);
int /*<<< orphan*/ isascii(int);
scalar_t__ isprint(int);
int putc(char const, int /*<<< orphan*/ *);
int fputc_careful(int c, FILE *fp, const char fail) {
  int ret;
  if (isprint(c) || c == '\a' || c == '\t' || c == '\r' || c == '\n')
    ret = putc(c, fp);
  else if (!isascii(c))
    ret = fprintf(fp, "\\%3o", (unsigned char)c);
  else {
    ret = putc(fail, fp);
    if (ret != EOF)
      ret = putc(c ^ 0x40, fp);
  }
  return (ret < 0) ? EOF : 0;
}


x86 assembly (clang, -O0):
<fputc_careful>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <isprint@plt>
cmp    $0x0,%rax
jne    118e <fputc_careful+0x4e>
cmpl   $0x7,-0x4(%rbp)
je     118e <fputc_careful+0x4e>
cmpl   $0x9,-0x4(%rbp)
je     118e <fputc_careful+0x4e>
cmpl   $0xd,-0x4(%rbp)
je     118e <fputc_careful+0x4e>
cmpl   $0xa,-0x4(%rbp)
jne    11a5 <fputc_careful+0x65>
mov    -0x4(%rbp),%eax
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1030 <putc@plt>
mov    %eax,-0x18(%rbp)
jmp    1217 <fputc_careful+0xd7>
mov    -0x4(%rbp),%edi
call   1060 <isascii@plt>
cmp    $0x0,%eax
jne    11d4 <fputc_careful+0x94>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%eax
lea    0xe3c(%rip),%rsi
movzbl %al,%edx
call   1040 <fprintf@plt>
mov    %eax,-0x18(%rbp)
jmp    1212 <fputc_careful+0xd2>
mov    -0x11(%rbp),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1030 <putc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2df8(%rip),%rcx
cmp    (%rcx),%eax
je     120d <fputc_careful+0xcd>
mov    -0x4(%rbp),%eax
xor    $0x40,%eax
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1030 <putc@plt>
mov    %eax,-0x18(%rbp)
jmp    1212 <fputc_careful+0xd2>
jmp    1217 <fputc_careful+0xd7>
cmpl   $0x0,-0x18(%rbp)
jge    1232 <fputc_careful+0xf2>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    123c <fputc_careful+0xfc>
xor    %eax,%eax
mov    %eax,-0x1c(%rbp)
jmp    123c <fputc_careful+0xfc>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fputc_careful>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
call   1050 <isprint@plt>
test   %rax,%rax
jne    1155 <fputc_careful+0x25>
cmp    $0xd,%ebp
ja     1172 <fputc_careful+0x42>
mov    $0x2680,%eax
bt     %ebp,%eax
jae    1172 <fputc_careful+0x42>
movsbl %bpl,%edi
mov    %rbx,%rsi
call   1030 <putc@plt>
mov    0x2e80(%rip),%rcx
sar    $0x1f,%eax
and    (%rcx),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
cmp    $0x80,%ebp
jae    1197 <fputc_careful+0x67>
movsbl %r14b,%edi
mov    %rbx,%rsi
call   1030 <putc@plt>
mov    0x2e5b(%rip),%rcx
cmp    (%rcx),%eax
je     1161 <fputc_careful+0x31>
xor    $0x40,%bpl
jmp    1155 <fputc_careful+0x25>
movzbl %bpl,%edx
lea    0xe5e(%rip),%rsi
mov    %rbx,%rdi
call   1040 <fprintf@plt>
jmp    1161 <fputc_careful+0x31>

LLVM IR (-O0):
@.str = [5 x i8] c"\\%3o\00"
@EOF = global i32 0
define i32 @fputc_careful(i32 %0, i32* %1, i8 signext %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8
%7 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i8 %2, i8* %6
%8 = load i32, i32* %4
%9 = call i64 @isprint(i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %23, label %11
11: ; preds = %3
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 7
br i1 %13, label %23, label %14
14: ; preds = %11
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 9
br i1 %16, label %23, label %17
17: ; preds = %14
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 13
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 10
br i1 %22, label %23, label %28
23: ; preds = %20, %17, %14, %11, %3
%24 = load i32, i32* %4
%25 = trunc i32 %24 to i8
%26 = load i32*, i32** %5
%27 = call i32 @putc(i8 signext %25, i32* %26)
store i32 %27, i32* %7
br label %52
28: ; preds = %20
%29 = load i32, i32* %4
%30 = call i32 @isascii(i32 %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %37, label %32
32: ; preds = %28
%33 = load i32*, i32** %5
%34 = load i32, i32* %4
%35 = trunc i32 %34 to i8
%36 = call i32 @fprintf(i32* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %35)
store i32 %36, i32* %7
br label %51
37: ; preds = %28
%38 = load i8, i8* %6
%39 = load i32*, i32** %5
%40 = call i32 @putc(i8 signext %38, i32* %39)
store i32 %40, i32* %7
%41 = load i32, i32* %7
%42 = load i32, i32* @EOF
%43 = icmp ne i32 %41, %42
br i1 %43, label %44, label %50
44: ; preds = %37
%45 = load i32, i32* %4
%46 = xor i32 %45, 64
%47 = trunc i32 %46 to i8
%48 = load i32*, i32** %5
%49 = call i32 @putc(i8 signext %47, i32* %48)
store i32 %49, i32* %7
br label %50
50: ; preds = %44, %37
br label %51
51: ; preds = %50, %32
br label %52
52: ; preds = %51, %23
%53 = load i32, i32* %7
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = load i32, i32* @EOF
br label %58
57: ; preds = %52
br label %58
58: ; preds = %57, %55
%59 = phi i32 [ %56, %55 ], [ 0, %57 ]
ret i32 %59
}

LLVM IR (-O2):
@.str = [5 x i8] c"\\%3o\00"
@EOF = global i32 0
define i32 @fputc_careful(i32 %0, i32* nocapture %1, i8 signext %2) {
%4 = tail call i64 @isprint(i32 %0)
%5 = freeze i64 %4
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %3
switch i32 %0, label %11 [
i32 13, label %8
i32 10, label %8
i32 9, label %8
i32 7, label %8
]
8: ; preds = %7, %7, %7, %7, %3
%9 = trunc i32 %0 to i8
%10 = tail call i32 @putc(i8 signext %9, i32* %1)
br label %24
11: ; preds = %7
%12 = icmp ult i32 %0, 128
br i1 %12, label %16, label %13
13: ; preds = %11
%14 = trunc i32 %0 to i8
%15 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %14)
br label %24
16: ; preds = %11
%17 = tail call i32 @putc(i8 signext %2, i32* %1)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = trunc i32 %0 to i8
%22 = xor i8 %21, 64
%23 = tail call i32 @putc(i8 signext %22, i32* %1)
br label %24
24: ; preds = %13, %20, %16, %8
%25 = phi i32 [ %10, %8 ], [ %23, %20 ], [ %17, %16 ], [ %15, %13 ]
%26 = icmp slt i32 %25, 0
%27 = load i32, i32* @EOF
%28 = select i1 %26, i32 %27, i32 0
ret i32 %28
}