#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int is_ascii(char *);
int is_dos_eol(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ to_unix_line_endings(char *, char *);
void dos2unix_str(char *filename, char *ucontents) {
  char contents[100000];
  FILE *f;
  f = fopen(filename, "rb");
  fread(contents, 1, 100000, f);
  fclose(f);
  if (is_ascii(filename) == 1 && is_dos_eol(filename) == 1) {
    to_unix_line_endings(contents, ucontents);
    return;
  }
  strcpy(ucontents, contents);
}


x86 assembly (clang, -O0):
<dos2unix_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x186c0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x186b8(%rbp)
lea    -0x186b0(%rbp),%rdi
mov    -0x186b8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x186a0,%edx
call   1040 <fread@plt>
mov    -0x186b8(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x8(%rbp),%rdi
call   1080 <is_ascii@plt>
cmp    $0x1,%eax
jne    11fc <dos2unix_str+0x8c>
mov    -0x8(%rbp),%rdi
call   1070 <is_dos_eol@plt>
cmp    $0x1,%eax
jne    11fc <dos2unix_str+0x8c>
lea    -0x186b0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <to_unix_line_endings@plt>
jmp    120c <dos2unix_str+0x9c>
mov    -0x10(%rbp),%rdi
lea    -0x186b0(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x186c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dos2unix_str>:
push   %r15
push   %r14
push   %rbx
sub    $0x186a0,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe77(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x186a0,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1080 <is_ascii@plt>
cmp    $0x1,%eax
jne    11d5 <dos2unix_str+0x65>
mov    %r15,%rdi
call   1070 <is_dos_eol@plt>
cmp    $0x1,%eax
jne    11d5 <dos2unix_str+0x65>
mov    %rsp,%rdi
mov    %r14,%rsi
call   1060 <to_unix_line_endings@plt>
jmp    11e0 <dos2unix_str+0x70>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
add    $0x186a0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define void @dos2unix_str(i8* %0, i8* %1) {
%3 = alloca [100000 x i8]
%4 = getelementptr inbounds [100000 x i8], [100000 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @fread(i8* %4, i32 1, i32 100000, i32* %5)
%7 = tail call i32 @fclose(i32* %5)
%8 = tail call i32 @is_ascii(i8* %0)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = tail call i32 @is_dos_eol(i8* %0)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @to_unix_line_endings(i8* %4, i8* %1)
br label %17
15: ; preds = %10, %2
%16 = call i32 @strcpy(i8* %1, i8* %4)
br label %17
17: ; preds = %15, %13
ret void
}