#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: 2mac 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("2mac.tmp", "wb")) == NULL) {
      fprintf(stderr, "Unable to open 2mac.tmp for output\n");
      exit(1);
    }
    while ((ch = fgetc(src_fs)) != EOF) {
      if (foundCr) {
        fputc(0x0D, 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);
          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("2mac.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    13f8 <main+0x268>
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     1360 <main+0x1d0>
cmpl   $0x0,-0x30(%rbp)
je     1306 <main+0x176>
mov    -0x28(%rbp),%rsi
mov    $0xd,%edi
call   1060 <fputc@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0xa,%eax
je     12e2 <main+0x152>
jmp    12cc <main+0x13c>
mov    -0x34(%rbp),%eax
sub    $0xd,%eax
jne    12ee <main+0x15e>
jmp    12dd <main+0x14d>
jmp    1301 <main+0x171>
movl   $0x0,-0x30(%rbp)
jmp    1301 <main+0x171>
movl   $0x0,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1060 <fputc@plt>
jmp    135b <main+0x1cb>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0xa,%eax
je     1337 <main+0x1a7>
jmp    131a <main+0x18a>
mov    -0x38(%rbp),%eax
sub    $0xd,%eax
jne    134a <main+0x1ba>
jmp    132b <main+0x19b>
movl   $0x1,-0x30(%rbp)
jmp    1356 <main+0x1c6>
mov    -0x28(%rbp),%rsi
mov    $0xd,%edi
call   1060 <fputc@plt>
jmp    1356 <main+0x1c6>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1060 <fputc@plt>
jmp    135b <main+0x1cb>
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     13a8 <main+0x218>
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    0xc76(%rip),%rdi
call   10a0 <rename@plt>
cmp    $0x0,%rax
je     13e5 <main+0x255>
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    13ea <main+0x25a>
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     12f1 <main+0x161>
mov    %rax,%rbx
mov    %rbp,%rdi
lea    0xe24(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1316 <main+0x186>
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     12a0 <main+0x110>
test   %r13d,%r13d
je     1270 <main+0xe0>
mov    $0xd,%edi
mov    %rbp,%rsi
call   1060 <fputc@plt>
cmp    $0xd,%r14d
je     1290 <main+0x100>
cmp    $0xa,%r14d
je     123b <main+0xab>
jmp    1230 <main+0xa0>
xchg   %ax,%ax
cmp    $0xd,%r14d
je     1298 <main+0x108>
cmp    $0xa,%r14d
jne    1230 <main+0xa0>
mov    $0xd,%edi
jmp    1233 <main+0xa3>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
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    132b <main+0x19b>
lea    0xd63(%rip),%rbp
mov    %rbp,%rdi
call   10a0 <rename@plt>
test   %rax,%rax
jne    1330 <main+0x1a0>
add    $0x1,%r12
cmp    0x8(%rsp),%r12
jne    11f0 <main+0x60>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    0x2ce0(%rip),%rax
mov    (%rax),%edi
mov    (%r14,%r12,8),%rdx
lea    0xd14(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
lea    0xd17(%rip),%rsi
jmp    11b3 <main+0x23>
mov    %rsi,%rdi
jmp    1334 <main+0x1a4>
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: 2mac 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"2mac.tmp\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [36 x i8] c"Unable to open 2mac.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 = %115, %17
%19 = load i32, i32* %6
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %118
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 = %77, %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 %78
52: ; preds = %47
%53 = load i32, i32* %10
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %66
55: ; preds = %52
%56 = load i32*, i32** %8
%57 = call i32 @fputc(i32 13, i32* %56)
%58 = load i32, i32* %9
switch i32 %58, label %61 [
i32 13, label %59
i32 10, label %60
]
59: ; preds = %55
br label %65
60: ; preds = %55
store i32 0, i32* %10
br label %65
61: ; preds = %55
store i32 0, i32* %10
%62 = load i32, i32* %9
%63 = load i32*, i32** %8
%64 = call i32 @fputc(i32 %62, i32* %63)
br label %65
65: ; preds = %61, %60, %59
br label %77
66: ; preds = %52
%67 = load i32, i32* %9
switch i32 %67, label %72 [
i32 13, label %68
i32 10, label %69
]
68: ; preds = %66
store i32 1, i32* %10
br label %76
69: ; preds = %66
%70 = load i32*, i32** %8
%71 = call i32 @fputc(i32 13, i32* %70)
br label %76
72: ; preds = %66
%73 = load i32, i32* %9
%74 = load i32*, i32** %8
%75 = call i32 @fputc(i32 %73, i32* %74)
br label %76
76: ; preds = %72, %69, %68
br label %77
77: ; preds = %76, %65
br label %47
78: ; preds = %47
%79 = load i32*, i32** %7
%80 = call i32 @fclose(i32* %79)
%81 = load i32*, i32** %8
%82 = call i32 @fclose(i32* %81)
%83 = load i8**, i8*** %5
%84 = load i32, i32* %6
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8*, i8** %83, i64 %85
%87 = load i8*, i8** %86
%88 = call i64 @remove(i8* %87)
%89 = icmp ne i64 %88, 0
br i1 %89, label %90, label %98
90: ; preds = %78
%91 = load i8**, i8*** %5
%92 = load i32, i32* %6
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8*, i8** %91, i64 %93
%95 = load i8*, i8** %94
%96 = call i32 @perror(i8* %95)
%97 = call i32 @exit(i32 1)
unreachable
98: ; preds = %78
%99 = load i8**, i8*** %5
%100 = load i32, i32* %6
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds i8*, i8** %99, i64 %101
%103 = load i8*, i8** %102
%104 = call i64 @rename(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %103)
%105 = icmp ne i64 %104, 0
br i1 %105, label %106, label %114
106: ; preds = %98
%107 = load i8**, i8*** %5
%108 = load i32, i32* %6
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds i8*, i8** %107, i64 %109
%111 = load i8*, i8** %110
%112 = call i32 @perror(i8* %111)
%113 = call i32 @exit(i32 1)
unreachable
114: ; preds = %98
br label %115
115: ; preds = %114
%116 = load i32, i32* %6
%117 = add nsw i32 %116, 1
store i32 %117, i32* %6
br label %18
118: ; preds = %18
%119 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"Usage: 2mac 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"2mac.tmp\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [36 x i8] c"Unable to open 2mac.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 = %65
%11 = icmp eq i64 %68, %5
br i1 %11, label %73, label %12
12: ; preds = %4, %10
%13 = phi i64 [ 1, %4 ], [ %68, %10 ]
%14 = phi i32 [ 0, %4 ], [ %55, %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 %54, 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, %49
%36 = phi i32 [ %51, %49 ], [ %28, %27 ]
%37 = phi i32 [ %50, %49 ], [ %14, %27 ]
%38 = icmp eq i32 %37, 0
br i1 %38, label %44, label %39
39: ; preds = %35
%40 = tail call i32 @fputc(i32 13, i32* %25)
switch i32 %36, label %42 [
i32 13, label %49
i32 10, label %41
]
41: ; preds = %39
br label %49
42: ; preds = %39
%43 = tail call i32 @fputc(i32 %36, i32* %25)
br label %49
44: ; preds = %35
switch i32 %36, label %47 [
i32 13, label %49
i32 10, label %45
]
45: ; preds = %44
%46 = tail call i32 @fputc(i32 13, i32* %25)
br label %49
47: ; preds = %44
%48 = tail call i32 @fputc(i32 %36, i32* %25)
br label %49
49: ; preds = %44, %45, %47, %41, %42, %39
%50 = phi i32 [ 0, %42 ], [ 0, %41 ], [ 1, %39 ], [ 0, %47 ], [ 0, %45 ], [ 1, %44 ]
%51 = tail call i32 @fgetc(i32* %17)
%52 = load i32, i32* @EOF
%53 = icmp eq i32 %51, %52
br i1 %53, label %54, label %35
54: ; preds = %49, %27
%55 = phi i32 [ %14, %27 ], [ %50, %49 ]
%56 = tail call i32 @fclose(i32* %17)
%57 = tail call i32 @fclose(i32* %25)
%58 = load i8*, i8** %15
%59 = tail call i64 @remove(i8* %58)
%60 = icmp eq i64 %59, 0
%61 = load i8*, i8** %15
br i1 %60, label %65, label %62
62: ; preds = %54
%63 = tail call i32 @perror(i8* %61)
%64 = tail call i32 @exit(i32 1)
unreachable
65: ; preds = %54
%66 = tail call i64 @rename(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %61)
%67 = icmp eq i64 %66, 0
%68 = add nuw nsw i64 %13, 1
br i1 %67, label %10, label %69
69: ; preds = %65
%70 = load i8*, i8** %15
%71 = tail call i32 @perror(i8* %70)
%72 = tail call i32 @exit(i32 1)
unreachable
73: ; preds = %10
%74 = tail call i32 @exit(i32 0)
unreachable
}