#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ mktemp(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ rename(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  FILE *dosfile;
  FILE *unixfile;
  int idx;
  int buf;
  char unixname[48];
  if (argc == 1) {
    printf("Usage :  dos2unix  [-f] file1 [file2 ... fileN]\n");
    printf("         Wildcards in file names will be expanded.\n");
    exit(1);
  }
  for (idx = 1; idx < argc; idx++) {
    printf("%s\n", argv[idx]);
    if (dosfile = fopen(argv[idx], "rb")) {
      strcpy(unixname, "d2uXXXXX");
      mktemp(unixname);
      unixfile = fopen(unixname, "wb");
      while ((buf = getc(dosfile)) != EOF) {
        if (buf != '\r')
          putc(buf, unixfile);
      }
      fclose(dosfile);
      fclose(unixfile);
      remove(argv[idx]);
      rename(unixname, argv[idx]);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11e6 <main+0x46>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12e7 <main+0x147>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe43(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12d4 <main+0x134>
lea    -0x60(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x60(%rbp),%rdi
call   10c0 <mktemp@plt>
lea    -0x60(%rbp),%rdi
lea    0xe18(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   10b0 <getc@plt>
mov    %eax,-0x28(%rbp)
mov    0x2d6f(%rip),%rcx
cmp    (%rcx),%eax
je     129c <main+0xfc>
cmpl   $0xd,-0x28(%rbp)
je     1297 <main+0xf7>
mov    -0x28(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1070 <putc@plt>
jmp    1266 <main+0xc6>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <remove@plt>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1090 <rename@plt>
jmp    12d9 <main+0x139>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ed <main+0x4d>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
cmp    $0x1,%edi
je     1294 <main+0xf4>
jle    1283 <main+0xe3>
mov    %rsi,%rbx
mov    %edi,%eax
mov    %rax,0x8(%rsp)
mov    $0x1,%r14d
lea    0x10(%rsp),%r12
mov    0x2e0f(%rip),%r13
jmp    1210 <main+0x70>
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1060 <fclose@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    (%rbx,%r14,8),%rdi
call   1030 <remove@plt>
mov    (%rbx,%r14,8),%rsi
mov    %r12,%rdi
call   1090 <rename@plt>
add    $0x1,%r14
cmp    0x8(%rsp),%r14
je     1283 <main+0xe3>
mov    (%rbx,%r14,8),%rdi
call   1050 <puts@plt>
mov    (%rbx,%r14,8),%rdi
lea    0xddc(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1205 <main+0x65>
mov    %rax,%rbp
mov    %r12,%rdi
lea    0xdc8(%rip),%rsi
call   1040 <strcpy@plt>
mov    %r12,%rdi
call   10c0 <mktemp@plt>
mov    %r12,%rdi
lea    0xdba(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   10b0 <getc@plt>
cmp    0x0(%r13),%eax
je     11e0 <main+0x40>
cmp    $0xd,%eax
je     1260 <main+0xc0>
mov    %eax,%edi
mov    %r15,%rsi
call   1070 <putc@plt>
jmp    1260 <main+0xc0>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd74(%rip),%rdi
call   1050 <puts@plt>
lea    0xd98(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [49 x i8] c"Usage : dos2unix [-f] file1 [file2 ... fileN]\0A\00"
@.str.1 = [52 x i8] c" Wildcards in file names will be expanded.\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [9 x i8] c"d2uXXXXX\00"
@.str.5 = [3 x i8] c"wb\00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [48 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
store i32 1, i32* %8
br label %18
18: ; preds = %75, %17
%19 = load i32, i32* %8
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %78
22: ; preds = %18
%23 = load i8**, i8*** %5
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = load i8**, i8*** %5
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %34, i32** %6
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %74
36: ; preds = %22
%37 = getelementptr inbounds [48 x i8], [48 x i8]* %10, i64 0, i64 0
%38 = call i32 @strcpy(i8* %37, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%39 = getelementptr inbounds [48 x i8], [48 x i8]* %10, i64 0, i64 0
%40 = call i32 @mktemp(i8* %39)
%41 = getelementptr inbounds [48 x i8], [48 x i8]* %10, i64 0, i64 0
%42 = call i32* @fopen(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %42, i32** %7
br label %43
43: ; preds = %55, %36
%44 = load i32*, i32** %6
%45 = call i32 @getc(i32* %44)
store i32 %45, i32* %9
%46 = load i32, i32* @EOF
%47 = icmp ne i32 %45, %46
br i1 %47, label %48, label %56
48: ; preds = %43
%49 = load i32, i32* %9
%50 = icmp ne i32 %49, 13
br i1 %50, label %51, label %55
51: ; preds = %48
%52 = load i32, i32* %9
%53 = load i32*, i32** %7
%54 = call i32 @putc(i32 %52, i32* %53)
br label %55
55: ; preds = %51, %48
br label %43
56: ; preds = %43
%57 = load i32*, i32** %6
%58 = call i32 @fclose(i32* %57)
%59 = load i32*, i32** %7
%60 = call i32 @fclose(i32* %59)
%61 = load i8**, i8*** %5
%62 = load i32, i32* %8
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8*, i8** %61, i64 %63
%65 = load i8*, i8** %64
%66 = call i32 @remove(i8* %65)
%67 = getelementptr inbounds [48 x i8], [48 x i8]* %10, i64 0, i64 0
%68 = load i8**, i8*** %5
%69 = load i32, i32* %8
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8*, i8** %68, i64 %70
%72 = load i8*, i8** %71
%73 = call i32 @rename(i8* %67, i8* %72)
br label %74
74: ; preds = %56, %22
br label %75
75: ; preds = %74
%76 = load i32, i32* %8
%77 = add nsw i32 %76, 1
store i32 %77, i32* %8
br label %18
78: ; preds = %18
ret i32 0
}

LLVM IR (-O2):
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [9 x i8] c"d2uXXXXX\00"
@.str.5 = [3 x i8] c"wb\00"
@EOF = global i32 0
@str = [48 x i8] c"Usage : dos2unix [-f] file1 [file2 ... fileN]\00"
@str.6 = [51 x i8] c" Wildcards in file names will be expanded.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [48 x i8]
%4 = getelementptr inbounds [48 x i8], [48 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 1
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %48
8: ; preds = %6
%9 = zext i32 %0 to i64
br label %14
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.6, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %8, %45
%15 = phi i64 [ 1, %8 ], [ %46, %45 ]
%16 = getelementptr inbounds i8*, i8** %1, i64 %15
%17 = load i8*, i8** %16
%18 = call i32 @puts(i8* dereferenceable(1) %17)
%19 = load i8*, i8** %16
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %45, label %22
22: ; preds = %14
%23 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%24 = call i32 @mktemp(i8* %4)
%25 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%26 = call i32 @getc(i32* %20)
%27 = load i32, i32* @EOF
%28 = icmp eq i32 %26, %27
br i1 %28, label %38, label %29
29: ; preds = %22, %34
%30 = phi i32 [ %35, %34 ], [ %26, %22 ]
%31 = icmp eq i32 %30, 13
br i1 %31, label %34, label %32
32: ; preds = %29
%33 = call i32 @putc(i32 %30, i32* %25)
br label %34
34: ; preds = %32, %29
%35 = call i32 @getc(i32* %20)
%36 = load i32, i32* @EOF
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %29
38: ; preds = %34, %22
%39 = call i32 @fclose(i32* %20)
%40 = call i32 @fclose(i32* %25)
%41 = load i8*, i8** %16
%42 = call i32 @remove(i8* %41)
%43 = load i8*, i8** %16
%44 = call i32 @rename(i8* %4, i8* %43)
br label %45
45: ; preds = %14, %38
%46 = add nuw nsw i64 %15, 1
%47 = icmp eq i64 %46, %9
br i1 %47, label %48, label %14
48: ; preds = %45, %6
ret i32 0
}