#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 EOF;
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int istextfile(FILE *f) {
  int ch, i;
  if (f == NULL)
    return (1);
  rewind(f);
  for (i = 0; i <= 768; i++) {
    ch = fgetc(f);
    if (ch == '\0') {
      rewind(f);
      return (0);
    }
    if (ch == EOF)
      break;
  }
  rewind(f);
  return (1);
}


x86 assembly (clang, -O0):
<istextfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1143 <istextfile+0x23>
movl   $0x1,-0x4(%rbp)
jmp    11c5 <istextfile+0xa5>
mov    -0x10(%rbp),%rdi
call   1030 <rewind@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x300,-0x18(%rbp)
jg     11b5 <istextfile+0x95>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    118b <istextfile+0x6b>
mov    -0x10(%rbp),%rdi
call   1030 <rewind@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c5 <istextfile+0xa5>
mov    -0x14(%rbp),%eax
mov    0x2e53(%rip),%rcx
cmp    (%rcx),%eax
jne    11a2 <istextfile+0x82>
jmp    11b5 <istextfile+0x95>
jmp    11a7 <istextfile+0x87>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1153 <istextfile+0x33>
mov    -0x10(%rbp),%rdi
call   1030 <rewind@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<istextfile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     116d <istextfile+0x4d>
mov    %rdi,%r14
call   1030 <rewind@plt>
mov    $0x300,%ebx
mov    0x2ea8(%rip),%r15
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1040 <fgetc@plt>
test   %eax,%eax
je     1174 <istextfile+0x54>
sub    $0x1,%ebx
setb   %cl
cmp    (%r15),%eax
je     1176 <istextfile+0x56>
test   %cl,%cl
je     1150 <istextfile+0x30>
jmp    1176 <istextfile+0x56>
mov    $0x1,%ebp
jmp    117e <istextfile+0x5e>
xor    %ebp,%ebp
mov    %r14,%rdi
call   1030 <rewind@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @istextfile(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
%6 = load i32*, i32** %3
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 1, i32* %2
br label %35
9: ; preds = %1
%10 = load i32*, i32** %3
%11 = call i32 @rewind(i32* %10)
store i32 0, i32* %5
br label %12
12: ; preds = %29, %9
%13 = load i32, i32* %5
%14 = icmp sle i32 %13, 768
br i1 %14, label %15, label %32
15: ; preds = %12
%16 = load i32*, i32** %3
%17 = call i32 @fgetc(i32* %16)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i32*, i32** %3
%22 = call i32 @rewind(i32* %21)
store i32 0, i32* %2
br label %35
23: ; preds = %15
%24 = load i32, i32* %4
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %23
br label %32
28: ; preds = %23
br label %29
29: ; preds = %28
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %12
32: ; preds = %27, %12
%33 = load i32*, i32** %3
%34 = call i32 @rewind(i32* %33)
store i32 1, i32* %2
br label %35
35: ; preds = %32, %20, %8
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @istextfile(i32* %0) {
%2 = icmp eq i32* %0, null
br i1 %2, label %18, label %3
3: ; preds = %1
%4 = tail call i32 @rewind(i32* %0)
br label %5
5: ; preds = %9, %3
%6 = phi i32 [ 0, %3 ], [ %12, %9 ]
%7 = tail call i32 @fgetc(i32* %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %5
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %7, %10
%12 = add nuw nsw i32 %6, 1
%13 = icmp eq i32 %12, 769
%14 = select i1 %11, i1 true, i1 %13
br i1 %14, label %15, label %5
15: ; preds = %9, %5
%16 = phi i32 [ 0, %5 ], [ 1, %9 ]
%17 = tail call i32 @rewind(i32* %0)
br label %18
18: ; preds = %15, %1
%19 = phi i32 [ 1, %1 ], [ %16, %15 ]
ret i32 %19
}