#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(int, int /*<<< orphan*/ *);
int carefulputc(int c, FILE *fp) {
  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('^', fp);
    if (ret != EOF)
      ret = putc(c ^ 0x40, fp);
  }
  return (ret < 0) ? EOF : 0;
}


x86 assembly (clang, -O0):
<carefulputc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x7,-0x4(%rbp)
je     11b4 <carefulputc+0x74>
cmpl   $0x9,-0x4(%rbp)
je     11b4 <carefulputc+0x74>
cmpl   $0xd,-0x4(%rbp)
je     11b4 <carefulputc+0x74>
cmpl   $0xa,-0x4(%rbp)
je     11b4 <carefulputc+0x74>
mov    -0x4(%rbp),%eax
and    $0x7f,%eax
cmp    $0x20,%eax
jl     11c8 <carefulputc+0x88>
cmpl   $0x7f,-0x4(%rbp)
je     11c8 <carefulputc+0x88>
mov    -0x4(%rbp),%edi
call   1060 <isprint@plt>
cmp    $0x0,%rax
jne    11b4 <carefulputc+0x74>
mov    -0x4(%rbp),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     11c8 <carefulputc+0x88>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <putc@plt>
mov    %eax,-0x14(%rbp)
jmp    124b <carefulputc+0x10b>
mov    -0x4(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    11ee <carefulputc+0xae>
mov    -0x4(%rbp),%edi
xor    $0x40,%edi
call   1060 <isprint@plt>
cmp    $0x0,%rax
jne    120c <carefulputc+0xcc>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%eax
lea    0xe04(%rip),%rsi
movzbl %al,%edx
call   1050 <fprintf@plt>
mov    %eax,-0x14(%rbp)
jmp    1246 <carefulputc+0x106>
mov    -0x10(%rbp),%rsi
mov    $0x5e,%edi
call   1040 <putc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2dc1(%rip),%rcx
cmp    (%rcx),%eax
je     1241 <carefulputc+0x101>
mov    -0x4(%rbp),%edi
xor    $0x40,%edi
mov    -0x10(%rbp),%rsi
call   1040 <putc@plt>
mov    %eax,-0x14(%rbp)
jmp    1246 <carefulputc+0x106>
jmp    124b <carefulputc+0x10b>
cmpl   $0x0,-0x14(%rbp)
jge    1266 <carefulputc+0x126>
mov    0x2d8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1270 <carefulputc+0x130>
xor    %eax,%eax
mov    %eax,-0x18(%rbp)
jmp    1270 <carefulputc+0x130>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<carefulputc>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
cmp    $0xd,%edi
ja     1173 <carefulputc+0x33>
mov    $0x2680,%eax
bt     %ebp,%eax
jae    1173 <carefulputc+0x33>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <putc@plt>
mov    0x2e7f(%rip),%rcx
sar    $0x1f,%eax
and    (%rcx),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
cmp    $0x7f,%ebp
je     1197 <carefulputc+0x57>
mov    %ebp,%eax
and    $0x60,%eax
je     1197 <carefulputc+0x57>
mov    %ebp,%edi
call   1060 <isprint@plt>
test   %rax,%rax
jne    1158 <carefulputc+0x18>
mov    %ebp,%edi
call   1030 <isspace@plt>
test   %rax,%rax
jne    1158 <carefulputc+0x18>
test   $0x80,%bpl
jne    11ce <carefulputc+0x8e>
mov    %ebp,%r14d
xor    $0x40,%r14d
mov    %r14d,%edi
call   1060 <isprint@plt>
test   %rax,%rax
je     11ce <carefulputc+0x8e>
mov    $0x5e,%edi
mov    %rbx,%rsi
call   1040 <putc@plt>
mov    0x2e23(%rip),%rcx
cmp    (%rcx),%eax
je     1162 <carefulputc+0x22>
mov    %r14d,%edi
jmp    115a <carefulputc+0x1a>
movzbl %bpl,%edx
lea    0xe27(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fprintf@plt>
jmp    1162 <carefulputc+0x22>

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

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