#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
scalar_t__ isgraph(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  FILE *fp;
  int c = EOF;
  if (argc == 1) {
    fprintf(stderr, "Usage: cleantxt <file>\n");
    return 1;
  }
  fp = strcmp(argv[1], "-") ? fopen(argv[1], "rb") : stdin;
  if (fp == 0) {
    fprintf(stderr, "ERROR: fail to open the input file.\n");
    return 1;
  }
  while (!feof(fp)) {
    c = fgetc(fp);
    if (isgraph(c) || c == '\t' || c == '\n' || c == ' ')
      fputc(c, stdout);
  }
  if (c != '\n')
    fputc('\n', stdout);
  fclose(fp);
  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)
mov    0x2e43(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11cd <main+0x4d>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ef <main+0x16f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe3c(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1208 <main+0x88>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe20(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
jmp    1216 <main+0x96>
mov    0x2dd9(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    124a <main+0xca>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
lea    0xde4(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ef <main+0x16f>
jmp    124f <main+0xcf>
mov    -0x18(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    126d <main+0xed>
jmp    12c2 <main+0x142>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   10a0 <isgraph@plt>
cmp    $0x0,%rax
jne    12a9 <main+0x129>
cmpl   $0x9,-0x1c(%rbp)
je     12a9 <main+0x129>
cmpl   $0xa,-0x1c(%rbp)
je     12a9 <main+0x129>
cmpl   $0x20,-0x1c(%rbp)
jne    12bd <main+0x13d>
mov    -0x1c(%rbp),%eax
mov    0x2d15(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1050 <fputc@plt>
jmp    124f <main+0xcf>
cmpl   $0xa,-0x1c(%rbp)
je     12df <main+0x15f>
mov    0x2cf5(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1050 <fputc@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jne    11a1 <main+0x21>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
jmp    1282 <main+0x102>
mov    %rsi,%rbx
mov    0x2e35(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rsi),%rdi
lea    0xe60(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     125f <main+0xdf>
mov    0x8(%rbx),%rdi
lea    0xe49(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
test   %rbx,%rbx
je     1272 <main+0xf2>
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    123b <main+0xbb>
movabs $0x100000600,%r14
mov    0x2dc9(%rip),%r15
nop
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   10a0 <isgraph@plt>
test   %rax,%rax
jne    1223 <main+0xa3>
cmp    $0x20,%ebp
ja     122f <main+0xaf>
mov    %ebp,%eax
bt     %rax,%r14
jae    122f <main+0xaf>
mov    (%r15),%esi
movsbl %bpl,%edi
call   1050 <fputc@plt>
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     1200 <main+0x80>
cmp    $0xa,%ebp
je     1253 <main+0xd3>
mov    0x2d81(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1050 <fputc@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    128c <main+0x10c>
mov    0x2d82(%rip),%rax
mov    (%rax),%rbx
test   %rbx,%rbx
jne    11e2 <main+0x62>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
lea    0xd9b(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"Usage: cleantxt <file>\0A\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [3 x i8] c"rb\00"
@stdin = global i32* null
@.str.3 = [37 x i8] c"ERROR: fail to open the input file.\0A\00"
@stdout = 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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @EOF
store i32 %8, i32* %7
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %70
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %14
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %27
25: ; preds = %14
%26 = load i32*, i32** @stdin
br label %27
27: ; preds = %25, %20
%28 = phi i32* [ %24, %20 ], [ %26, %25 ]
store i32* %28, i32** %6
%29 = load i32*, i32** %6
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %70
34: ; preds = %27
br label %35
35: ; preds = %60, %34
%36 = load i32*, i32** %6
%37 = call i32 @feof(i32* %36)
%38 = icmp ne i32 %37, 0
%39 = xor i1 %38, true
br i1 %39, label %40, label %61
40: ; preds = %35
%41 = load i32*, i32** %6
%42 = call i32 @fgetc(i32* %41)
store i32 %42, i32* %7
%43 = load i32, i32* %7
%44 = call i64 @isgraph(i32 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %55, label %46
46: ; preds = %40
%47 = load i32, i32* %7
%48 = icmp eq i32 %47, 9
br i1 %48, label %55, label %49
49: ; preds = %46
%50 = load i32, i32* %7
%51 = icmp eq i32 %50, 10
br i1 %51, label %55, label %52
52: ; preds = %49
%53 = load i32, i32* %7
%54 = icmp eq i32 %53, 32
br i1 %54, label %55, label %60
55: ; preds = %52, %49, %46, %40
%56 = load i32, i32* %7
%57 = trunc i32 %56 to i8
%58 = load i32, i32* @stdout
%59 = call i32 @fputc(i8 signext %57, i32 %58)
br label %60
60: ; preds = %55, %52
br label %35
61: ; preds = %35
%62 = load i32, i32* %7
%63 = icmp ne i32 %62, 10
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = load i32, i32* @stdout
%66 = call i32 @fputc(i8 signext 10, i32 %65)
br label %67
67: ; preds = %64, %61
%68 = load i32*, i32** %6
%69 = call i32 @fclose(i32* %68)
store i32 0, i32* %3
br label %70
70: ; preds = %67, %31, %11
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
@EOF = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"Usage: cleantxt <file>\0A\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [3 x i8] c"rb\00"
@stdin = global i32* null
@.str.3 = [37 x i8] c"ERROR: fail to open the input file.\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %0, 1
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %48
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = load i8*, i8** %9
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %18
16: ; preds = %8
%17 = load i32*, i32** @stdin
br label %18
18: ; preds = %16, %13
%19 = phi i32* [ %15, %13 ], [ %17, %16 ]
%20 = icmp eq i32* %19, null
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = tail call i32 @feof(i32* %19)
%23 = icmp eq i32 %22, 0
br i1 %23, label %27, label %40
24: ; preds = %18
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
br label %48
27: ; preds = %21, %37
%28 = tail call i32 @fgetc(i32* %19)
%29 = tail call i64 @isgraph(i32 %28)
%30 = freeze i64 %29
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %27
switch i32 %28, label %37 [
i32 32, label %33
i32 10, label %33
i32 9, label %33
]
33: ; preds = %32, %32, %32, %27
%34 = trunc i32 %28 to i8
%35 = load i32, i32* @stdout
%36 = tail call i32 @fputc(i8 signext %34, i32 %35)
br label %37
37: ; preds = %32, %33
%38 = tail call i32 @feof(i32* %19)
%39 = icmp eq i32 %38, 0
br i1 %39, label %27, label %40
40: ; preds = %37, %21
%41 = phi i32 [ %3, %21 ], [ %28, %37 ]
%42 = icmp eq i32 %41, 10
br i1 %42, label %46, label %43
43: ; preds = %40
%44 = load i32, i32* @stdout
%45 = tail call i32 @fputc(i8 signext 10, i32 %44)
br label %46
46: ; preds = %43, %40
%47 = tail call i32 @fclose(i32* %19)
br label %48
48: ; preds = %46, %24, %5
%49 = phi i32 [ 1, %5 ], [ 1, %24 ], [ 0, %46 ]
ret i32 %49
}