#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*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int strlen(char *);
int is_dos_eol(char *filename) {
  int dos_eol = 0;
  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] == '\r') {
      dos_eol = 1;
      break;
    }
  }
  return dos_eol;
}


x86 assembly (clang, -O0):
<is_dos_eol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeaf(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x408(%rbp)
lea    -0x400(%rbp),%rdi
mov    -0x408(%rbp),%rdx
mov    $0x3e8,%esi
call   1040 <fgets@plt>
movl   $0x0,-0x40c(%rbp)
mov    -0x40c(%rbp),%eax
mov    %eax,-0x410(%rbp)
lea    -0x400(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x410(%rbp),%eax
cmp    %ecx,%eax
jge    11e4 <is_dos_eol+0xb4>
movslq -0x40c(%rbp),%rax
movsbl -0x400(%rbp,%rax,1),%eax
ff
cmp    $0xd,%eax
jne    11cb <is_dos_eol+0x9b>
movl   $0x1,-0xc(%rbp)
jmp    11e4 <is_dos_eol+0xb4>
jmp    11d0 <is_dos_eol+0xa0>
mov    -0x40c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40c(%rbp)
jmp    117f <is_dos_eol+0x4f>
mov    -0xc(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_dos_eol>:
push   %r14
push   %rbx
sub    $0x3e8,%rsp
lea    0xebf(%rip),%rsi
call   1050 <fopen@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3e8,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1189 <is_dos_eol+0x59>
xor    %ebx,%ebx
mov    %rsp,%r14
nopw   0x0(%rax,%rax,1)
cmpb   $0xd,(%rsp,%rbx,1)
je     118d <is_dos_eol+0x5d>
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1170 <is_dos_eol+0x40>
xor    %eax,%eax
jmp    1192 <is_dos_eol+0x62>
mov    $0x1,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define i32 @is_dos_eol(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, 13
%17 = add nuw nsw i64 %13, 1
br i1 %16, label %18, label %8
18: ; preds = %8, %12, %1
%19 = phi i32 [ 0, %1 ], [ 1, %12 ], [ 0, %8 ]
ret i32 %19
}