#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*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int main(void) {
  FILE *fin, *fdos, *flinux, *fmac;
  char buf[(1024 * 8)];
  int ret, i;
  if ((fin = fopen("file_in", "r")) == NULL ||
      (fdos = fopen("file_dos", "w")) == NULL ||
      (flinux = fopen("file_linux", "w")) == NULL ||
      (fmac = fopen("file_mac", "w")) == NULL) {
    perror("Open failed!");
    exit(1);
  }
  while ((ret = fread(buf, sizeof(char), (1024 * 8), fin)) > 0) {
    for (i = 0; i < ret; i++) {
      if (buf[i] == '\n') {
        fwrite("\r\n", sizeof(char), 2, fdos);
        fwrite("\n", sizeof(char), 1, flinux);
        fwrite("\r", sizeof(char), 1, fmac);
      } else {
        fwrite(&buf[i], sizeof(char), 1, fdos);
        fwrite(&buf[i], sizeof(char), 1, flinux);
        fwrite(&buf[i], sizeof(char), 1, fmac);
      }
    }
  }
  printf("Finish!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2040,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11f6 <main+0x96>
lea    0xe70(%rip),%rdi
lea    0xe72(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11f6 <main+0x96>
lea    0xe5a(%rip),%rdi
lea    0xe51(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11f6 <main+0x96>
lea    0xe44(%rip),%rdi
lea    0xe30(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    120c <main+0xac>
lea    0xe2c(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1211 <main+0xb1>
lea    -0x2030(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2000,%edx
call   1030 <fread@plt>
mov    %eax,-0x2034(%rbp)
cmp    $0x0,%eax
jle    133c <main+0x1dc>
movl   $0x0,-0x2038(%rbp)
mov    -0x2038(%rbp),%eax
cmp    -0x2034(%rbp),%eax
jge    1337 <main+0x1d7>
movslq -0x2038(%rbp),%rax
movsbl -0x2030(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    12bb <main+0x15b>
mov    -0x18(%rbp),%rcx
lea    0xdbd(%rip),%rdi
mov    $0x1,%esi
mov    $0x2,%edx
call   1080 <fwrite@plt>
mov    -0x20(%rbp),%rcx
lea    0xda4(%rip),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1080 <fwrite@plt>
mov    -0x28(%rbp),%rcx
lea    0xd8f(%rip),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1080 <fwrite@plt>
jmp    131e <main+0x1be>
movslq -0x2038(%rbp),%rax
lea    -0x2030(%rbp),%rdi
add    %rax,%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1080 <fwrite@plt>
movslq -0x2038(%rbp),%rax
lea    -0x2030(%rbp),%rdi
add    %rax,%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1080 <fwrite@plt>
movslq -0x2038(%rbp),%rax
lea    -0x2030(%rbp),%rdi
add    %rax,%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1080 <fwrite@plt>
jmp    1323 <main+0x1c3>
mov    -0x2038(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2038(%rbp)
jmp    1244 <main+0xe4>
jmp    1211 <main+0xb1>
lea    0xcf8(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x2040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2018,%rsp
lea    0xe78(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     12b0 <main+0x140>
lea    0xe62(%rip),%rdi
lea    0xe64(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     12b0 <main+0x140>
lea    0xe4c(%rip),%rdi
lea    0xe43(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     12b0 <main+0x140>
mov    %rax,%r12
lea    0xe38(%rip),%rdi
lea    0xe24(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     12b0 <main+0x140>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x2000,%edx
mov    (%rsp),%rcx
call   1040 <fread@plt>
test   %eax,%eax
jle    1290 <main+0x120>
mov    %eax,%r13d
xor    %r15d,%r15d
jmp    125d <main+0xed>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    0x8(%rsp),%rsi
call   1050 <fputc@plt>
mov    %ebp,%r14d
mov    %ebp,%edi
mov    %r12,%rsi
call   1050 <fputc@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
add    $0x1,%r15
cmp    %r15,%r13
je     1200 <main+0x90>
movsbl 0x10(%rsp,%r15,1),%ebp
cmp    $0xa,%ebp
jne    1230 <main+0xc0>
lea    0xdc7(%rip),%rdi
mov    $0x1,%esi
mov    $0x2,%edx
mov    0x8(%rsp),%rcx
call   1090 <fwrite@plt>
mov    $0xd,%r14d
mov    $0xa,%ebp
jmp    123f <main+0xcf>
lea    0xda2(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x2018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd72(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"file_in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"file_dos\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [11 x i8] c"file_linux\00"
@.str.5 = [9 x i8] c"file_mac\00"
@.str.6 = [13 x i8] c"Open failed!\00"
@.str.7 = [3 x i8] c"\0D\0A\00"
@.str.8 = [2 x i8] c"\0A\00"
@.str.9 = [2 x i8] c"\0D\00"
@.str.10 = [9 x i8] c"Finish!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [8192 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %2
%10 = icmp eq i32* %9, null
br i1 %10, label %20, label %11
11: ; preds = %0
%12 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %12, i32** %3
%13 = icmp eq i32* %12, null
br i1 %13, label %20, label %14
14: ; preds = %11
%15 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %15, i32** %4
%16 = icmp eq i32* %15, null
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %18, i32** %5
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %17, %14, %11, %0
%21 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %17
br label %24
24: ; preds = %68, %23
%25 = getelementptr inbounds [8192 x i8], [8192 x i8]* %6, i64 0, i64 0
%26 = load i32*, i32** %2
%27 = call i32 @fread(i8* %25, i32 1, i32 8192, i32* %26)
store i32 %27, i32* %7
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %69
29: ; preds = %24
store i32 0, i32* %8
br label %30
30: ; preds = %65, %29
%31 = load i32, i32* %8
%32 = load i32, i32* %7
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %68
34: ; preds = %30
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [8192 x i8], [8192 x i8]* %6, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 10
br i1 %40, label %41, label %48
41: ; preds = %34
%42 = load i32*, i32** %3
%43 = call i32 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 1, i32 2, i32* %42)
%44 = load i32*, i32** %4
%45 = call i32 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 1, i32 1, i32* %44)
%46 = load i32*, i32** %5
%47 = call i32 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i32 1, i32 1, i32* %46)
br label %64
48: ; preds = %34
%49 = load i32, i32* %8
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [8192 x i8], [8192 x i8]* %6, i64 0, i64 %50
%52 = load i32*, i32** %3
%53 = call i32 @fwrite(i8* %51, i32 1, i32 1, i32* %52)
%54 = load i32, i32* %8
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [8192 x i8], [8192 x i8]* %6, i64 0, i64 %55
%57 = load i32*, i32** %4
%58 = call i32 @fwrite(i8* %56, i32 1, i32 1, i32* %57)
%59 = load i32, i32* %8
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [8192 x i8], [8192 x i8]* %6, i64 0, i64 %60
%62 = load i32*, i32** %5
%63 = call i32 @fwrite(i8* %61, i32 1, i32 1, i32* %62)
br label %64
64: ; preds = %48, %41
br label %65
65: ; preds = %64
%66 = load i32, i32* %8
%67 = add nsw i32 %66, 1
store i32 %67, i32* %8
br label %30
68: ; preds = %30
br label %24
69: ; preds = %24
%70 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"file_in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"file_dos\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [11 x i8] c"file_linux\00"
@.str.5 = [9 x i8] c"file_mac\00"
@.str.6 = [13 x i8] c"Open failed!\00"
@.str.7 = [3 x i8] c"\0D\0A\00"
@str = [8 x i8] c"Finish!\00"
define i32 @main() {
%1 = alloca [8192 x i8]
%2 = getelementptr inbounds [8192 x i8], [8192 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %17, label %5
5: ; preds = %0
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %17, label %8
8: ; preds = %5
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %17, label %11
11: ; preds = %8
%12 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = call i32 @fread(i8* %2, i32 1, i32 8192, i32* %3)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %23, label %43
17: ; preds = %11, %8, %5, %0
%18 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %36
%21 = call i32 @fread(i8* %2, i32 1, i32 8192, i32* %3)
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %43
23: ; preds = %14, %20
%24 = phi i32 [ %21, %20 ], [ %15, %14 ]
%25 = zext i32 %24 to i64
br label %26
26: ; preds = %23, %36
%27 = phi i64 [ 0, %23 ], [ %41, %36 ]
%28 = getelementptr inbounds [8192 x i8], [8192 x i8]* %1, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 10
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = tail call i32 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 1, i32 2, i32* %6)
br label %36
33: ; preds = %26
%34 = sext i8 %29 to i32
%35 = tail call i32 @fputc(i32 %34, i32* %6)
br label %36
36: ; preds = %31, %33
%37 = phi i32 [ 10, %31 ], [ %34, %33 ]
%38 = phi i32 [ 13, %31 ], [ %34, %33 ]
%39 = tail call i32 @fputc(i32 %37, i32* %9)
%40 = tail call i32 @fputc(i32 %38, i32* %12)
%41 = add nuw nsw i64 %27, 1
%42 = icmp eq i64 %41, %25
br i1 %42, label %20, label %26
43: ; preds = %20, %14
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
ret i32 0
}