#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;
scalar_t__ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ is_ASCII(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  FILE *stream;
  char *path;
  int character, last_character;
  int unsupported_binary_file;
  path = (argc < 2) ? (char *)"in" : argv[1];
  stream = fopen(path, "r+");
  if (stream == NULL) {
    fputs("Failed to access file for streaming.\n", stderr);
    getchar();
    return -1;
  }
  unsupported_binary_file = !is_ASCII(path);
  if (unsupported_binary_file)
    return -2;
  character = fgetc(stream);
  last_character = '\0';
  while (character != EOF) {
    if (character < 0) {
      fprintf(stderr, "Unknown negative return value:  %i\n", character);
      getchar();
      return -3;
    }
    last_character = character;
    character = fgetc(stream);
  }
  if (last_character == '\n')
    puts("Text file was already terminated by a newline.");
  else
    fputc('\n', stream);
  while (fclose(stream) != 0)
    ;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11c0 <main+0x30>
lea    0xe49(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    11cc <main+0x3c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe24(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    121b <main+0x8b>
mov    0x2dde(%rip),%rax
mov    (%rax),%esi
lea    0xe03(%rip),%rdi
call   1060 <fputs@plt>
mov    $0x0,%al
call   1090 <getchar@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1308 <main+0x178>
mov    -0x20(%rbp),%rdi
call   1030 <is_ASCII@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     124a <main+0xba>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1308 <main+0x178>
mov    -0x18(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2d81(%rip),%rcx
cmp    (%rcx),%eax
je     12bb <main+0x12b>
cmpl   $0x0,-0x24(%rbp)
jge    12a4 <main+0x114>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xda0(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x0,%al
call   1090 <getchar@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1308 <main+0x178>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %eax,-0x24(%rbp)
jmp    125d <main+0xcd>
cmpl   $0xa,-0x28(%rbp)
jne    12d6 <main+0x146>
lea    0xd84(%rip),%rdi
call   1040 <puts@plt>
jmp    12e4 <main+0x154>
mov    -0x18(%rbp),%rsi
mov    $0xa,%edi
call   1080 <fputc@plt>
jmp    12e9 <main+0x159>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
cmp    $0x0,%rax
je     1301 <main+0x171>
jmp    12e9 <main+0x159>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jge    11a2 <main+0x12>
lea    0xe60(%rip),%rbp
jmp    11a6 <main+0x16>
mov    0x8(%rsi),%rbp
lea    0xe56(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1206 <main+0x76>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1030 <is_ASCII@plt>
test   %eax,%eax
je     1241 <main+0xb1>
mov    %rbx,%rdi
call   1070 <fgetc@plt>
mov    0x2e10(%rip),%r14
cmp    (%r14),%eax
je     1222 <main+0x92>
nopl   (%rax)
mov    %eax,%ebp
test   %eax,%eax
js     1248 <main+0xb8>
mov    %rbx,%rdi
call   1070 <fgetc@plt>
cmp    (%r14),%eax
jne    11e0 <main+0x50>
cmp    $0xa,%ebp
jne    1222 <main+0x92>
lea    0xe51(%rip),%rdi
call   1040 <puts@plt>
jmp    1230 <main+0xa0>
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
lea    0xdf0(%rip),%rdi
call   1060 <fputs@plt>
mov    $0xffffffff,%ebx
jmp    1264 <main+0xd4>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1080 <fputc@plt>
nop
mov    %rbx,%rdi
call   1050 <fclose@plt>
test   %rax,%rax
jne    1230 <main+0xa0>
xor    %ebx,%ebx
jmp    126b <main+0xdb>
mov    $0xfffffffe,%ebx
jmp    126b <main+0xdb>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
lea    0xdd4(%rip),%rsi
mov    %ebp,%edx
call   10a0 <fprintf@plt>
mov    $0xfffffffd,%ebx
xor    %eax,%eax
call   1090 <getchar@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"in\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [38 x i8] c"Failed to access file for streaming.\0A\00"
@stderr = global i32 0
@EOF = global i32 0
@.str.3 = [36 x i8] c"Unknown negative return value: %i\0A\00"
@.str.4 = [47 x i8] c"Text file was already terminated by a newline.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %14
13: ; preds = %2
br label %18
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
br label %18
18: ; preds = %14, %13
%19 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %13 ], [ %17, %14 ]
store i8* %19, i8** %7
%20 = load i8*, i8** %7
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i32*, i32** %6
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %28
24: ; preds = %18
%25 = load i32, i32* @stderr
%26 = call i32 @fputs(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = call i32 (...) @getchar()
store i32 -1, i32* %3
br label %71
28: ; preds = %18
%29 = load i8*, i8** %7
%30 = call i32 @is_ASCII(i8* %29)
%31 = icmp ne i32 %30, 0
%32 = xor i1 %31, true
%33 = zext i1 %32 to i32
store i32 %33, i32* %10
%34 = load i32, i32* %10
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %28
store i32 -2, i32* %3
br label %71
37: ; preds = %28
%38 = load i32*, i32** %6
%39 = call i32 @fgetc(i32* %38)
store i32 %39, i32* %8
store i32 0, i32* %9
br label %40
40: ; preds = %52, %37
%41 = load i32, i32* %8
%42 = load i32, i32* @EOF
%43 = icmp ne i32 %41, %42
br i1 %43, label %44, label %56
44: ; preds = %40
%45 = load i32, i32* %8
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %44
%48 = load i32, i32* @stderr
%49 = load i32, i32* %8
%50 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %49)
%51 = call i32 (...) @getchar()
store i32 -3, i32* %3
br label %71
52: ; preds = %44
%53 = load i32, i32* %8
store i32 %53, i32* %9
%54 = load i32*, i32** %6
%55 = call i32 @fgetc(i32* %54)
store i32 %55, i32* %8
br label %40
56: ; preds = %40
%57 = load i32, i32* %9
%58 = icmp eq i32 %57, 10
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = call i32 @puts(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0))
br label %64
61: ; preds = %56
%62 = load i32*, i32** %6
%63 = call i32 @fputc(i8 signext 10, i32* %62)
br label %64
64: ; preds = %61, %59
br label %65
65: ; preds = %69, %64
%66 = load i32*, i32** %6
%67 = call i64 @fclose(i32* %66)
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %65
br label %65
70: ; preds = %65
store i32 0, i32* %3
br label %71
71: ; preds = %70, %47, %36, %24
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
@.str = [3 x i8] c"in\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [38 x i8] c"Failed to access file for streaming.\0A\00"
@stderr = global i32 0
@EOF = global i32 0
@.str.3 = [36 x i8] c"Unknown negative return value: %i\0A\00"
@.str.4 = [47 x i8] c"Text file was already terminated by a newline.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
br label %7
7: ; preds = %2, %4
%8 = phi i8* [ %6, %4 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %2 ]
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i32, i32* @stderr
%13 = tail call i32 @fputs(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %12)
br label %41
14: ; preds = %7
%15 = tail call i32 @is_ASCII(i8* %8)
%16 = icmp eq i32 %15, 0
br i1 %16, label %44, label %17
17: ; preds = %14
%18 = tail call i32 @fgetc(i32* %9)
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %35, label %21
21: ; preds = %17, %27
%22 = phi i32 [ %28, %27 ], [ %18, %17 ]
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %22)
br label %41
27: ; preds = %21
%28 = tail call i32 @fgetc(i32* %9)
%29 = load i32, i32* @EOF
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %21
31: ; preds = %27
%32 = icmp eq i32 %22, 10
br i1 %32, label %33, label %35
33: ; preds = %31
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0))
br label %37
35: ; preds = %17, %31
%36 = tail call i32 @fputc(i8 signext 10, i32* %9)
br label %37
37: ; preds = %35, %33
br label %38
38: ; preds = %37, %38
%39 = tail call i64 @fclose(i32* %9)
%40 = icmp eq i64 %39, 0
br i1 %40, label %44, label %38
41: ; preds = %11, %24
%42 = phi i32 [ -3, %24 ], [ -1, %11 ]
%43 = tail call i32 (...) @getchar()
br label %44
44: ; preds = %38, %41, %14
%45 = phi i32 [ -2, %14 ], [ %42, %41 ], [ 0, %38 ]
ret i32 %45
}