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

/* Variables and functions */
int /*<<< orphan*/ *check_fopen(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int64_t is_binary(char *filename) {
  int64_t i;
  FILE *input = check_fopen(filename, "r");
  char buffer[1024];
  int64_t nr = fread(buffer, 1, 1024, input);
  fclose(input);
  if (!nr)
    return 0;
  for (i = 0; i < nr; i++) {
    if (buffer[i] < 1)
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<is_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb6(%rip),%rsi
call   1050 <check_fopen@plt>
mov    %rax,-0x20(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %rax,-0x428(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x428(%rbp)
jne    1198 <is_binary+0x68>
movq   $0x0,-0x8(%rbp)
jmp    11f1 <is_binary+0xc1>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x428(%rbp),%rax
jae    11e9 <is_binary+0xb9>
mov    -0x18(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0x1,%eax
jge    11d3 <is_binary+0xa3>
movq   $0x1,-0x8(%rbp)
jmp    11f1 <is_binary+0xc1>
jmp    11d8 <is_binary+0xa8>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11a0 <is_binary+0x70>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_binary>:
push   %r14
push   %rbx
sub    $0x408,%rsp
lea    0xebf(%rip),%rsi
call   1050 <check_fopen@plt>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
test   %rbx,%rbx
je     1196 <is_binary+0x66>
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmpb   $0x0,(%rsp,%rcx,1)
jle    1191 <is_binary+0x61>
add    $0x1,%rcx
cmp    %rcx,%rbx
jne    1180 <is_binary+0x50>
jmp    1196 <is_binary+0x66>
mov    $0x1,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i64 @is_binary(i8* %0) {
%2 = alloca [1024 x i8]
%3 = tail call i32* @check_fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = call i64 @fread(i8* %4, i32 1, i32 1024, i32* %3)
%6 = tail call i32 @fclose(i32* %3)
%7 = icmp eq i64 %5, 0
br i1 %7, label %16, label %10
8: ; preds = %10
%9 = icmp eq i64 %15, %5
br i1 %9, label %16, label %10
10: ; preds = %1, %8
%11 = phi i64 [ %15, %8 ], [ 0, %1 ]
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = icmp slt i8 %13, 1
%15 = add nuw i64 %11, 1
br i1 %14, label %16, label %8
16: ; preds = %10, %8, %1
%17 = phi i64 [ 0, %1 ], [ 1, %10 ], [ 0, %8 ]
ret i64 %17
}