isbinaryfile(s) 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;
    if (c & 0x80)
      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
mov    $0x0,%al
call   1050 <open@plt>
mov    %eax,-0x120(%rbp)
cmpl   $0xffffffff,-0x120(%rbp)
jne    1194 <isbinaryfile+0x44>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x120(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
mov    $0x0,%al
call   1040 <read@plt>
mov    %eax,-0x11c(%rbp)
cmpl   $0xffffffff,-0x11c(%rbp)
jne    11d5 <isbinaryfile+0x85>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x120(%rbp),%edi
mov    $0x0,%al
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    126b <isbinaryfile+0x11b>
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    1246 <isbinaryfile+0xf6>
movl   $0x1,-0x4(%rbp)
jmp    1272 <isbinaryfile+0x122>
mov    -0x124(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     1266 <isbinaryfile+0x116>
movl   $0x1,-0x4(%rbp)
jmp    1272 <isbinaryfile+0x122>
jmp    11f0 <isbinaryfile+0xa0>
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
xor    %eax,%eax
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     11c7 <isbinaryfile+0x77>
mov    %eax,%r15d
mov    %rsp,%rbx
mov    $0x100,%edx
mov    %eax,%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <read@plt>
cmp    $0xffffffff,%eax
je     11c7 <isbinaryfile+0x77>
mov    %eax,%ebp
xor    %r14d,%r14d
mov    %r15d,%edi
xor    %eax,%eax
call   1030 <close@plt>
nopl   0x0(%rax)
test   %ebp,%ebp
jle    11b6 <isbinaryfile+0x66>
add    $0xffffffff,%ebp
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
jg     11a0 <isbinaryfile+0x50>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
xor    %eax,%eax
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 (i8*, i32, ...) bitcast (i32 (...)* @open to i32 (i8*, i32, ...)*)(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 %16
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i32 (i8*, ...) bitcast (i32 (...)* @perror to i32 (i8*, ...)*)(i8* %14)
unreachable
16: ; preds = %1
%17 = load i32, i32* %7
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%19 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i64, ...)*)(i32 %17, i8* %18, i64 256)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i8*, i8** %3
%24 = call i32 (i8*, ...) bitcast (i32 (...)* @perror to i32 (i8*, ...)*)(i8* %23)
unreachable
25: ; preds = %16
%26 = load i32, i32* %7
%27 = call i32 (i32, ...) bitcast (i32 (...)* @close to i32 (i32, ...)*)(i32 %26)
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
store i8* %28, i8** %5
br label %29
29: ; preds = %47, %25
%30 = load i32, i32* %6
%31 = add nsw i32 %30, -1
store i32 %31, i32* %6
%32 = icmp sgt i32 %30, 0
br i1 %32, label %33, label %48
33: ; preds = %29
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %5
%36 = load i8, i8* %34
%37 = sext i8 %36 to i32
%38 = and i32 %37, 255
store i32 %38, i32* %8
%39 = load i32, i32* %8
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %33
store i32 1, i32* %2
br label %49
42: ; preds = %33
%43 = load i32, i32* %8
%44 = and i32 %43, 128
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %42
store i32 1, i32* %2
br label %49
47: ; preds = %42
br label %29
48: ; preds = %29
store i32 0, i32* %2
br label %49
49: ; preds = %48, %46, %41
%50 = load i32, i32* %2
ret i32 %50
}

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