#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 fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int is_printable(int);
int /*<<< orphan*/ printf(char *, int);
int is_ASCII(char *path) {
  FILE *stream;
  int character;
  stream = fopen(path, "rb");
  if (stream == NULL)
    return -1;
  character = fgetc(stream);
  while (character >= 0) {
    const int acceptable = is_printable(character);
    if (acceptable == 0) {
      fclose(stream);
      return 0;
    }
    character = fgetc(stream);
  }
  fclose(stream);
  if (character == EOF)
    return 1;
  printf("Undocumented fgetc return value:  %i.\n", character);
  return 0;
}


x86 assembly (clang, -O0):
<is_ASCII>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1187 <is_ASCII+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    1215 <is_ASCII+0xc5>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     11d8 <is_ASCII+0x88>
mov    -0x1c(%rbp),%edi
call   1030 <is_printable@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    11c7 <is_ASCII+0x77>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1215 <is_ASCII+0xc5>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
jmp    1193 <is_ASCII+0x43>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    0x2dfd(%rip),%rcx
cmp    (%rcx),%eax
jne    11ff <is_ASCII+0xaf>
movl   $0x1,-0x4(%rbp)
jmp    1215 <is_ASCII+0xc5>
mov    -0x1c(%rbp),%esi
lea    0xdfa(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_ASCII>:
push   %rbp
push   %rbx
push   %rax
lea    0xea6(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11bd <is_ASCII+0x6d>
mov    %rax,%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1193 <is_ASCII+0x43>
mov    %ebp,%edi
call   1030 <is_printable@plt>
test   %eax,%eax
jne    1170 <is_ASCII+0x20>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11b9 <is_ASCII+0x69>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x2e46(%rip),%rcx
mov    $0x1,%eax
cmp    (%rcx),%ebp
je     11c2 <is_ASCII+0x72>
lea    0xe51(%rip),%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
xor    %eax,%eax
jmp    11c2 <is_ASCII+0x72>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@EOF = global i32 0
@.str.1 = [39 x i8] c"Undocumented fgetc return value: %i.\0A\00"
define i32 @is_ASCII(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %4
%9 = load i32*, i32** %4
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 -1, i32* %2
br label %39
12: ; preds = %1
%13 = load i32*, i32** %4
%14 = call i32 @fgetc(i32* %13)
store i32 %14, i32* %5
br label %15
15: ; preds = %26, %12
%16 = load i32, i32* %5
%17 = icmp sge i32 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %15
%19 = load i32, i32* %5
%20 = call i32 @is_printable(i32 %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i32*, i32** %4
%25 = call i32 @fclose(i32* %24)
store i32 0, i32* %2
br label %39
26: ; preds = %18
%27 = load i32*, i32** %4
%28 = call i32 @fgetc(i32* %27)
store i32 %28, i32* %5
br label %15
29: ; preds = %15
%30 = load i32*, i32** %4
%31 = call i32 @fclose(i32* %30)
%32 = load i32, i32* %5
%33 = load i32, i32* @EOF
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %36
35: ; preds = %29
store i32 1, i32* %2
br label %39
36: ; preds = %29
%37 = load i32, i32* %5
%38 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %37)
store i32 0, i32* %2
br label %39
39: ; preds = %36, %35, %23, %11
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@EOF = global i32 0
@.str.1 = [39 x i8] c"Undocumented fgetc return value: %i.\0A\00"
define i32 @is_ASCII(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %23, label %4
4: ; preds = %1
%5 = tail call i32 @fgetc(i32* %2)
%6 = icmp sgt i32 %5, -1
br i1 %6, label %7, label %16
7: ; preds = %4, %13
%8 = phi i32 [ %14, %13 ], [ %5, %4 ]
%9 = tail call i32 @is_printable(i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @fclose(i32* %2)
br label %23
13: ; preds = %7
%14 = tail call i32 @fgetc(i32* %2)
%15 = icmp sgt i32 %14, -1
br i1 %15, label %7, label %16
16: ; preds = %13, %4
%17 = phi i32 [ %5, %4 ], [ %14, %13 ]
%18 = tail call i32 @fclose(i32* %2)
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %17, %19
br i1 %20, label %23, label %21
21: ; preds = %16
%22 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %23
23: ; preds = %11, %16, %1, %21
%24 = phi i32 [ 0, %21 ], [ -1, %1 ], [ 1, %16 ], [ 0, %11 ]
ret i32 %24
}