#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*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int strlen(char *);
int is_ascii(char *filename) {
  int ascii = 1;
  int c = -1;
  char l[1000];
  FILE *f;
  f = fopen(filename, "rb");
  fgets(l, 1000, f);
  int i;
  for (i = 0; i < strlen(l); i++) {
    if (l[i] > 127 || l[i] == 0x01) {
      ascii = 0;
      break;
    }
  }
  fclose(f);
  return ascii;
}


x86 assembly (clang, -O0):
<is_ascii>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x408(%rbp)
lea    -0x400(%rbp),%rdi
mov    -0x408(%rbp),%rdx
mov    $0x3e8,%esi
call   1050 <fgets@plt>
movl   $0x0,-0x40c(%rbp)
mov    -0x40c(%rbp),%eax
mov    %eax,-0x410(%rbp)
lea    -0x400(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x410(%rbp),%eax
cmp    %ecx,%eax
jge    1213 <is_ascii+0xd3>
movslq -0x40c(%rbp),%rax
movsbl -0x400(%rbp,%rax,1),%eax
ff
cmp    $0x7f,%eax
jg     11ee <is_ascii+0xae>
movslq -0x40c(%rbp),%rax
movsbl -0x400(%rbp,%rax,1),%eax
ff
cmp    $0x1,%eax
jne    11fa <is_ascii+0xba>
movl   $0x0,-0xc(%rbp)
jmp    1213 <is_ascii+0xd3>
jmp    11ff <is_ascii+0xbf>
mov    -0x40c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40c(%rbp)
jmp    1196 <is_ascii+0x56>
mov    -0x408(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xc(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_ascii>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x3e8,%rsp
lea    0xeac(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r15
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x3e8,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    $0x1,%r14d
test   %eax,%eax
jle    11ae <is_ascii+0x6e>
xor    %ebx,%ebx
mov    %rsp,%rbp
cs nopw 0x0(%rax,%rax,1)
cmpb   $0x1,(%rsp,%rbx,1)
je     11ab <is_ascii+0x6b>
add    $0x1,%rbx
mov    %rbp,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1190 <is_ascii+0x50>
jmp    11ae <is_ascii+0x6e>
xor    %r14d,%r14d
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %r14d,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
define i32 @is_ascii(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1000 x i8]
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %2
store i32 1, i32* %3
store i32 -1, i32* %4
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %6
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%11 = load i32*, i32** %6
%12 = call i32 @fgets(i8* %10, i32 1000, i32* %11)
store i32 0, i32* %7
br label %13
13: ; preds = %34, %1
%14 = load i32, i32* %7
%15 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%16 = call i32 @strlen(i8* %15)
%17 = icmp slt i32 %14, %16
br i1 %17, label %18, label %37
18: ; preds = %13
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp sgt i32 %23, 127
br i1 %24, label %32, label %25
25: ; preds = %18
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 1
br i1 %31, label %32, label %33
32: ; preds = %25, %18
store i32 0, i32* %3
br label %37
33: ; preds = %25
br label %34
34: ; preds = %33
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %13
37: ; preds = %32, %13
%38 = load i32*, i32** %6
%39 = call i32 @fclose(i32* %38)
%40 = load i32, i32* %3
ret i32 %40
}

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