#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ recomment(int /*<<< orphan*/ *, int /*<<< orphan*/ *, char);
int main(int argc, char *argv[]) {
  char ch;
  FILE *in, *out;
  in = fopen("input.dat", "r");
  out = fopen("output.dat", "w");
  if (in == NULL) {
    perror("input.dat");
    return 1;
  }
  if (out == NULL) {
    perror("output.dat");
    return 1;
  }
  while ((ch = fgetc(in)) != EOF) {
    recomment(in, out, ch);
  }
  fclose(in);
  fclose(out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
lea    0xe96(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    0xe88(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b7 <main+0x67>
lea    0xe5a(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    122f <main+0xdf>
cmpq   $0x0,-0x28(%rbp)
jne    11da <main+0x8a>
lea    0xe43(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    122f <main+0xdf>
jmp    11df <main+0x8f>
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2df3(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1216 <main+0xc6>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
movsbl -0x11(%rbp),%edx
call   1050 <recomment@plt>
jmp    11df <main+0x8f>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xea4(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe9a(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
test   %rbx,%rbx
je     11d3 <main+0x83>
mov    %rax,%r14
test   %rax,%rax
je     11dc <main+0x8c>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    0x2e4e(%rip),%r15
cmp    (%r15),%al
je     11bb <main+0x6b>
nop
movsbl %al,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <recomment@plt>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    (%r15),%al
jne    11a0 <main+0x50>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe26(%rip),%rdi
jmp    11e3 <main+0x93>
lea    0xe29(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
jmp    11cd <main+0x7d>

LLVM IR (-O0):
@.str = [10 x i8] c"input.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"output.dat\00"
@.str.3 = [2 x i8] c"w\00"
@EOF = global i8 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i32*
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 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** %7
%10 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 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* %10, i32** %8
%11 = load i32*, i32** %7
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %38
15: ; preds = %2
%16 = load i32*, i32** %8
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %38
20: ; preds = %15
br label %21
21: ; preds = %28, %20
%22 = load i32*, i32** %7
%23 = call signext i8 @fgetc(i32* %22)
store i8 %23, i8* %6
%24 = sext i8 %23 to i32
%25 = load i8, i8* @EOF
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %24, %26
br i1 %27, label %28, label %33
28: ; preds = %21
%29 = load i32*, i32** %7
%30 = load i32*, i32** %8
%31 = load i8, i8* %6
%32 = call i32 @recomment(i32* %29, i32* %30, i8 signext %31)
br label %21
33: ; preds = %21
%34 = load i32*, i32** %7
%35 = call i32 @fclose(i32* %34)
%36 = load i32*, i32** %8
%37 = call i32 @fclose(i32* %36)
store i32 0, i32* %3
br label %38
38: ; preds = %33, %18, %13
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [10 x i8] c"input.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"output.dat\00"
@.str.3 = [2 x i8] c"w\00"
@EOF = global i8 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%5 = icmp eq i32* %3, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %25
8: ; preds = %2
%9 = icmp eq i32* %4, null
br i1 %9, label %14, label %10
10: ; preds = %8
%11 = tail call signext i8 @fgetc(i32* %3)
%12 = load i8, i8* @EOF
%13 = icmp eq i8 %11, %12
br i1 %13, label %22, label %16
14: ; preds = %8
%15 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %25
16: ; preds = %10, %16
%17 = phi i8 [ %19, %16 ], [ %11, %10 ]
%18 = tail call i32 @recomment(i32* %3, i32* %4, i8 signext %17)
%19 = tail call signext i8 @fgetc(i32* %3)
%20 = load i8, i8* @EOF
%21 = icmp eq i8 %19, %20
br i1 %21, label %22, label %16
22: ; preds = %16, %10
%23 = tail call i32 @fclose(i32* %3)
%24 = tail call i32 @fclose(i32* %4)
br label %25
25: ; preds = %22, %14, %6
%26 = phi i32 [ 1, %6 ], [ 1, %14 ], [ 0, %22 ]
ret i32 %26
}