#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*/ append(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
scalar_t__ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int main(void) {
  FILE *fa, *fs;
  int files = 0;
  char file_app[81];
  char file_src[81];
  puts("Enter name of destination file: ");
  gets(file_app);
  if ((fa = fopen(file_app, "a")) == NULL) {
    fprintf(stderr, "Can't open %s\n", file_app);
    exit(2);
  }
  puts("Enter name of first source file (empty line to quit): ");
  while (gets(file_src) && file_src[0] != '\0') {
    if (strcmp(file_src, file_app) == 0)
      fputs("Can't append file to itself\n", stderr);
    else if ((fs = fopen(file_src, "r")) == NULL)
      fprintf(stderr, "Can't open %s\n", file_src);
    else {
      append(fs, fa);
      if (ferror(fs) != 0)
        fprintf(stderr, "Error in reading file %s.\n", file_src);
      if (ferror(fa) != 0)
        fprintf(stderr, "Error in writing file %s.\n", file_app);
      fclose(fs);
      files++;
      printf("File %s appended.\n", file_src);
      puts("Next file(empty line to quit): ");
    }
  }
  printf("Done. %d files appended.\n", files);
  fclose(fa);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xe30(%rip),%rdi
call   1040 <puts@plt>
lea    -0x70(%rbp),%rdi
call   10b0 <gets@plt>
lea    -0x70(%rbp),%rdi
lea    0xe38(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    121f <main+0x6f>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    -0x70(%rbp),%rdx
lea    0xe13(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>
lea    0xe0c(%rip),%rdi
call   1040 <puts@plt>
lea    -0xd0(%rbp),%rdi
call   10b0 <gets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0xd1(%rbp)
je     125f <main+0xaf>
movsbl -0xd0(%rbp),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0xd1(%rbp)
mov    -0xd1(%rbp),%al
test   $0x1,%al
jne    1272 <main+0xc2>
jmp    138d <main+0x1dd>
lea    -0xd0(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    12a6 <main+0xf6>
mov    0x2d4d(%rip),%rax
mov    (%rax),%esi
lea    0xdcd(%rip),%rdi
call   1080 <fputs@plt>
jmp    1388 <main+0x1d8>
lea    -0xd0(%rbp),%rdi
lea    0xdd2(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    12e8 <main+0x138>
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
lea    -0xd0(%rbp),%rdx
lea    0xd45(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    1383 <main+0x1d3>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <append@plt>
mov    -0x18(%rbp),%rdi
call   1050 <ferror@plt>
cmp    $0x0,%rax
je     1324 <main+0x174>
mov    0x2cd1(%rip),%rax
mov    (%rax),%edi
lea    -0xd0(%rbp),%rdx
lea    0xd69(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <ferror@plt>
cmp    $0x0,%rax
je     1350 <main+0x1a0>
mov    0x2ca2(%rip),%rax
mov    (%rax),%edi
lea    -0x70(%rbp),%rdx
lea    0xd58(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
lea    -0xd0(%rbp),%rsi
lea    0xd4e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xd53(%rip),%rdi
call   1040 <puts@plt>
jmp    1388 <main+0x1d8>
jmp    122b <main+0x7b>
mov    -0x1c(%rbp),%esi
lea    0xd5a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
lea    0xe38(%rip),%rdi
call   1040 <puts@plt>
lea    0x60(%rsp),%rbx
mov    %rbx,%rdi
call   10b0 <gets@plt>
lea    0xe40(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1356 <main+0x1a6>
mov    %rax,%r14
lea    0xe36(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rdi
call   10b0 <gets@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     132a <main+0x17a>
cmpb   $0x0,(%rsp)
je     132a <main+0x17a>
mov    %rsp,%rbx
lea    0x60(%rsp),%r15
mov    0x2db3(%rip),%r13
xor    %ebp,%ebp
nop
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     12e0 <main+0x130>
mov    %rbx,%rdi
lea    0xe38(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1300 <main+0x150>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <append@plt>
mov    %r12,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
je     128a <main+0xda>
mov    0x0(%r13),%edi
lea    0xe06(%rip),%rsi
mov    %rbx,%rdx
call   10a0 <fprintf@plt>
mov    %r14,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
je     12aa <main+0xfa>
mov    0x0(%r13),%edi
lea    0xe01(%rip),%rsi
mov    %r15,%rdx
call   10a0 <fprintf@plt>
mov    %r12,%rdi
call   1060 <fclose@plt>
add    $0x1,%ebp
lea    0xe02(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe04(%rip),%rdi
call   1040 <puts@plt>
jmp    1313 <main+0x163>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x0(%r13),%esi
lea    0xd7e(%rip),%rdi
call   1080 <fputs@plt>
jmp    1313 <main+0x163>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%r13),%edi
lea    0xd18(%rip),%rsi
mov    %rbx,%rdx
call   10a0 <fprintf@plt>
mov    %rbx,%rdi
call   10b0 <gets@plt>
test   %rax,%rax
je     132a <main+0x17a>
cmpb   $0x0,(%rsp)
jne    1230 <main+0x80>
lea    0xdc0(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c83(%rip),%rax
mov    (%rax),%edi
lea    0xcbd(%rip),%rsi
lea    0x60(%rsp),%rdx
call   10a0 <fprintf@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [33 x i8] c"Enter name of destination file: \00"
@.str.1 = [2 x i8] c"a\00"
@stderr = global i32 0
@.str.2 = [15 x i8] c"Can't open %s\0A\00"
@.str.3 = [55 x i8] c"Enter name of first source file (empty line to quit): \00"
@.str.4 = [29 x i8] c"Can't append file to itself\0A\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [27 x i8] c"Error in reading file %s.\0A\00"
@.str.7 = [27 x i8] c"Error in writing file %s.\0A\00"
@.str.8 = [19 x i8] c"File %s appended.\0A\00"
@.str.9 = [32 x i8] c"Next file(empty line to quit): \00"
@.str.10 = [26 x i8] c"Done. %d files appended.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [81 x i8]
%6 = alloca [81 x i8]
store i32 0, i32* %1
store i32 0, i32* %4
%7 = call i32 @puts(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [81 x i8], [81 x i8]* %5, i64 0, i64 0
%9 = call i64 @gets(i8* %8)
%10 = getelementptr inbounds [81 x i8], [81 x i8]* %5, i64 0, i64 0
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %2
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %18
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = getelementptr inbounds [81 x i8], [81 x i8]* %5, i64 0, i64 0
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 2)
unreachable
18: ; preds = %0
%19 = call i32 @puts(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %75, %18
%21 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 0
%22 = call i64 @gets(i8* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %20
%25 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br label %29
29: ; preds = %24, %20
%30 = phi i1 [ false, %20 ], [ %28, %24 ]
br i1 %30, label %31, label %76
31: ; preds = %29
%32 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 0
%33 = getelementptr inbounds [81 x i8], [81 x i8]* %5, i64 0, i64 0
%34 = call i64 @strcmp(i8* %32, i8* %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = load i32, i32* @stderr
%38 = call i32 @fputs(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %37)
br label %75
39: ; preds = %31
%40 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 0
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %41, i32** %3
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %47
43: ; preds = %39
%44 = load i32, i32* @stderr
%45 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 0
%46 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %45)
br label %74
47: ; preds = %39
%48 = load i32*, i32** %3
%49 = load i32*, i32** %2
%50 = call i32 @append(i32* %48, i32* %49)
%51 = load i32*, i32** %3
%52 = call i64 @ferror(i32* %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %47
%55 = load i32, i32* @stderr
%56 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 0
%57 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i8* %56)
br label %58
58: ; preds = %54, %47
%59 = load i32*, i32** %2
%60 = call i64 @ferror(i32* %59)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %66
62: ; preds = %58
%63 = load i32, i32* @stderr
%64 = getelementptr inbounds [81 x i8], [81 x i8]* %5, i64 0, i64 0
%65 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* %64)
br label %66
66: ; preds = %62, %58
%67 = load i32*, i32** %3
%68 = call i32 @fclose(i32* %67)
%69 = load i32, i32* %4
%70 = add nsw i32 %69, 1
store i32 %70, i32* %4
%71 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 0
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %71)
%73 = call i32 @puts(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0))
br label %74
74: ; preds = %66, %43
br label %75
75: ; preds = %74, %36
br label %20
76: ; preds = %29
%77 = load i32, i32* %4
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0), i32 %77)
%79 = load i32*, i32** %2
%80 = call i32 @fclose(i32* %79)
ret i32 0
}

LLVM IR (-O2):
@.str = [33 x i8] c"Enter name of destination file: \00"
@.str.1 = [2 x i8] c"a\00"
@stderr = global i32 0
@.str.2 = [15 x i8] c"Can't open %s\0A\00"
@.str.3 = [55 x i8] c"Enter name of first source file (empty line to quit): \00"
@.str.4 = [29 x i8] c"Can't append file to itself\0A\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [27 x i8] c"Error in reading file %s.\0A\00"
@.str.7 = [27 x i8] c"Error in writing file %s.\0A\00"
@.str.8 = [19 x i8] c"File %s appended.\0A\00"
@.str.9 = [32 x i8] c"Next file(empty line to quit): \00"
@.str.10 = [26 x i8] c"Done. %d files appended.\0A\00"
define i32 @main() {
%1 = alloca [81 x i8]
%2 = alloca [81 x i8]
%3 = getelementptr inbounds [81 x i8], [81 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [81 x i8], [81 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%6 = call i64 @gets(i8* %3)
%7 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%12 = call i32 @exit(i32 2)
unreachable
13: ; preds = %0
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0))
%15 = call i64 @gets(i8* %4)
%16 = icmp ne i64 %15, 0
%17 = load i8, i8* %4
%18 = icmp ne i8 %17, 0
%19 = select i1 %16, i1 %18, i1 false
br i1 %19, label %20, label %58
20: ; preds = %13, %51
%21 = phi i32 [ %52, %51 ], [ 0, %13 ]
%22 = call i64 @strcmp(i8* %4, i8* %3)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = call i32 @fputs(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %25)
br label %51
27: ; preds = %20
%28 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %51
33: ; preds = %27
%34 = call i32 @append(i32* %28, i32* %7)
%35 = call i64 @ferror(i32* %28)
%36 = icmp eq i64 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %33
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i8* %4)
br label %40
40: ; preds = %37, %33
%41 = call i64 @ferror(i32* %7)
%42 = icmp eq i64 %41, 0
br i1 %42, label %46, label %43
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* %3)
br label %46
46: ; preds = %43, %40
%47 = call i32 @fclose(i32* %28)
%48 = add nsw i32 %21, 1
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %4)
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0))
br label %51
51: ; preds = %30, %46, %24
%52 = phi i32 [ %21, %24 ], [ %21, %30 ], [ %48, %46 ]
%53 = call i64 @gets(i8* %4)
%54 = icmp ne i64 %53, 0
%55 = load i8, i8* %4
%56 = icmp ne i8 %55, 0
%57 = select i1 %54, i1 %56, i1 false
br i1 %57, label %20, label %58
58: ; preds = %51, %13
%59 = phi i32 [ 0, %13 ], [ %52, %51 ]
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0), i32 %59)
%61 = call i32 @fclose(i32* %7)
ret i32 0
}