#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*/ fclose(int /*<<< orphan*/ *);
int filtblocktag(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
char *generatefilename(char *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  char *newfilename = NULL;
  FILE *sourcefp = NULL;
  FILE *destfp = NULL;
  int charcount = 0;
  if (argc < 2) {
    printf("Please specify the name of the source file.\n");
    return 0;
  }
  newfilename = generatefilename(argv[1]);
  if (newfilename != NULL) {
    destfp = fopen(newfilename, "w+");
  } else {
    printf("Fail to open the destination file. \n");
    return 0;
  }
  sourcefp = fopen(argv[1], "r+");
  if (sourcefp != NULL && destfp != NULL) {
    charcount = filtblocktag(destfp, sourcefp);
    fclose(destfp);
    fclose(sourcefp);
    if (newfilename != NULL) {
      free(newfilename);
    }
    newfilename = NULL;
    return charcount;
  } else {
    printf("Fail to open the file. \n");
    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)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11b7 <main+0x57>
lea    0xe5a(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    128e <main+0x12e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <generatefilename@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ec <main+0x8c>
mov    -0x18(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
jmp    1204 <main+0xa4>
lea    0xe3d(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    128e <main+0x12e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe42(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     127b <main+0x11b>
cmpq   $0x0,-0x28(%rbp)
je     127b <main+0x11b>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <filtblocktag@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x18(%rbp)
je     1268 <main+0x108>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128e <main+0x12e>
lea    0xdd6(%rip),%rdi
call   1050 <printf@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    $0x1,%edi
jg     1175 <main+0x15>
lea    0xecf(%rip),%rdi
jmp    11f1 <main+0x91>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1080 <generatefilename@plt>
test   %rax,%rax
je     11e1 <main+0x81>
mov    %rax,%r15
lea    0xe70(%rip),%rsi
mov    %rax,%rdi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    0x8(%rbx),%rdi
lea    0xe5d(%rip),%rsi
call   1060 <fopen@plt>
test   %r14,%r14
je     11ea <main+0x8a>
mov    %rax,%rbx
test   %rax,%rax
je     11ea <main+0x8a>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <filtblocktag@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
jmp    11f8 <main+0x98>
lea    0xe1e(%rip),%rdi
jmp    11f1 <main+0x91>
lea    0xe39(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"Please specify the name of the source file.\0A\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [37 x i8] c"Fail to open the destination file. \0A\00"
@.str.3 = [3 x i8] c"r+\00"
@.str.4 = [25 x i8] c"Fail to open the file. \0A\00"
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*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i32* null, i32** %7
store i32* null, i32** %8
store i32 0, i32* %9
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
store i32 0, 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 = call i8* @generatefilename(i8* %17)
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = load i8*, i8** %6
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %8
br label %26
24: ; preds = %14
%25 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %53
26: ; preds = %21
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %30, i32** %7
%31 = load i32*, i32** %7
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %51
33: ; preds = %26
%34 = load i32*, i32** %8
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %51
36: ; preds = %33
%37 = load i32*, i32** %8
%38 = load i32*, i32** %7
%39 = call i32 @filtblocktag(i32* %37, i32* %38)
store i32 %39, i32* %9
%40 = load i32*, i32** %8
%41 = call i32 @fclose(i32* %40)
%42 = load i32*, i32** %7
%43 = call i32 @fclose(i32* %42)
%44 = load i8*, i8** %6
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %49
46: ; preds = %36
%47 = load i8*, i8** %6
%48 = call i32 @free(i8* %47)
br label %49
49: ; preds = %46, %36
store i8* null, i8** %6
%50 = load i32, i32* %9
store i32 %50, i32* %3
br label %53
51: ; preds = %33, %26
%52 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %53
53: ; preds = %51, %49, %24, %12
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"w+\00"
@.str.3 = [3 x i8] c"r+\00"
@str = [36 x i8] c"Fail to open the destination file. \00"
@str.5 = [24 x i8] c"Fail to open the file. \00"
@str.6 = [44 x i8] c"Please specify the name of the source file.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.6, i64 0, i64 0))
br label %27
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i8* @generatefilename(i8* %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %18, label %11
11: ; preds = %6
%12 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = load i8*, i8** %7
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp ne i32* %14, null
%16 = icmp ne i32* %12, null
%17 = and i1 %16, %15
br i1 %17, label %20, label %25
18: ; preds = %6
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %27
20: ; preds = %11
%21 = tail call i32 @filtblocktag(i32* %12, i32* %14)
%22 = tail call i32 @fclose(i32* %12)
%23 = tail call i32 @fclose(i32* %14)
%24 = tail call i32 @free(i8* %9)
br label %27
25: ; preds = %11
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.5, i64 0, i64 0))
br label %27
27: ; preds = %25, %20, %18, %4
%28 = phi i32 [ 0, %4 ], [ %21, %20 ], [ 0, %25 ], [ 0, %18 ]
ret i32 %28
}