#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*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ system(char *);
int main() {
  FILE *fp1, *fp2, *fp3;
  int iWordCount = 0, iLineCount = 0;
  char cCharacter;
  fp1 = fopen("f1.txt", "r");
  fp2 = fopen("f2.txt", "r");
  fp3 = fopen("f3.txt", "w+");
  while ((cCharacter = fgetc(fp1)) != EOF) {
    fputc(cCharacter, fp3);
  }
  while ((cCharacter = fgetc(fp2)) != EOF) {
    fputc(cCharacter, fp3);
  }
  rewind(fp3);
  while ((cCharacter = fgetc(fp3)) != EOF) {
    if (cCharacter == '\n') {
      iLineCount++;
      iWordCount++;
    } else if (cCharacter == '\t' || cCharacter == ' ')
      iWordCount++;
    printf("%c", cCharacter);
  }
  fclose(fp1);
  fclose(fp2);
  fclose(fp3);
  printf("\n\nNumber of lines is : %d\n", iLineCount);
  printf("\n\nNumber of words is : %d\n", iWordCount);
  printf("\nOutput of command : wc f3.txt -lw\n");
  system("wc f3.txt -lw");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
lea    0xe6c(%rip),%rdi
lea    0xe6c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe5e(%rip),%rdi
lea    0xe55(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe4e(%rip),%rdi
lea    0xe4e(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %al,-0x29(%rbp)
movsbl %al,%eax
mov    0x2e00(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1207 <main+0x97>
mov    -0x29(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1080 <fputc@plt>
jmp    11d2 <main+0x62>
jmp    120c <main+0x9c>
mov    -0x18(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %al,-0x29(%rbp)
movsbl %al,%eax
mov    0x2dc6(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1241 <main+0xd1>
mov    -0x29(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1080 <fputc@plt>
jmp    120c <main+0x9c>
mov    -0x20(%rbp),%rdi
call   1060 <rewind@plt>
mov    -0x20(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %al,-0x29(%rbp)
movsbl %al,%eax
mov    0x2d88(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     12ce <main+0x15e>
movsbl -0x29(%rbp),%eax
cmp    $0xa,%eax
jne    128f <main+0x11f>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12b7 <main+0x147>
movsbl -0x29(%rbp),%eax
cmp    $0x9,%eax
je     12a9 <main+0x139>
movsbl -0x29(%rbp),%eax
cmp    $0x20,%eax
jne    12b2 <main+0x142>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12b7 <main+0x147>
movsbl -0x29(%rbp),%esi
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    124a <main+0xda>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%esi
lea    0xd2a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xd34(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd57(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe5e(%rip),%rdi
lea    0xe5e(%rip),%rbx
mov    %rbx,%rsi
call   10b0 <fopen@plt>
mov    %rax,%r14
lea    0xe4e(%rip),%rdi
mov    %rbx,%rsi
call   10b0 <fopen@plt>
mov    %rax,%r15
lea    0xe43(%rip),%rdi
lea    0xe43(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1090 <fgetc@plt>
mov    0x2dfd(%rip),%r13
cmp    0x0(%r13),%al
je     122b <main+0x9b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
mov    %rbx,%rsi
call   10a0 <fputc@plt>
mov    %r14,%rdi
call   1090 <fgetc@plt>
cmp    0x0(%r13),%al
jne    1200 <main+0x70>
jmp    122b <main+0x9b>
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
mov    %rbx,%rsi
call   10a0 <fputc@plt>
mov    %r15,%rdi
call   1090 <fgetc@plt>
cmp    0x0(%r13),%al
jne    1220 <main+0x90>
mov    %rbx,%rdi
call   1080 <rewind@plt>
mov    %rbx,%rdi
call   1090 <fgetc@plt>
xor    %ebp,%ebp
mov    $0x0,%r12d
cmp    0x0(%r13),%al
jne    12b9 <main+0x129>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xda4(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdae(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdb9(%rip),%rdi
call   1040 <puts@plt>
lea    0xdc2(%rip),%rdi
call   1060 <system@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r12d,%r12d
xor    %ebp,%ebp
jmp    12dd <main+0x14d>
add    $0x1,%ebp
movsbl %al,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1090 <fgetc@plt>
cmp    0x0(%r13),%al
je     1257 <main+0xc7>
cmp    $0x9,%al
je     12c0 <main+0x130>
cmp    $0x20,%al
je     12c0 <main+0x130>
cmp    $0xa,%al
jne    12c3 <main+0x133>
add    $0x1,%r12d
jmp    12c0 <main+0x130>

LLVM IR (-O0):
@.str = [7 x i8] c"f1.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"f2.txt\00"
@.str.3 = [7 x i8] c"f3.txt\00"
@.str.4 = [3 x i8] c"w+\00"
@EOF = global i8 0
@.str.5 = [3 x i8] c"%c\00"
@.str.6 = [27 x i8] c"\0A\0ANumber of lines is : %d\0A\00"
@.str.7 = [27 x i8] c"\0A\0ANumber of words is : %d\0A\00"
@.str.8 = [36 x i8] c"\0AOutput of command : wc f3.txt -lw\0A\00"
@.str.9 = [14 x i8] c"wc f3.txt -lw\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %5
store i32 0, i32* %6
%8 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %2
%9 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %3
%10 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %10, i32** %4
br label %11
11: ; preds = %18, %0
%12 = load i32*, i32** %2
%13 = call signext i8 @fgetc(i32* %12)
store i8 %13, i8* %7
%14 = sext i8 %13 to i32
%15 = load i8, i8* @EOF
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %14, %16
br i1 %17, label %18, label %22
18: ; preds = %11
%19 = load i8, i8* %7
%20 = load i32*, i32** %4
%21 = call i32 @fputc(i8 signext %19, i32* %20)
br label %11
22: ; preds = %11
br label %23
23: ; preds = %30, %22
%24 = load i32*, i32** %3
%25 = call signext i8 @fgetc(i32* %24)
store i8 %25, i8* %7
%26 = sext i8 %25 to i32
%27 = load i8, i8* @EOF
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %26, %28
br i1 %29, label %30, label %34
30: ; preds = %23
%31 = load i8, i8* %7
%32 = load i32*, i32** %4
%33 = call i32 @fputc(i8 signext %31, i32* %32)
br label %23
34: ; preds = %23
%35 = load i32*, i32** %4
%36 = call i32 @rewind(i32* %35)
br label %37
37: ; preds = %65, %34
%38 = load i32*, i32** %4
%39 = call signext i8 @fgetc(i32* %38)
store i8 %39, i8* %7
%40 = sext i8 %39 to i32
%41 = load i8, i8* @EOF
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %40, %42
br i1 %43, label %44, label %69
44: ; preds = %37
%45 = load i8, i8* %7
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 10
br i1 %47, label %48, label %53
48: ; preds = %44
%49 = load i32, i32* %6
%50 = add nsw i32 %49, 1
store i32 %50, i32* %6
%51 = load i32, i32* %5
%52 = add nsw i32 %51, 1
store i32 %52, i32* %5
br label %65
53: ; preds = %44
%54 = load i8, i8* %7
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 9
br i1 %56, label %61, label %57
57: ; preds = %53
%58 = load i8, i8* %7
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 32
br i1 %60, label %61, label %64
61: ; preds = %57, %53
%62 = load i32, i32* %5
%63 = add nsw i32 %62, 1
store i32 %63, i32* %5
br label %64
64: ; preds = %61, %57
br label %65
65: ; preds = %64, %48
%66 = load i8, i8* %7
%67 = sext i8 %66 to i32
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %67)
br label %37
69: ; preds = %37
%70 = load i32*, i32** %2
%71 = call i32 @fclose(i32* %70)
%72 = load i32*, i32** %3
%73 = call i32 @fclose(i32* %72)
%74 = load i32*, i32** %4
%75 = call i32 @fclose(i32* %74)
%76 = load i32, i32* %6
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i32 %76)
%78 = load i32, i32* %5
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %78)
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0))
%81 = call i32 @system(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"f1.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"f2.txt\00"
@.str.3 = [7 x i8] c"f3.txt\00"
@.str.4 = [3 x i8] c"w+\00"
@EOF = global i8 0
@.str.6 = [27 x i8] c"\0A\0ANumber of lines is : %d\0A\00"
@.str.7 = [27 x i8] c"\0A\0ANumber of words is : %d\0A\00"
@.str.9 = [14 x i8] c"wc f3.txt -lw\00"
@str = [35 x i8] c"\0AOutput of command : wc f3.txt -lw\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%4 = tail call signext i8 @fgetc(i32* %1)
%5 = load i8, i8* @EOF
%6 = icmp eq i8 %4, %5
br i1 %6, label %7, label %11
7: ; preds = %11, %0
%8 = tail call signext i8 @fgetc(i32* %2)
%9 = load i8, i8* @EOF
%10 = icmp eq i8 %8, %9
br i1 %10, label %23, label %17
11: ; preds = %0, %11
%12 = phi i8 [ %14, %11 ], [ %4, %0 ]
%13 = tail call i32 @fputc(i8 signext %12, i32* %3)
%14 = tail call signext i8 @fgetc(i32* %1)
%15 = load i8, i8* @EOF
%16 = icmp eq i8 %14, %15
br i1 %16, label %7, label %11
17: ; preds = %7, %17
%18 = phi i8 [ %20, %17 ], [ %8, %7 ]
%19 = tail call i32 @fputc(i8 signext %18, i32* %3)
%20 = tail call signext i8 @fgetc(i32* %2)
%21 = load i8, i8* @EOF
%22 = icmp eq i8 %20, %21
br i1 %22, label %23, label %17
23: ; preds = %17, %7
%24 = tail call i32 @rewind(i32* %3)
%25 = tail call signext i8 @fgetc(i32* %3)
%26 = load i8, i8* @EOF
%27 = icmp eq i8 %25, %26
br i1 %27, label %45, label %28
28: ; preds = %23, %38
%29 = phi i8 [ %42, %38 ], [ %25, %23 ]
%30 = phi i32 [ %40, %38 ], [ 0, %23 ]
%31 = phi i32 [ %39, %38 ], [ 0, %23 ]
%32 = sext i8 %29 to i32
switch i8 %29, label %38 [
i8 10, label %33
i8 32, label %36
i8 9, label %36
]
33: ; preds = %28
%34 = add nsw i32 %30, 1
%35 = add nsw i32 %31, 1
br label %38
36: ; preds = %28, %28
%37 = add nsw i32 %31, 1
br label %38
38: ; preds = %28, %36, %33
%39 = phi i32 [ %35, %33 ], [ %37, %36 ], [ %31, %28 ]
%40 = phi i32 [ %34, %33 ], [ %30, %36 ], [ %30, %28 ]
%41 = tail call i32 @putchar(i32 %32)
%42 = tail call signext i8 @fgetc(i32* %3)
%43 = load i8, i8* @EOF
%44 = icmp eq i8 %42, %43
br i1 %44, label %45, label %28
45: ; preds = %38, %23
%46 = phi i32 [ 0, %23 ], [ %39, %38 ]
%47 = phi i32 [ 0, %23 ], [ %40, %38 ]
%48 = tail call i32 @fclose(i32* %1)
%49 = tail call i32 @fclose(i32* %2)
%50 = tail call i32 @fclose(i32* %3)
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i32 %47)
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %46)
%53 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%54 = tail call i32 @system(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
ret i32 0
}