#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 */

/* Variables and functions */
int O_CREAT;
int O_RDONLY;
int O_RDWR;
int /*<<< orphan*/ close(int);
int open(char *, int);
scalar_t__ read(int, char *, int);
int show_args(char **);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd1, fd2;
  char c = 0;
  if (argc != 3)
    return show_args(argv);
  fd1 = open(argv[1], O_RDONLY);
  fd2 = open(argv[2], O_RDWR | O_CREAT);
  while (read(fd1, &c, sizeof(char)) != 0) {
    if (c == 0x0d) {
      c = 0x9b;
      write(fd2, &c, sizeof(char));
    } else if (c == 0x0a) {
    } else {
      write(fd2, &c, sizeof(char));
    }
  }
  close(fd1);
  close(fd2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x19(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1185 <main+0x35>
mov    -0x10(%rbp),%rdi
call   1040 <show_args@plt>
mov    %eax,-0x4(%rbp)
jmp    1246 <main+0xf6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
mov    0x2e42(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
cmp    $0x0,%rax
je     122f <main+0xdf>
movsbl -0x19(%rbp),%eax
cmp    $0xd,%eax
jne    1202 <main+0xb2>
movb   $0x9b,-0x19(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    122a <main+0xda>
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
jne    1214 <main+0xc4>
jmp    1225 <main+0xd5>
mov    -0x18(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    122a <main+0xda>
jmp    11c0 <main+0x70>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbp
movb   $0x0,0xf(%rsp)
cmp    $0x3,%edi
jne    11f8 <main+0xa8>
mov    0x8(%rbp),%rdi
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,%ebx
mov    0x10(%rbp),%rdi
mov    0x2e58(%rip),%rax
mov    0x2e69(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,%r14d
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1060 <read@plt>
test   %rax,%rax
je     1208 <main+0xb8>
lea    0xf(%rsp),%rbp
jmp    11e4 <main+0x94>
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
test   %rax,%rax
je     1208 <main+0xb8>
movzbl 0xf(%rsp),%eax
cmp    $0xa,%al
je     11d0 <main+0x80>
cmp    $0xd,%al
jne    11c0 <main+0x70>
movb   $0x9b,0xf(%rsp)
jmp    11c0 <main+0x70>
mov    %rbp,%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <show_args@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    %r14d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@O_RDWR = global i32 0
@O_CREAT = 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 i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8 0, i8* %8
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = call i32 @show_args(i8** %12)
store i32 %13, i32* %3
br label %53
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = load i32, i32* @O_RDONLY
%19 = call i32 @open(i8* %17, i32 %18)
store i32 %19, i32* %6
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDWR
%24 = load i32, i32* @O_CREAT
%25 = or i32 %23, %24
%26 = call i32 @open(i8* %22, i32 %25)
store i32 %26, i32* %7
br label %27
27: ; preds = %47, %14
%28 = load i32, i32* %6
%29 = call i64 @read(i32 %28, i8* %8, i32 1)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %48
31: ; preds = %27
%32 = load i8, i8* %8
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 13
br i1 %34, label %35, label %38
35: ; preds = %31
store i8 -101, i8* %8
%36 = load i32, i32* %7
%37 = call i32 @write(i32 %36, i8* %8, i32 1)
br label %47
38: ; preds = %31
%39 = load i8, i8* %8
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 10
br i1 %41, label %42, label %43
42: ; preds = %38
br label %46
43: ; preds = %38
%44 = load i32, i32* %7
%45 = call i32 @write(i32 %44, i8* %8, i32 1)
br label %46
46: ; preds = %43, %42
br label %47
47: ; preds = %46, %35
br label %27
48: ; preds = %27
%49 = load i32, i32* %6
%50 = call i32 @close(i32 %49)
%51 = load i32, i32* %7
%52 = call i32 @close(i32 %51)
store i32 0, i32* %3
br label %53
53: ; preds = %48, %11
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i8
store i8 0, i8* %3
%4 = icmp eq i32 %0, 3
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @show_args(i8** %1)
br label %31
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_RDONLY
%11 = tail call i32 @open(i8* %9, i32 %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_RDWR
%15 = load i32, i32* @O_CREAT
%16 = or i32 %15, %14
%17 = tail call i32 @open(i8* %13, i32 %16)
%18 = call i64 @read(i32 %11, i8* %3, i32 1)
%19 = icmp eq i64 %18, 0
br i1 %19, label %28, label %20
20: ; preds = %7, %25
%21 = load i8, i8* %3
switch i8 %21, label %23 [
i8 13, label %22
i8 10, label %25
]
22: ; preds = %20
store i8 -101, i8* %3
br label %23
23: ; preds = %20, %22
%24 = call i32 @write(i32 %17, i8* %3, i32 1)
br label %25
25: ; preds = %23, %20
%26 = call i64 @read(i32 %11, i8* %3, i32 1)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %20
28: ; preds = %25, %7
%29 = tail call i32 @close(i32 %11)
%30 = tail call i32 @close(i32 %17)
br label %31
31: ; preds = %28, %5
%32 = phi i32 [ %6, %5 ], [ 0, %28 ]
ret i32 %32
}