#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ isascii(int);
char *saferead(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
int main(int argc, char *argv[]) {
  FILE *f;
  int c;
  int x = 0;
  char *buf;
  if (argc < 2)
    f = stdin;
  else {
    f = fopen(argv[1], "r");
    if (f == NULL) {
      fprintf(stderr, "Could not read %s\n", argv[1]);
      exit(EXIT_FAILURE);
    }
  }
  buf = saferead(f);
  if (argc < 3)
    f = stdout;
  else
    f = fopen(argv[2], "w");
  while ((c = buf[x]) != 0) {
    if (isascii(c))
      fputc((int)c, f);
    x++;
  }
  fclose(f);
  free(buf);
  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,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11ba <main+0x3a>
mov    0x2e3a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    120d <main+0x8d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe37(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1208 <main+0x88>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe0d(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    120d <main+0x8d>
mov    -0x18(%rbp),%rdi
call   1070 <saferead@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1237 <main+0xb7>
mov    0x2d9d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    124f <main+0xcf>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdcf(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
jmp    1254 <main+0xd4>
mov    -0x28(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     1298 <main+0x118>
mov    -0x1c(%rbp),%edi
call   10a0 <isascii@plt>
cmp    $0x0,%rax
je     128a <main+0x10a>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1050 <fputc@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1254 <main+0xd4>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%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
jg     11a0 <main+0x20>
mov    0x2e55(%rip),%rax
mov    (%rax),%rdi
call   1070 <saferead@plt>
mov    %rax,%r14
jmp    11ce <main+0x4e>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
lea    0xe50(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1243 <main+0xc3>
mov    %rax,%rdi
call   1070 <saferead@plt>
mov    %rax,%r14
cmp    $0x2,%ebp
ja     11da <main+0x5a>
mov    0x2df3(%rip),%rax
mov    (%rax),%r15
jmp    11ed <main+0x6d>
mov    0x10(%rbx),%rdi
lea    0xe30(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
mov    (%r14),%al
test   %al,%al
je     1226 <main+0xa6>
lea    0x1(%r14),%rbx
jmp    120b <main+0x8b>
nopw   0x0(%rax,%rax,1)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1226 <main+0xa6>
movsbl %al,%ebp
mov    %ebp,%edi
call   10a0 <isascii@plt>
test   %rax,%rax
je     1200 <main+0x80>
mov    %ebp,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
jmp    1200 <main+0x80>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xdab(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"Could not read %s\0A\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32* null
@.str.2 = [2 x i8] c"w\00"
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* %8
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i32*, i32** @stdin
store i32* %13, i32** %6
br label %30
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %29
21: ; preds = %14
%22 = load i32, i32* @stderr
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %14
br label %30
30: ; preds = %29, %12
%31 = load i32*, i32** %6
%32 = call i8* @saferead(i32* %31)
store i8* %32, i8** %9
%33 = load i32, i32* %4
%34 = icmp slt i32 %33, 3
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = load i32*, i32** @stdout
store i32* %36, i32** %6
br label %42
37: ; preds = %30
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %41, i32** %6
br label %42
42: ; preds = %37, %35
br label %43
43: ; preds = %59, %42
%44 = load i8*, i8** %9
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
store i32 %49, i32* %7
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %62
51: ; preds = %43
%52 = load i32, i32* %7
%53 = call i64 @isascii(i32 %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %51
%56 = load i32, i32* %7
%57 = load i32*, i32** %6
%58 = call i32 @fputc(i32 %56, i32* %57)
br label %59
59: ; preds = %55, %51
%60 = load i32, i32* %8
%61 = add nsw i32 %60, 1
store i32 %61, i32* %8
br label %43
62: ; preds = %43
%63 = load i32*, i32** %6
%64 = call i32 @fclose(i32* %63)
%65 = load i8*, i8** %9
%66 = call i32 @free(i8* %65)
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"Could not read %s\0A\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32* null
@.str.2 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32*, i32** @stdin
%6 = tail call i8* @saferead(i32* %5)
br label %21
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %18
12: ; preds = %7
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %8
%15 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %7
%19 = tail call i8* @saferead(i32* %10)
%20 = icmp ult i32 %0, 3
br i1 %20, label %21, label %24
21: ; preds = %4, %18
%22 = phi i8* [ %6, %4 ], [ %19, %18 ]
%23 = load i32*, i32** @stdout
br label %28
24: ; preds = %18
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = tail call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %24, %21
%29 = phi i8* [ %22, %21 ], [ %19, %24 ]
%30 = phi i32* [ %23, %21 ], [ %27, %24 ]
%31 = load i8, i8* %29
%32 = icmp eq i8 %31, 0
br i1 %32, label %46, label %33
33: ; preds = %28, %41
%34 = phi i64 [ %42, %41 ], [ 0, %28 ]
%35 = phi i8 [ %44, %41 ], [ %31, %28 ]
%36 = sext i8 %35 to i32
%37 = tail call i64 @isascii(i32 %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %41, label %39
39: ; preds = %33
%40 = tail call i32 @fputc(i32 %36, i32* %30)
br label %41
41: ; preds = %39, %33
%42 = add nuw i64 %34, 1
%43 = getelementptr inbounds i8, i8* %29, i64 %42
%44 = load i8, i8* %43
%45 = icmp eq i8 %44, 0
br i1 %45, label %46, label %33
46: ; preds = %41, %28
%47 = tail call i32 @fclose(i32* %30)
%48 = tail call i32 @free(i8* %29)
ret i32 0
}