#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*/ ch;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ isprint(char);
scalar_t__ isspace(char);
int /*<<< orphan*/ perror(char *);
int text_or_binary(const char *File_name) {
  int x;
  FILE *fp;
  char ch;
  fp = fopen(File_name, "r");
  if (fp == NULL) {
    perror("Error");
    return errno;
  }
  while (fread(&ch, sizeof(ch), 1, fp) != 0) {
    if (isprint(ch) == 0) {
      if (isspace(ch) != 0)
        continue;
      else {
        fclose(fp);
        return 0;
      }
    }
  }
  fclose(fp);
  return 1;
}


x86 assembly (clang, -O0):
<text_or_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a8 <text_or_binary+0x48>
lea    0xe6e(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1220 <text_or_binary+0xc0>
jmp    11ad <text_or_binary+0x4d>
mov    -0x20(%rbp),%rcx
lea    -0x21(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x0,%rax
je     1210 <text_or_binary+0xb0>
movsbl -0x21(%rbp),%edi
call   1060 <isprint@plt>
cmp    $0x0,%rax
jne    120b <text_or_binary+0xab>
movsbl -0x21(%rbp),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     11f6 <text_or_binary+0x96>
jmp    11ad <text_or_binary+0x4d>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1220 <text_or_binary+0xc0>
jmp    11ad <text_or_binary+0x4d>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<text_or_binary>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe96(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     120a <text_or_binary+0xaa>
mov    %rax,%rbx
lea    0x7(%rsp),%rdi
mov    $0x1,%r14d
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     11f4 <text_or_binary+0x94>
lea    0x7(%rsp),%r15
jmp    11ca <text_or_binary+0x6a>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     11f4 <text_or_binary+0x94>
movsbl 0x7(%rsp),%ebp
mov    %ebp,%edi
call   1060 <isprint@plt>
test   %rax,%rax
jne    11b0 <text_or_binary+0x50>
mov    %ebp,%edi
call   1050 <isspace@plt>
test   %rax,%rax
jne    11b0 <text_or_binary+0x50>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %r14d,%r14d
jmp    11fc <text_or_binary+0x9c>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdef(%rip),%rdi
call   1080 <perror@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%r14d
jmp    11fc <text_or_binary+0x9c>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"Error\00"
@errno = global i32 0
define i32 @text_or_binary(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @errno
store i32 %13, i32* %2
br label %35
14: ; preds = %1
br label %15
15: ; preds = %31, %27, %14
%16 = load i32*, i32** %5
%17 = call i64 @fread(i8* %6, i32 1, i32 1, i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %32
19: ; preds = %15
%20 = load i8, i8* %6
%21 = call i64 @isprint(i8 signext %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %19
%24 = load i8, i8* %6
%25 = call i64 @isspace(i8 signext %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %23
br label %15
28: ; preds = %23
%29 = load i32*, i32** %5
%30 = call i32 @fclose(i32* %29)
store i32 0, i32* %2
br label %35
31: ; preds = %19
br label %15
32: ; preds = %15
%33 = load i32*, i32** %5
%34 = call i32 @fclose(i32* %33)
store i32 1, i32* %2
br label %35
35: ; preds = %32, %28, %11
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"Error\00"
@errno = global i32 0
define i32 @text_or_binary(i8* nocapture %0) {
%2 = alloca i8
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = call i64 @fread(i8* %2, i32 1, i32 1, i32* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %23, label %11
8: ; preds = %1
%9 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @errno
br label %25
11: ; preds = %5, %18
%12 = load i8, i8* %2
%13 = tail call i64 @isprint(i8 signext %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = tail call i64 @isspace(i8 signext %12)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15, %11
%19 = call i64 @fread(i8* %2, i32 1, i32 1, i32* %3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %11
21: ; preds = %15
%22 = tail call i32 @fclose(i32* %3)
br label %25
23: ; preds = %18, %5
%24 = tail call i32 @fclose(i32* %3)
br label %25
25: ; preds = %23, %21, %8
%26 = phi i32 [ %10, %8 ], [ 0, %21 ], [ 1, %23 ]
ret i32 %26
}