#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*/ ClearTagsInFile(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                   char *, char *);
scalar_t__ FileExists(char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *tmpfile();
int main(int argc, const char **argv) {
  if (argc < 3) {
    fprintf(stderr, "Usage: ./removeComments source destination.\n");
    return 1;
  }
  FILE *from = fopen(argv[1], "r");
  if (!from) {
    fprintf(stderr, "Error opening file \"%s\"", argv[1]);
    return 2;
  }
  if (FileExists(argv[2])) {
    fprintf(stderr, "Destination file with the same name already exists in the "
                    "directory.\n");
    return 3;
  }
  FILE *to = fopen(argv[2], "w");
  if (!to) {
    fprintf(stderr, "Error creating a destination file.\n");
    return 4;
  }
  FILE *tmpf = tmpfile();
  if (!tmpf) {
    fprintf(stderr, "Error creating a temporary file.\n");
    return 5;
  }
  ClearTagsInFile(from, tmpf, "/*", "*/");
  ClearTagsInFile(tmpf, to, "//", "\n");
  fclose(tmpf);
  fclose(from);
  fclose(to);
  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)
cmpl   $0x3,-0x8(%rbp)
jge    11a3 <main+0x43>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1302 <main+0x1a2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe7b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f1 <main+0x91>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe51(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1302 <main+0x1a2>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <FileExists@plt>
cmp    $0x0,%rax
je     122b <main+0xcb>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    1302 <main+0x1a2>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe53(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1271 <main+0x111>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x4,-0x4(%rbp)
jmp    1302 <main+0x1a2>
mov    $0x0,%al
call   1040 <tmpfile@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12aa <main+0x14a>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
lea    0xe1c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x5,-0x4(%rbp)
jmp    1302 <main+0x1a2>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    0xe1c(%rip),%rdx
lea    0xe18(%rip),%rcx
call   1050 <ClearTagsInFile@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    0xe07(%rip),%rdx
lea    0xdd6(%rip),%rcx
call   1050 <ClearTagsInFile@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%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   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jg     118d <main+0x2d>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%ebp
jmp    12ab <main+0x14b>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xe92(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d7 <main+0x77>
mov    %rax,%rbx
mov    0x10(%rbp),%rdi
call   1080 <FileExists@plt>
test   %rax,%rax
je     11fc <main+0x9c>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x3,%ebp
jmp    12ab <main+0x14b>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rdx
lea    0xe44(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%ebp
jmp    12ab <main+0x14b>
mov    0x10(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1271 <main+0x111>
mov    %rax,%r14
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <tmpfile@plt>
test   %rax,%rax
je     128f <main+0x12f>
mov    %rax,%r15
lea    0xea9(%rip),%rdx
lea    0xea5(%rip),%rcx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <ClearTagsInFile@plt>
lea    0xe96(%rip),%rdx
lea    0xe65(%rip),%rcx
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <ClearTagsInFile@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    12ab <main+0x14b>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
lea    0xe0e(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x4,%ebp
jmp    12ab <main+0x14b>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
lea    0xe14(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x5,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [45 x i8] c"Usage: ./removeComments source destination.\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"Error opening file \22%s\22\00"
@.str.3 = [70 x i8] c"Destination file with the same name already exists in the directory.\0A\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [36 x i8] c"Error creating a destination file.\0A\00"
@.str.6 = [34 x i8] c"Error creating a temporary file.\0A\00"
@.str.7 = [3 x i8] c"/*\00"
@.str.8 = [3 x i8] c"*/\00"
@.str.9 = [3 x i8] c"//\00"
@.str.10 = [2 x i8] c"\0A\00"
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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %66
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = icmp ne i32* %19, null
br i1 %20, label %27, label %21
21: ; preds = %14
%22 = load i32, i32* @stderr
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %25)
store i32 2, i32* %3
br label %66
27: ; preds = %14
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i64 @FileExists(i8* %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %27
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.3, i64 0, i64 0))
store i32 3, i32* %3
br label %66
36: ; preds = %27
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = call i32* @fopen(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %40, i32** %7
%41 = load i32*, i32** %7
%42 = icmp ne i32* %41, null
br i1 %42, label %46, label %43
43: ; preds = %36
%44 = load i32, i32* @stderr
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
store i32 4, i32* %3
br label %66
46: ; preds = %36
%47 = call i32* (...) @tmpfile()
store i32* %47, i32** %8
%48 = load i32*, i32** %8
%49 = icmp ne i32* %48, null
br i1 %49, label %53, label %50
50: ; preds = %46
%51 = load i32, i32* @stderr
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
store i32 5, i32* %3
br label %66
53: ; preds = %46
%54 = load i32*, i32** %6
%55 = load i32*, i32** %8
%56 = call i32 @ClearTagsInFile(i32* %54, i32* %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%57 = load i32*, i32** %8
%58 = load i32*, i32** %7
%59 = call i32 @ClearTagsInFile(i32* %57, i32* %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%60 = load i32*, i32** %8
%61 = call i32 @fclose(i32* %60)
%62 = load i32*, i32** %6
%63 = call i32 @fclose(i32* %62)
%64 = load i32*, i32** %7
%65 = call i32 @fclose(i32* %64)
store i32 0, i32* %3
br label %66
66: ; preds = %53, %50, %43, %33, %21, %11
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [45 x i8] c"Usage: ./removeComments source destination.\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"Error opening file \22%s\22\00"
@.str.3 = [70 x i8] c"Destination file with the same name already exists in the directory.\0A\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [36 x i8] c"Error creating a destination file.\0A\00"
@.str.6 = [34 x i8] c"Error creating a temporary file.\0A\00"
@.str.7 = [3 x i8] c"/*\00"
@.str.8 = [3 x i8] c"*/\00"
@.str.9 = [3 x i8] c"//\00"
@.str.10 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %43
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %8
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %14)
br label %43
16: ; preds = %7
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i64 @FileExists(i8* %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.3, i64 0, i64 0))
br label %43
24: ; preds = %16
%25 = load i8*, i8** %17
%26 = tail call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
br label %43
31: ; preds = %24
%32 = tail call i32* (...) @tmpfile()
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i32, i32* @stderr
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
br label %43
37: ; preds = %31
%38 = tail call i32 @ClearTagsInFile(i32* %10, i32* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%39 = tail call i32 @ClearTagsInFile(i32* %32, i32* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%40 = tail call i32 @fclose(i32* %32)
%41 = tail call i32 @fclose(i32* %10)
%42 = tail call i32 @fclose(i32* %26)
br label %43
43: ; preds = %12, %21, %34, %37, %28, %4
%44 = phi i32 [ 1, %4 ], [ 3, %21 ], [ 2, %12 ], [ 4, %28 ], [ 0, %37 ], [ 5, %34 ]
ret i32 %44
}