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

/* Variables and functions */
int EOF;
int fprintf(int /*<<< orphan*/ *, char *, unsigned char);
scalar_t__ isprint(int);
scalar_t__ isspace(int);
int putc(char const, int /*<<< orphan*/ *);
int fputc_careful(int c, FILE *fp, const char fail) {
  int ret;
  if (c == '\007' || c == '\t' || c == '\r' || c == '\n' ||
      (!(((c)&0x7f) < 0x20 || (c) == 0x7f) && (isprint(c) || isspace(c))))
    ret = putc(c, fp);
  else if ((c & 0x80) || !isprint(c ^ 0x40))
    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)
cmpl   $0x7,-0x4(%rbp)
je     11b9 <fputc_careful+0x79>
cmpl   $0x9,-0x4(%rbp)
je     11b9 <fputc_careful+0x79>
cmpl   $0xd,-0x4(%rbp)
je     11b9 <fputc_careful+0x79>
cmpl   $0xa,-0x4(%rbp)
je     11b9 <fputc_careful+0x79>
mov    -0x4(%rbp),%eax
and    $0x7f,%eax
cmp    $0x20,%eax
jl     11d0 <fputc_careful+0x90>
cmpl   $0x7f,-0x4(%rbp)
je     11d0 <fputc_careful+0x90>
mov    -0x4(%rbp),%edi
call   1060 <isprint@plt>
cmp    $0x0,%rax
jne    11b9 <fputc_careful+0x79>
mov    -0x4(%rbp),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     11d0 <fputc_careful+0x90>
mov    -0x4(%rbp),%eax
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1040 <putc@plt>
mov    %eax,-0x18(%rbp)
jmp    1257 <fputc_careful+0x117>
mov    -0x4(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    11f6 <fputc_careful+0xb6>
mov    -0x4(%rbp),%edi
xor    $0x40,%edi
call   1060 <isprint@plt>
cmp    $0x0,%rax
jne    1214 <fputc_careful+0xd4>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%eax
lea    0xdfc(%rip),%rsi
movzbl %al,%edx
call   1050 <fprintf@plt>
mov    %eax,-0x18(%rbp)
jmp    1252 <fputc_careful+0x112>
mov    -0x11(%rbp),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1040 <putc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2db8(%rip),%rcx
cmp    (%rcx),%eax
je     124d <fputc_careful+0x10d>
mov    -0x4(%rbp),%eax
xor    $0x40,%eax
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1040 <putc@plt>
mov    %eax,-0x18(%rbp)
jmp    1252 <fputc_careful+0x112>
jmp    1257 <fputc_careful+0x117>
cmpl   $0x0,-0x18(%rbp)
jge    1272 <fputc_careful+0x132>
mov    0x2d80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    127c <fputc_careful+0x13c>
xor    %eax,%eax
mov    %eax,-0x1c(%rbp)
jmp    127c <fputc_careful+0x13c>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fputc_careful>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
cmp    $0xd,%edi
ja     1181 <fputc_careful+0x41>
mov    $0x2680,%eax
bt     %ebp,%eax
jae    1181 <fputc_careful+0x41>
movsbl %bpl,%edi
mov    %rbx,%rsi
call   1040 <putc@plt>
mov    0x2e77(%rip),%rcx
sar    $0x1f,%eax
and    (%rcx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0x7f,%ebp
je     11a5 <fputc_careful+0x65>
mov    %ebp,%eax
and    $0x60,%eax
je     11a5 <fputc_careful+0x65>
mov    %ebp,%edi
call   1060 <isprint@plt>
test   %rax,%rax
jne    115e <fputc_careful+0x1e>
mov    %ebp,%edi
call   1030 <isspace@plt>
test   %rax,%rax
jne    115e <fputc_careful+0x1e>
test   $0x80,%bpl
jne    11dc <fputc_careful+0x9c>
mov    %ebp,%r15d
xor    $0x40,%r15d
mov    %r15d,%edi
call   1060 <isprint@plt>
test   %rax,%rax
je     11dc <fputc_careful+0x9c>
movsbl %r14b,%edi
mov    %rbx,%rsi
call   1040 <putc@plt>
mov    0x2e16(%rip),%rcx
cmp    (%rcx),%eax
je     116a <fputc_careful+0x2a>
movsbl %r15b,%edi
jmp    1162 <fputc_careful+0x22>
movzbl %bpl,%edx
lea    0xe19(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fprintf@plt>
jmp    116a <fputc_careful+0x2a>

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 = icmp eq i32 %8, 7
br i1 %9, label %34, label %10
10: ; preds = %3
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 9
br i1 %12, label %34, label %13
13: ; preds = %10
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 13
br i1 %15, label %34, label %16
16: ; preds = %13
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 10
br i1 %18, label %34, label %19
19: ; preds = %16
%20 = load i32, i32* %4
%21 = and i32 %20, 127
%22 = icmp slt i32 %21, 32
br i1 %22, label %39, label %23
23: ; preds = %19
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 127
br i1 %25, label %39, label %26
26: ; preds = %23
%27 = load i32, i32* %4
%28 = call i64 @isprint(i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %26
%31 = load i32, i32* %4
%32 = call i64 @isspace(i32 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %30, %26, %16, %13, %10, %3
%35 = load i32, i32* %4
%36 = trunc i32 %35 to i8
%37 = load i32*, i32** %5
%38 = call i32 @putc(i8 signext %36, i32* %37)
store i32 %38, i32* %7
br label %68
39: ; preds = %30, %23, %19
%40 = load i32, i32* %4
%41 = and i32 %40, 128
%42 = icmp ne i32 %41, 0
br i1 %42, label %48, label %43
43: ; preds = %39
%44 = load i32, i32* %4
%45 = xor i32 %44, 64
%46 = call i64 @isprint(i32 %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %53, label %48
48: ; preds = %43, %39
%49 = load i32*, i32** %5
%50 = load i32, i32* %4
%51 = trunc i32 %50 to i8
%52 = call i32 @fprintf(i32* %49, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %51)
store i32 %52, i32* %7
br label %67
53: ; preds = %43
%54 = load i8, i8* %6
%55 = load i32*, i32** %5
%56 = call i32 @putc(i8 signext %54, i32* %55)
store i32 %56, i32* %7
%57 = load i32, i32* %7
%58 = load i32, i32* @EOF
%59 = icmp ne i32 %57, %58
br i1 %59, label %60, label %66
60: ; preds = %53
%61 = load i32, i32* %4
%62 = xor i32 %61, 64
%63 = trunc i32 %62 to i8
%64 = load i32*, i32** %5
%65 = call i32 @putc(i8 signext %63, i32* %64)
store i32 %65, i32* %7
br label %66
66: ; preds = %60, %53
br label %67
67: ; preds = %66, %48
br label %68
68: ; preds = %67, %34
%69 = load i32, i32* %7
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %68
%72 = load i32, i32* @EOF
br label %74
73: ; preds = %68
br label %74
74: ; preds = %73, %71
%75 = phi i32 [ %72, %71 ], [ 0, %73 ]
ret i32 %75
}

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) {
switch i32 %0, label %4 [
i32 13, label %15
i32 10, label %15
i32 9, label %15
i32 7, label %15
]
4: ; preds = %3
%5 = and i32 %0, 96
%6 = icmp eq i32 %5, 0
%7 = icmp eq i32 %0, 127
%8 = or i1 %7, %6
br i1 %8, label %18, label %9
9: ; preds = %4
%10 = tail call i64 @isprint(i32 %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = tail call i64 @isspace(i32 %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %3, %3, %3, %3, %12, %9
%16 = trunc i32 %0 to i8
%17 = tail call i32 @putc(i8 signext %16, i32* %1)
br label %35
18: ; preds = %12, %4
%19 = and i32 %0, 128
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = xor i32 %0, 64
%23 = tail call i64 @isprint(i32 %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21, %18
%26 = trunc i32 %0 to i8
%27 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %26)
br label %35
28: ; preds = %21
%29 = tail call i32 @putc(i8 signext %2, i32* %1)
%30 = load i32, i32* @EOF
%31 = icmp eq i32 %29, %30
br i1 %31, label %35, label %32
32: ; preds = %28
%33 = trunc i32 %22 to i8
%34 = tail call i32 @putc(i8 signext %33, i32* %1)
br label %35
35: ; preds = %25, %32, %28, %15
%36 = phi i32 [ %17, %15 ], [ %27, %25 ], [ %34, %32 ], [ %29, %28 ]
%37 = icmp slt i32 %36, 0
%38 = load i32, i32* @EOF
%39 = select i1 %37, i32 %38, i32 0
ret i32 %39
}