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


x86 assembly (clang, -O0):
<dos2unix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30d60,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <is_ascii@plt>
cmp    $0x1,%eax
jne    1269 <dos2unix+0xe9>
mov    -0x10(%rbp),%rdi
call   1070 <is_dos_eol@plt>
cmp    $0x1,%eax
jne    1269 <dos2unix+0xe9>
mov    -0x10(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30d58(%rbp)
lea    -0x186b0(%rbp),%rdi
mov    -0x30d58(%rbp),%rcx
mov    $0x1,%esi
mov    $0x186a0,%edx
call   1030 <fread@plt>
mov    -0x30d58(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x186b0(%rbp),%rdi
lea    -0x30d50(%rbp),%rsi
call   1060 <to_unix_line_endings@plt>
mov    -0x10(%rbp),%rdi
lea    0xdf2(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30d58(%rbp)
lea    -0x30d50(%rbp),%rax
mov    %rax,-0x30d60(%rbp)
lea    -0x30d50(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x30d60(%rbp),%rdi
mov    %eax,%edx
mov    -0x30d58(%rbp),%rcx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
mov    -0x30d58(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1270 <dos2unix+0xf0>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30d60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dos2unix>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30d40,%rsp
mov    %rdi,%rbx
call   1080 <is_ascii@plt>
mov    $0x1,%ebp
cmp    $0x1,%eax
jne    1229 <dos2unix+0xa9>
mov    %rbx,%rdi
call   1070 <is_dos_eol@plt>
cmp    $0x1,%eax
jne    1229 <dos2unix+0xa9>
lea    0xe4b(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbp
lea    0x186a0(%rsp),%r14
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x186a0,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    %rsp,%rbp
mov    %r14,%rdi
mov    %rbp,%rsi
call   1060 <to_unix_line_endings@plt>
lea    0xe09(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x30d40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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