#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int isbinaryfile(char *s) {
  char buf[256];
  char *p;
  int n, f, c;
  f = open(s, 0);
  if (f == -1) {
    perror(s);
    exit(1);
  }
  n = read(f, buf, sizeof(buf));
  if (n == -1) {
    perror(s);
    exit(1);
  }
  (void)close(f);
  p = buf;
  while (n-- > 0) {
    c = *p++ & 0xff;
    if (c == 0)
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<isbinaryfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1050 <open@plt>
mov    %eax,-0x120(%rbp)
cmpl   $0xffffffff,-0x120(%rbp)
jne    1190 <isbinaryfile+0x40>
mov    -0x10(%rbp),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x120(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1040 <read@plt>
mov    %eax,-0x11c(%rbp)
cmpl   $0xffffffff,-0x11c(%rbp)
jne    11cd <isbinaryfile+0x7d>
mov    -0x10(%rbp),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x120(%rbp),%edi
call   1030 <close@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x118(%rbp)
mov    -0x11c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x11c(%rbp)
cmp    $0x0,%eax
jle    1241 <isbinaryfile+0xf1>
mov    -0x118(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x118(%rbp)
movsbl (%rax),%eax
and    $0xff,%eax
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
jne    123c <isbinaryfile+0xec>
movl   $0x1,-0x4(%rbp)
jmp    1248 <isbinaryfile+0xf8>
jmp    11e6 <isbinaryfile+0x96>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isbinaryfile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%r14
xor    %esi,%esi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     11b7 <isbinaryfile+0x67>
mov    %eax,%r15d
mov    %rsp,%rbx
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1040 <read@plt>
cmp    $0xffffffff,%eax
je     11b7 <isbinaryfile+0x67>
mov    %eax,%ebp
mov    %r15d,%edi
call   1030 <close@plt>
test   %ebp,%ebp
jle    11a7 <isbinaryfile+0x57>
add    $0xffffffff,%ebp
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
jne    1190 <isbinaryfile+0x40>
mov    $0x1,%eax
jmp    11a9 <isbinaryfile+0x59>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
define i32 @isbinaryfile(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [256 x i8]
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 @open(i8* %9, i32 0)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i32 @perror(i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %1
%18 = load i32, i32* %7
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%20 = call i32 @read(i32 %18, i8* %19, i32 256)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = load i8*, i8** %3
%25 = call i32 @perror(i8* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %17
%28 = load i32, i32* %7
%29 = call i32 @close(i32 %28)
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
store i8* %30, i8** %5
br label %31
31: ; preds = %44, %27
%32 = load i32, i32* %6
%33 = add nsw i32 %32, -1
store i32 %33, i32* %6
%34 = icmp sgt i32 %32, 0
br i1 %34, label %35, label %45
35: ; preds = %31
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %5
%38 = load i8, i8* %36
%39 = sext i8 %38 to i32
%40 = and i32 %39, 255
store i32 %40, i32* %8
%41 = load i32, i32* %8
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %35
store i32 1, i32* %2
br label %46
44: ; preds = %35
br label %31
45: ; preds = %31
store i32 0, i32* %2
br label %46
46: ; preds = %45, %43
%47 = load i32, i32* %2
ret i32 %47
}

LLVM IR (-O2):
define i32 @isbinaryfile(i8* nocapture %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @open(i8* %0, i32 0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = tail call i32 @perror(i8* %0)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %1
%10 = call i32 @read(i32 %4, i8* %3, i32 256)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = tail call i32 @perror(i8* %0)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %9
%16 = tail call i32 @close(i32 %4)
br label %17
17: ; preds = %21, %15
%18 = phi i32 [ %10, %15 ], [ %22, %21 ]
%19 = phi i8* [ %3, %15 ], [ %23, %21 ]
%20 = icmp sgt i32 %18, 0
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = add nsw i32 %18, -1
%23 = getelementptr inbounds i8, i8* %19, i64 1
%24 = load i8, i8* %19
%25 = icmp eq i8 %24, 0
br i1 %25, label %26, label %17
26: ; preds = %17, %21
%27 = phi i32 [ 1, %21 ], [ 0, %17 ]
ret i32 %27
}