#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 fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
scalar_t__ remove(char *);
scalar_t__ rename(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int i;
  FILE *src_fs;
  FILE *dst_fs;
  int ch;
  int foundCr = 0;
  if (argc < 2) {
    fprintf(stderr, "Usage: 2dos file ...\n");
    exit(1);
  }
  for (i = 1; i < argc; i++) {
    if ((src_fs = fopen(argv[i], "rb")) == NULL) {
      fprintf(stderr, "Unable to open file %s\n", argv[i]);
      exit(1);
    }
    if ((dst_fs = fopen("2dos.tmp", "wb")) == NULL) {
      fprintf(stderr, "Unable to open 2dos.tmp for output\n");
      exit(1);
    }
    while ((ch = fgetc(src_fs)) != EOF) {
      if (foundCr) {
        fputc(0x0D, dst_fs);
        fputc(0x0A, dst_fs);
        switch (ch) {
        case 0x0D: {
          break;
        }
        case 0x0A: {
          foundCr = 0;
          break;
        }
        default: {
          foundCr = 0;
          fputc(ch, dst_fs);
          break;
        }
        }
      } else {
        switch (ch) {
        case 0x0D: {
          foundCr = 1;
          break;
        }
        case 0x0A: {
          fputc(0x0D, dst_fs);
          fputc(0x0A, dst_fs);
          break;
        }
        default: {
          fputc(ch, dst_fs);
          break;
        }
        }
      }
    }
    fclose(src_fs);
    fclose(dst_fs);
    if (remove(argv[i]) != 0) {
      perror(argv[i]);
      exit(1);
    }
    if (rename("2dos.tmp", argv[i]) != 0) {
      perror(argv[i]);
      exit(1);
    }
  }
  exit(0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11d8 <main+0x48>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1414 <main+0x284>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe18(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    123e <main+0xae>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdec(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xdec(%rip),%rdi
lea    0xdee(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1280 <main+0xf0>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
lea    0xdce(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1285 <main+0xf5>
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2d50(%rip),%rcx
cmp    (%rcx),%eax
je     137c <main+0x1ec>
cmpl   $0x0,-0x30(%rbp)
je     1314 <main+0x184>
mov    -0x28(%rbp),%rsi
mov    $0xd,%edi
call   1060 <fputc@plt>
mov    -0x28(%rbp),%rsi
mov    $0xa,%edi
call   1060 <fputc@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0xa,%eax
je     12f0 <main+0x160>
jmp    12da <main+0x14a>
mov    -0x34(%rbp),%eax
sub    $0xd,%eax
jne    12fc <main+0x16c>
jmp    12eb <main+0x15b>
jmp    130f <main+0x17f>
movl   $0x0,-0x30(%rbp)
jmp    130f <main+0x17f>
movl   $0x0,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1060 <fputc@plt>
jmp    1377 <main+0x1e7>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0xa,%eax
je     1345 <main+0x1b5>
jmp    1328 <main+0x198>
mov    -0x38(%rbp),%eax
sub    $0xd,%eax
jne    1366 <main+0x1d6>
jmp    1339 <main+0x1a9>
movl   $0x1,-0x30(%rbp)
jmp    1372 <main+0x1e2>
mov    -0x28(%rbp),%rsi
mov    $0xd,%edi
call   1060 <fputc@plt>
mov    -0x28(%rbp),%rsi
mov    $0xa,%edi
call   1060 <fputc@plt>
jmp    1372 <main+0x1e2>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1060 <fputc@plt>
jmp    1377 <main+0x1e7>
jmp    1285 <main+0xf5>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <remove@plt>
cmp    $0x0,%rax
je     13c4 <main+0x234>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xc5a(%rip),%rdi
call   10a0 <rename@plt>
cmp    $0x0,%rax
je     1401 <main+0x271>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1406 <main+0x276>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11df <main+0x4f>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jge    11c4 <main+0x34>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %rsi,%r14
mov    %edi,%eax
mov    %rax,0x8(%rsp)
xor    %r13d,%r13d
mov    $0x1,%r12d
lea    0xe53(%rip),%rbp
mov    0x2e03(%rip),%r15
mov    %rsi,0x10(%rsp)
nopw   0x0(%rax,%rax,1)
mov    (%r14,%r12,8),%rdi
lea    0xe1b(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1301 <main+0x171>
mov    %rax,%rbx
mov    %rbp,%rdi
lea    0xe24(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1326 <main+0x196>
mov    %rax,%rbp
jmp    123e <main+0xae>
nopl   0x0(%rax)
mov    %r14d,%edi
mov    %rbp,%rsi
call   1060 <fputc@plt>
xor    %r13d,%r13d
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    %eax,%r14d
cmp    (%r15),%eax
je     12b0 <main+0x120>
test   %r13d,%r13d
je     1280 <main+0xf0>
mov    $0xd,%edi
mov    %rbp,%rsi
call   1060 <fputc@plt>
mov    $0xa,%edi
mov    %rbp,%rsi
call   1060 <fputc@plt>
cmp    $0xd,%r14d
je     12a0 <main+0x110>
cmp    $0xa,%r14d
je     123b <main+0xab>
jmp    1230 <main+0xa0>
nopl   0x0(%rax,%rax,1)
cmp    $0xd,%r14d
je     12a8 <main+0x118>
cmp    $0xa,%r14d
jne    1230 <main+0xa0>
mov    $0xd,%edi
mov    %rbp,%rsi
call   1060 <fputc@plt>
mov    $0xa,%edi
jmp    1233 <main+0xa3>
mov    $0x1,%r13d
jmp    123e <main+0xae>
mov    $0x1,%r13d
jmp    123e <main+0xae>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    0x10(%rsp),%r14
mov    (%r14,%r12,8),%rdi
call   1030 <remove@plt>
mov    (%r14,%r12,8),%rsi
test   %rax,%rax
jne    133b <main+0x1ab>
lea    0xd53(%rip),%rbp
mov    %rbp,%rdi
call   10a0 <rename@plt>
test   %rax,%rax
jne    1340 <main+0x1b0>
add    $0x1,%r12
cmp    0x8(%rsp),%r12
jne    11f0 <main+0x60>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    0x2cd0(%rip),%rax
mov    (%rax),%edi
mov    (%r14,%r12,8),%rdx
lea    0xd04(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2cab(%rip),%rax
mov    (%rax),%edi
lea    0xd07(%rip),%rsi
jmp    11b3 <main+0x23>
mov    %rsi,%rdi
jmp    1344 <main+0x1b4>
mov    (%r14,%r12,8),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"Usage: 2dos file ...\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [24 x i8] c"Unable to open file %s\0A\00"
@.str.3 = [9 x i8] c"2dos.tmp\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [36 x i8] c"Unable to open 2dos.tmp for output\0A\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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
store i32 1, i32* %6
br label %18
18: ; preds = %119, %17
%19 = load i32, i32* %6
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %122
22: ; preds = %18
%23 = load i8**, i8*** %5
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %28, i32** %7
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %39
30: ; preds = %22
%31 = load i32, i32* @stderr
%32 = load i8**, i8*** %5
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %32, i64 %34
%36 = load i8*, i8** %35
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %36)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %22
%40 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %40, i32** %8
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %46
42: ; preds = %39
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %39
br label %47
47: ; preds = %81, %46
%48 = load i32*, i32** %7
%49 = call i32 @fgetc(i32* %48)
store i32 %49, i32* %9
%50 = load i32, i32* @EOF
%51 = icmp ne i32 %49, %50
br i1 %51, label %52, label %82
52: ; preds = %47
%53 = load i32, i32* %10
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %68
55: ; preds = %52
%56 = load i32*, i32** %8
%57 = call i32 @fputc(i32 13, i32* %56)
%58 = load i32*, i32** %8
%59 = call i32 @fputc(i32 10, i32* %58)
%60 = load i32, i32* %9
switch i32 %60, label %63 [
i32 13, label %61
i32 10, label %62
]
61: ; preds = %55
br label %67
62: ; preds = %55
store i32 0, i32* %10
br label %67
63: ; preds = %55
store i32 0, i32* %10
%64 = load i32, i32* %9
%65 = load i32*, i32** %8
%66 = call i32 @fputc(i32 %64, i32* %65)
br label %67
67: ; preds = %63, %62, %61
br label %81
68: ; preds = %52
%69 = load i32, i32* %9
switch i32 %69, label %76 [
i32 13, label %70
i32 10, label %71
]
70: ; preds = %68
store i32 1, i32* %10
br label %80
71: ; preds = %68
%72 = load i32*, i32** %8
%73 = call i32 @fputc(i32 13, i32* %72)
%74 = load i32*, i32** %8
%75 = call i32 @fputc(i32 10, i32* %74)
br label %80
76: ; preds = %68
%77 = load i32, i32* %9
%78 = load i32*, i32** %8
%79 = call i32 @fputc(i32 %77, i32* %78)
br label %80
80: ; preds = %76, %71, %70
br label %81
81: ; preds = %80, %67
br label %47
82: ; preds = %47
%83 = load i32*, i32** %7
%84 = call i32 @fclose(i32* %83)
%85 = load i32*, i32** %8
%86 = call i32 @fclose(i32* %85)
%87 = load i8**, i8*** %5
%88 = load i32, i32* %6
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i8*, i8** %87, i64 %89
%91 = load i8*, i8** %90
%92 = call i64 @remove(i8* %91)
%93 = icmp ne i64 %92, 0
br i1 %93, label %94, label %102
94: ; preds = %82
%95 = load i8**, i8*** %5
%96 = load i32, i32* %6
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i8*, i8** %95, i64 %97
%99 = load i8*, i8** %98
%100 = call i32 @perror(i8* %99)
%101 = call i32 @exit(i32 1)
unreachable
102: ; preds = %82
%103 = load i8**, i8*** %5
%104 = load i32, i32* %6
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds i8*, i8** %103, i64 %105
%107 = load i8*, i8** %106
%108 = call i64 @rename(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %107)
%109 = icmp ne i64 %108, 0
br i1 %109, label %110, label %118
110: ; preds = %102
%111 = load i8**, i8*** %5
%112 = load i32, i32* %6
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds i8*, i8** %111, i64 %113
%115 = load i8*, i8** %114
%116 = call i32 @perror(i8* %115)
%117 = call i32 @exit(i32 1)
unreachable
118: ; preds = %102
br label %119
119: ; preds = %118
%120 = load i32, i32* %6
%121 = add nsw i32 %120, 1
store i32 %121, i32* %6
br label %18
122: ; preds = %18
%123 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"Usage: 2dos file ...\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [24 x i8] c"Unable to open file %s\0A\00"
@.str.3 = [9 x i8] c"2dos.tmp\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [36 x i8] c"Unable to open 2dos.tmp for output\0A\00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %12
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %67
%11 = icmp eq i64 %70, %5
br i1 %11, label %75, label %12
12: ; preds = %4, %10
%13 = phi i64 [ 1, %4 ], [ %70, %10 ]
%14 = phi i32 [ 0, %4 ], [ %57, %10 ]
%15 = getelementptr inbounds i8*, i8** %1, i64 %13
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %24
19: ; preds = %12
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %15
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %12
%25 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %31, label %27
27: ; preds = %24
%28 = tail call i32 @fgetc(i32* %17)
%29 = load i32, i32* @EOF
%30 = icmp eq i32 %28, %29
br i1 %30, label %56, label %35
31: ; preds = %24
%32 = load i32, i32* @stderr
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %27, %51
%36 = phi i32 [ %53, %51 ], [ %28, %27 ]
%37 = phi i32 [ %52, %51 ], [ %14, %27 ]
%38 = icmp eq i32 %37, 0
br i1 %38, label %45, label %39
39: ; preds = %35
%40 = tail call i32 @fputc(i32 13, i32* %25)
%41 = tail call i32 @fputc(i32 10, i32* %25)
switch i32 %36, label %43 [
i32 13, label %51
i32 10, label %42
]
42: ; preds = %39
br label %51
43: ; preds = %39
%44 = tail call i32 @fputc(i32 %36, i32* %25)
br label %51
45: ; preds = %35
switch i32 %36, label %49 [
i32 13, label %51
i32 10, label %46
]
46: ; preds = %45
%47 = tail call i32 @fputc(i32 13, i32* %25)
%48 = tail call i32 @fputc(i32 10, i32* %25)
br label %51
49: ; preds = %45
%50 = tail call i32 @fputc(i32 %36, i32* %25)
br label %51
51: ; preds = %45, %46, %49, %42, %43, %39
%52 = phi i32 [ 0, %43 ], [ 0, %42 ], [ 1, %39 ], [ 0, %49 ], [ 0, %46 ], [ 1, %45 ]
%53 = tail call i32 @fgetc(i32* %17)
%54 = load i32, i32* @EOF
%55 = icmp eq i32 %53, %54
br i1 %55, label %56, label %35
56: ; preds = %51, %27
%57 = phi i32 [ %14, %27 ], [ %52, %51 ]
%58 = tail call i32 @fclose(i32* %17)
%59 = tail call i32 @fclose(i32* %25)
%60 = load i8*, i8** %15
%61 = tail call i64 @remove(i8* %60)
%62 = icmp eq i64 %61, 0
%63 = load i8*, i8** %15
br i1 %62, label %67, label %64
64: ; preds = %56
%65 = tail call i32 @perror(i8* %63)
%66 = tail call i32 @exit(i32 1)
unreachable
67: ; preds = %56
%68 = tail call i64 @rename(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %63)
%69 = icmp eq i64 %68, 0
%70 = add nuw nsw i64 %13, 1
br i1 %69, label %10, label %71
71: ; preds = %67
%72 = load i8*, i8** %15
%73 = tail call i32 @perror(i8* %72)
%74 = tail call i32 @exit(i32 1)
unreachable
75: ; preds = %10
%76 = tail call i32 @exit(i32 0)
unreachable
}