#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int MIMEH_is_binary(char *fname) {
  char buffer[1024];
  int read_count;
  FILE *f;
  f = fopen(fname, "r");
  if (!f)
    return 1;
  read_count = fread(buffer, 1, 1024, f);
  fclose(f);
  while (read_count) {
    read_count--;
    if (buffer[read_count] == 0)
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<MIMEH_is_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x0,-0x420(%rbp)
jne    1170 <MIMEH_is_binary+0x40>
movl   $0x1,-0x4(%rbp)
jmp    11eb <MIMEH_is_binary+0xbb>
lea    -0x410(%rbp),%rdi
mov    -0x420(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %eax,-0x414(%rbp)
mov    -0x420(%rbp),%rdi
call   1040 <fclose@plt>
cmpl   $0x0,-0x414(%rbp)
je     11e4 <MIMEH_is_binary+0xb4>
mov    -0x414(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x414(%rbp)
movslq -0x414(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
jne    11df <MIMEH_is_binary+0xaf>
movl   $0x1,-0x4(%rbp)
jmp    11eb <MIMEH_is_binary+0xbb>
jmp    119f <MIMEH_is_binary+0x6f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MIMEH_is_binary>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
lea    0xec0(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1190 <MIMEH_is_binary+0x60>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
movslq %ebp,%rax
mov    %rax,%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
sub    $0x1,%rcx
jb     1197 <MIMEH_is_binary+0x67>
cmpb   $0x0,-0x1(%rsp,%rax,1)
mov    %rcx,%rax
jne    1180 <MIMEH_is_binary+0x50>
mov    $0x1,%eax
jmp    1199 <MIMEH_is_binary+0x69>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret

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

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