#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 */

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int getopt(int, char **, char *);
int /*<<< orphan*/ isprint(char);
int /*<<< orphan*/ optarg;
int read(int /*<<< orphan*/, void *, int);
int /*<<< orphan*/ strstr(int /*<<< orphan*/, char *);
int /*<<< orphan*/ usage();
int /*<<< orphan*/ write(int /*<<< orphan*/, void *, int);
int main(int argc, char *argv[]) {
  int option;
  int flag_filter_non_ascii = 0;
  int n;
  char ch;
  while ((option = getopt(argc, argv, "hf:")) != -1) {
    switch (option) {
    case 'f':
      if (strstr(optarg, "delete:non-ascii")) {
        flag_filter_non_ascii = 1;
        ;
      } else {
        usage();
      }
      break;
    case 'h':
    default:
      usage();
    }
  }
  while (1) {
    n = read(STDIN_FILENO, (void *)&ch, 1);
    if (n <= 0) {
      return 0;
    }
    if (flag_filter_non_ascii && (!isprint(ch))) {
      continue;
    }
    write(STDOUT_FILENO, (void *)&ch, 1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe75(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1208 <main+0xa8>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x66,%eax
je     11c1 <main+0x61>
jmp    11b0 <main+0x50>
mov    -0x24(%rbp),%eax
sub    $0x68,%eax
je     11f7 <main+0x97>
jmp    11fc <main+0x9c>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%eax
je     11eb <main+0x8b>
movl   $0x1,-0x18(%rbp)
jmp    11f2 <main+0x92>
mov    $0x0,%al
call   1050 <usage@plt>
jmp    1203 <main+0xa3>
jmp    11fc <main+0x9c>
mov    $0x0,%al
call   1050 <usage@plt>
jmp    117d <main+0x1d>
jmp    120d <main+0xad>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
lea    -0x1d(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     1239 <main+0xd9>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret
cmpl   $0x0,-0x18(%rbp)
je     125a <main+0xfa>
movsbl -0x1d(%rbp),%edi
call   1060 <isprint@plt>
cmp    $0x0,%eax
jne    125a <main+0xfa>
jmp    120d <main+0xad>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
lea    -0x1d(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    120d <main+0xad>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x1,%r12b
lea    0xe86(%rip),%r14
mov    0x2e77(%rip),%r13
lea    0xe7c(%rip),%r15
jmp    119c <main+0x3c>
nopw   0x0(%rax,%rax,1)
cmp    $0xffffffff,%eax
je     11c3 <main+0x63>
xor    %eax,%eax
call   1050 <usage@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1070 <getopt@plt>
cmp    $0x66,%eax
jne    1190 <main+0x30>
mov    0x0(%r13),%edi
mov    %r15,%rsi
call   1080 <strstr@plt>
test   %eax,%eax
je     1195 <main+0x35>
xor    %r12d,%r12d
jmp    119c <main+0x3c>
mov    0x2e06(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    122a <main+0xca>
mov    0x2e01(%rip),%r14
lea    0x7(%rsp),%rbx
jmp    1214 <main+0xb4>
xchg   %ax,%ax
mov    (%r14),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    122a <main+0xca>
test   $0x1,%r12b
jne    11f0 <main+0x90>
movsbl 0x7(%rsp),%edi
call   1060 <isprint@plt>
test   %eax,%eax
jne    11f0 <main+0x90>
jmp    1200 <main+0xa0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"hf:\00"
@optarg = global i32 0
@.str.1 = [17 x i8] c"delete:non-ascii\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
br label %10
10: ; preds = %28, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %13, i32* %6
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %29
15: ; preds = %10
%16 = load i32, i32* %6
switch i32 %16, label %26 [
i32 102, label %17
i32 104, label %25
]
17: ; preds = %15
%18 = load i32, i32* @optarg
%19 = call i32 @strstr(i32 %18, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 1, i32* %7
br label %24
22: ; preds = %17
%23 = call i32 (...) @usage()
br label %24
24: ; preds = %22, %21
br label %28
25: ; preds = %15
br label %26
26: ; preds = %15, %25
%27 = call i32 (...) @usage()
br label %28
28: ; preds = %26, %24
br label %10
29: ; preds = %10
br label %30
30: ; preds = %29, %43, %44
%31 = load i32, i32* @STDIN_FILENO
%32 = call i32 @read(i32 %31, i8* %9, i32 1)
store i32 %32, i32* %8
%33 = load i32, i32* %8
%34 = icmp sle i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %30
ret i32 0
36: ; preds = %30
%37 = load i32, i32* %7
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %36
%40 = load i8, i8* %9
%41 = call i32 @isprint(i8 signext %40)
%42 = icmp ne i32 %41, 0
br i1 %42, label %44, label %43
43: ; preds = %39
br label %30
44: ; preds = %39, %36
%45 = load i32, i32* @STDOUT_FILENO
%46 = call i32 @write(i32 %45, i8* %9, i32 1)
br label %30
}

LLVM IR (-O2):
@.str = [4 x i8] c"hf:\00"
@optarg = global i32 0
@.str.1 = [17 x i8] c"delete:non-ascii\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i8
br label %4
4: ; preds = %12, %2
%5 = phi i1 [ true, %2 ], [ false, %12 ]
br label %6
6: ; preds = %4, %16
%7 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %7, label %16 [
i32 -1, label %8
i32 102, label %12
]
8: ; preds = %6
%9 = load i32, i32* @STDIN_FILENO
%10 = call i32 @read(i32 %9, i8* %3, i32 1)
%11 = icmp slt i32 %10, 1
br i1 %11, label %18, label %19
12: ; preds = %6
%13 = load i32, i32* @optarg
%14 = tail call i32 @strstr(i32 %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %4
16: ; preds = %6, %12
%17 = tail call i32 (...) @usage()
br label %6
18: ; preds = %27, %8
ret i32 0
19: ; preds = %8, %27
br i1 %5, label %24, label %20
20: ; preds = %19
%21 = load i8, i8* %3
%22 = tail call i32 @isprint(i8 signext %21)
%23 = icmp eq i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %20, %19
%25 = load i32, i32* @STDOUT_FILENO
%26 = call i32 @write(i32 %25, i8* %3, i32 1)
br label %27
27: ; preds = %24, %20
%28 = load i32, i32* @STDIN_FILENO
%29 = call i32 @read(i32 %28, i8* %3, i32 1)
%30 = icmp slt i32 %29, 1
br i1 %30, label %18, label %19
}