#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int dos2unix(char *src_filename, char *dest_filename) {
  FILE *in;
  FILE *out;
  int c;
  if ((in = fopen(src_filename, "r")) == NULL)
    return -1;
  if ((out = fopen(dest_filename, "w")) == NULL) {
    fclose(in);
    return -1;
  }
  while ((c = fgetc(in)) != EOF) {
    if (c != '\r') {
      fputc(c, out);
    }
  }
  fclose(in);
  fclose(out);
  return 0;
}


x86 assembly (clang, -O0):
<dos2unix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    117a <dos2unix+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1201 <dos2unix+0xc1>
mov    -0x18(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11ad <dos2unix+0x6d>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1201 <dos2unix+0xc1>
jmp    11b2 <dos2unix+0x72>
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2e23(%rip),%rcx
cmp    (%rcx),%eax
je     11e8 <dos2unix+0xa8>
cmpl   $0xd,-0x2c(%rbp)
je     11e3 <dos2unix+0xa3>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1050 <fputc@plt>
jmp    11b2 <dos2unix+0x72>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dos2unix>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbp
lea    0xeb2(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ba <dos2unix+0x7a>
mov    %rax,%rbx
lea    0xea0(%rip),%rsi
mov    %rbp,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c1 <dos2unix+0x81>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    0x2e67(%rip),%rbp
jmp    1198 <dos2unix+0x58>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    0x0(%rbp),%eax
je     11ae <dos2unix+0x6e>
cmp    $0xd,%eax
je     1190 <dos2unix+0x50>
mov    %eax,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
jmp    1190 <dos2unix+0x50>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %ebp,%ebp
jmp    11c9 <dos2unix+0x89>
mov    $0xffffffff,%ebp
jmp    11d1 <dos2unix+0x91>
mov    $0xffffffff,%ebp
mov    %rbx,%r14
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@EOF = global i32 0
define i32 @dos2unix(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %27, label %5
5: ; preds = %2
%6 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %23, label %8
8: ; preds = %5
%9 = tail call i32 @fgetc(i32* %3)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %21, label %12
12: ; preds = %8, %17
%13 = phi i32 [ %18, %17 ], [ %9, %8 ]
%14 = icmp eq i32 %13, 13
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 @fputc(i32 %13, i32* %6)
br label %17
17: ; preds = %15, %12
%18 = tail call i32 @fgetc(i32* %3)
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %12
21: ; preds = %17, %8
%22 = tail call i32 @fclose(i32* %3)
br label %23
23: ; preds = %5, %21
%24 = phi i32* [ %6, %21 ], [ %3, %5 ]
%25 = phi i32 [ 0, %21 ], [ -1, %5 ]
%26 = tail call i32 @fclose(i32* %24)
br label %27
27: ; preds = %23, %2
%28 = phi i32 [ -1, %2 ], [ %25, %23 ]
ret i32 %28
}