#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int concatf(void) {
  FILE *fp1, *fp2, *ft;
  char ch, file1[256], file2[256], file3[256];
  printf("Usage: Enter the filenames of the two files to be concat'd\n"
         "then enter the path of the file which will store the content of"
         "both files\n");
  gets(file1);
  gets(file2);
  gets(file3);
  fp1 = fopen(file1, "r");
  fp2 = fopen(file2, "r");
  if (fp1 == NULL || fp2 == NULL) {
    perror("Error:");
    printf("Press any key to exit\n");
    exit(EXIT_FAILURE);
  }
  ft = fopen(file3, "w");
  if (ft == NULL) {
    perror("Error");
    printf("Press any key to exit\n");
    exit(EXIT_FAILURE);
  }
  while ((ch = fgetc(fp1)) != EOF)
    fputc(ch, ft);
  while ((ch = fgetc(fp2)) != EOF)
    fputc(ch, ft);
  printf("Merging successful\n");
  fclose(fp1);
  fclose(fp2);
  fclose(ft);
}


x86 assembly (clang, -O0):
<concatf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x330,%rsp
lea    0xe6e(%rip),%rdi
call   1040 <printf@plt>
lea    -0x130(%rbp),%rdi
call   1070 <gets@plt>
lea    -0x230(%rbp),%rdi
call   1070 <gets@plt>
lea    -0x330(%rbp),%rdi
call   1070 <gets@plt>
lea    -0x130(%rbp),%rdi
lea    0xee1(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x230(%rbp),%rdi
lea    0xeca(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11ff <concatf+0x7f>
cmpq   $0x0,-0x18(%rbp)
jne    1225 <concatf+0xa5>
lea    0xe80(%rip),%rdi
call   1090 <perror@plt>
lea    0xe7b(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    -0x330(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    126d <concatf+0xed>
lea    0xe58(%rip),%rdi
call   1090 <perror@plt>
lea    0xe33(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    1272 <concatf+0xf2>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
mov    0x2d60(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     12a7 <concatf+0x127>
mov    -0x21(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
jmp    1272 <concatf+0xf2>
jmp    12ac <concatf+0x12c>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
mov    0x2d26(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     12e1 <concatf+0x161>
mov    -0x21(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
jmp    12ac <concatf+0x12c>
lea    0xdc4(%rip),%rdi
call   1040 <printf@plt>
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    -0x4(%rbp),%eax
add    $0x330,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<concatf>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x308,%rsp
lea    0xe7a(%rip),%rdi
call   1030 <puts@plt>
lea    0x200(%rsp),%r14
mov    %r14,%rdi
call   1070 <gets@plt>
lea    0x100(%rsp),%r15
mov    %r15,%rdi
call   1070 <gets@plt>
mov    %rsp,%rdi
call   1070 <gets@plt>
lea    0xe44(%rip),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <fopen@plt>
test   %r14,%r14
je     129c <concatf+0x11c>
mov    %rax,%r15
test   %rax,%rax
je     129c <concatf+0x11c>
lea    0xe09(%rip),%rsi
mov    %rsp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     12a5 <concatf+0x125>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    0x2dc7(%rip),%r12
cmp    (%r12),%al
je     125b <concatf+0xdb>
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %r14,%rdi
call   1050 <fgetc@plt>
cmp    (%r12),%al
jne    1230 <concatf+0xb0>
jmp    125b <concatf+0xdb>
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %r15,%rdi
call   1050 <fgetc@plt>
cmp    (%r12),%al
jne    1250 <concatf+0xd0>
lea    0xe24(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x308,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd5d(%rip),%rdi
jmp    12ac <concatf+0x12c>
lea    0xd5d(%rip),%rdi
call   1090 <perror@plt>
lea    0xdef(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [134 x i8] c"Usage: Enter the filenames of the two files to be concat'd\0Athen enter the path of the file which will store the content ofboth files\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"Error:\00"
@.str.3 = [23 x i8] c"Press any key to exit\0A\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [6 x i8] c"Error\00"
@EOF = global i8 0
@.str.6 = [20 x i8] c"Merging successful\0A\00"
define i32 @concatf() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i8
%6 = alloca [256 x i8]
%7 = alloca [256 x i8]
%8 = alloca [256 x i8]
%9 = call i32 @printf(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%11 = call i32 @gets(i8* %10)
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%13 = call i32 @gets(i8* %12)
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%15 = call i32 @gets(i8* %14)
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %2
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %3
%20 = load i32*, i32** %2
%21 = icmp eq i32* %20, null
br i1 %21, label %25, label %22
22: ; preds = %0
%23 = load i32*, i32** %3
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %30
25: ; preds = %22, %0
%26 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %22
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %32, i32** %4
%33 = load i32*, i32** %4
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %40
35: ; preds = %30
%36 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%37 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %30
br label %41
41: ; preds = %48, %40
%42 = load i32*, i32** %2
%43 = call signext i8 @fgetc(i32* %42)
store i8 %43, i8* %5
%44 = sext i8 %43 to i32
%45 = load i8, i8* @EOF
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %44, %46
br i1 %47, label %48, label %52
48: ; preds = %41
%49 = load i8, i8* %5
%50 = load i32*, i32** %4
%51 = call i32 @fputc(i8 signext %49, i32* %50)
br label %41
52: ; preds = %41
br label %53
53: ; preds = %60, %52
%54 = load i32*, i32** %3
%55 = call signext i8 @fgetc(i32* %54)
store i8 %55, i8* %5
%56 = sext i8 %55 to i32
%57 = load i8, i8* @EOF
%58 = sext i8 %57 to i32
%59 = icmp ne i32 %56, %58
br i1 %59, label %60, label %64
60: ; preds = %53
%61 = load i8, i8* %5
%62 = load i32*, i32** %4
%63 = call i32 @fputc(i8 signext %61, i32* %62)
br label %53
64: ; preds = %53
%65 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%66 = load i32*, i32** %2
%67 = call i32 @fclose(i32* %66)
%68 = load i32*, i32** %3
%69 = call i32 @fclose(i32* %68)
%70 = load i32*, i32** %4
%71 = call i32 @fclose(i32* %70)
%72 = load i32, i32* %1
ret i32 %72
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"Error:\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [6 x i8] c"Error\00"
@EOF = global i8 0
@str = [133 x i8] c"Usage: Enter the filenames of the two files to be concat'd\0Athen enter the path of the file which will store the content ofboth files\00"
@str.7 = [19 x i8] c"Merging successful\00"
@str.9 = [22 x i8] c"Press any key to exit\00"
define i32 @concatf() {
%1 = alloca [256 x i8]
%2 = alloca [256 x i8]
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([133 x i8], [133 x i8]* @str, i64 0, i64 0))
%8 = call i32 @gets(i8* %4)
%9 = call i32 @gets(i8* %5)
%10 = call i32 @gets(i8* %6)
%11 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %11, null
%14 = icmp eq i32* %12, null
%15 = or i1 %13, %14
br i1 %15, label %16, label %21
16: ; preds = %0
%17 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.9, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %0
%22 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = call signext i8 @fgetc(i32* %11)
%26 = load i8, i8* @EOF
%27 = icmp eq i8 %25, %26
br i1 %27, label %33, label %37
28: ; preds = %21
%29 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.9, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %37, %24
%34 = call signext i8 @fgetc(i32* %12)
%35 = load i8, i8* @EOF
%36 = icmp eq i8 %34, %35
br i1 %36, label %49, label %43
37: ; preds = %24, %37
%38 = phi i8 [ %40, %37 ], [ %25, %24 ]
%39 = call i32 @fputc(i8 signext %38, i32* %22)
%40 = call signext i8 @fgetc(i32* %11)
%41 = load i8, i8* @EOF
%42 = icmp eq i8 %40, %41
br i1 %42, label %33, label %37
43: ; preds = %33, %43
%44 = phi i8 [ %46, %43 ], [ %34, %33 ]
%45 = call i32 @fputc(i8 signext %44, i32* %22)
%46 = call signext i8 @fgetc(i32* %12)
%47 = load i8, i8* @EOF
%48 = icmp eq i8 %46, %47
br i1 %48, label %49, label %43
49: ; preds = %43, %33
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.7, i64 0, i64 0))
%51 = call i32 @fclose(i32* %11)
%52 = call i32 @fclose(i32* %12)
%53 = call i32 @fclose(i32* %22)
ret i32 undef
}