#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 */
struct option {
  char *member_0;
  char member_3;
  int /*<<< orphan*/ member_2;
  int /*<<< orphan*/ const member_1;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ abort();
char **copy_lines(int /*<<< orphan*/ *, int);
int count_ln(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintln(int /*<<< orphan*/ *, char **, int);
int /*<<< orphan*/ free_array(void **, int);
int /*<<< orphan*/ *freopen(char *, char *, int /*<<< orphan*/ *);
int getopt_long(int, char **, char *, struct option *, int *);
char *malloc(int);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ printf(char *, char *);
#define required_argument 128
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int c;
  int nlines = 0;
  int ilines = 0;
  char *s_snoc_dst;
  char *s_snoc_src;
  char *message;
  char **lines = NULL;
  char **newlines = NULL;
  FILE *snoc_src;
  FILE *snoc_dst;
  while (1) {
    static struct option long_otps[] = {
        {"source", required_argument, 0, 's'},
        {"destination", required_argument, 0, 'd'},
        {0, 0, 0, 0}};
    int option_index = 0;
    c = getopt_long(argc, argv, "s:d:", long_otps, &option_index);
    if (c == -1) {
      break;
    }
    switch (c) {
    case 's':
      s_snoc_src = malloc(sizeof optarg);
      strcpy(s_snoc_src, optarg);
      break;
    case 'd':
      s_snoc_dst = malloc(sizeof optarg);
      strcpy(s_snoc_dst, optarg);
      break;
    default:
      message = "Illegal Option Found\n";
      printf("%s", message);
      abort();
    }
  }
  snoc_src = fopen(s_snoc_src, "r");
  snoc_dst = fopen(s_snoc_dst, "r+");
  if (!snoc_src || !snoc_dst) {
    printf("%s\n", "One or more of the specified files were not found");
    return 1;
  }
  nlines = count_ln(snoc_dst);
  ilines = count_ln(snoc_src);
  lines = copy_lines(snoc_dst, nlines);
  newlines = copy_lines(snoc_src, ilines);
  snoc_dst = freopen(s_snoc_dst, "w", snoc_dst);
  fprintln(snoc_dst, newlines, ilines);
  fprintln(snoc_dst, lines, nlines);
  free_array((void **)lines, nlines);
  free_array((void **)newlines, ilines);
  fclose(snoc_src);
  fclose(snoc_dst);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x0,-0x5c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe0a(%rip),%rdx
lea    0x2e80(%rip),%rcx
lea    -0x5c(%rbp),%r8
call   1060 <getopt_long@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    122b <main+0x6b>
jmp    12c1 <main+0x101>
mov    -0x14(%rbp),%eax
mov    %eax,-0x60(%rbp)
sub    $0x64,%eax
je     1275 <main+0xb5>
jmp    123f <main+0x7f>
mov    -0x60(%rbp),%eax
sub    $0x73,%eax
jne    129a <main+0xda>
jmp    1250 <main+0x90>
mov    $0x4,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2d8f(%rip),%rax
mov    (%rax),%esi
call   1040 <strcpy@plt>
jmp    12bc <main+0xfc>
mov    $0x4,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2d6a(%rip),%rax
mov    (%rax),%esi
call   1040 <strcpy@plt>
jmp    12bc <main+0xfc>
lea    0xd77(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xd7e(%rip),%rdi
call   1070 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    11f4 <main+0x34>
mov    -0x30(%rbp),%rdi
lea    0xd65(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xd53(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x50(%rbp)
je     12ff <main+0x13f>
cmpq   $0x0,-0x58(%rbp)
jne    131e <main+0x15e>
lea    0xd30(%rip),%rdi
lea    0xd2d(%rip),%rsi
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13bf <main+0x1ff>
mov    -0x58(%rbp),%rdi
call   10c0 <count_ln@plt>
mov    %eax,-0x18(%rbp)
mov    -0x50(%rbp),%rdi
call   10c0 <count_ln@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   10b0 <copy_lines@plt>
mov    %rax,-0x40(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10b0 <copy_lines@plt>
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x58(%rbp),%rdx
lea    0xd07(%rip),%rsi
call   1080 <freopen@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   10e0 <fprintln@plt>
mov    -0x58(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   10e0 <fprintln@plt>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1090 <free_array@plt>
mov    -0x48(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1090 <free_array@plt>
mov    -0x50(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x58(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x2eb6(%rip),%r12
lea    0xc(%rsp),%r13
mov    0x2e12(%rip),%r14
jmp    120a <main+0x4a>
nopl   0x0(%rax,%rax,1)
mov    $0x4,%edi
call   10a0 <malloc@plt>
mov    %rax,%rdi
mov    %rax,0x10(%rsp)
mov    (%r14),%esi
call   1040 <strcpy@plt>
movl   $0x0,0xc(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
lea    0xdf5(%rip),%rdx
mov    %r12,%rcx
mov    %r13,%r8
call   1060 <getopt_long@plt>
cmp    $0x64,%eax
je     11f0 <main+0x30>
cmp    $0x73,%eax
jne    1245 <main+0x85>
mov    $0x4,%edi
call   10a0 <malloc@plt>
mov    %rax,%rdi
mov    %rax,%r15
jmp    1202 <main+0x42>
cmp    $0xffffffff,%eax
jne    1338 <main+0x178>
lea    0xddc(%rip),%rsi
mov    %r15,%rdi
call   10d0 <fopen@plt>
mov    %rax,%r14
lea    0xdcc(%rip),%rsi
mov    0x10(%rsp),%rdi
call   10d0 <fopen@plt>
test   %r14,%r14
je     1311 <main+0x151>
mov    %rax,%rbx
test   %rax,%rax
je     1311 <main+0x151>
mov    %rbx,%rdi
call   10c0 <count_ln@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   10c0 <count_ln@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r15d,%esi
call   10b0 <copy_lines@plt>
mov    %rax,%r12
mov    %r14,%rdi
mov    %ebp,%esi
call   10b0 <copy_lines@plt>
mov    %rax,%r13
lea    0xdaf(%rip),%rsi
mov    0x10(%rsp),%rdi
mov    %rbx,%rdx
call   1080 <freopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
call   10e0 <fprintln@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   10e0 <fprintln@plt>
mov    %r12,%rdi
mov    %r15d,%esi
call   1090 <free_array@plt>
mov    %r13,%rdi
mov    %ebp,%esi
call   1090 <free_array@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    1329 <main+0x169>
lea    0xd1e(%rip),%rdi
lea    0xd1b(%rip),%rsi
call   1070 <printf@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcef(%rip),%rdi
lea    0xcd2(%rip),%rsi
call   1070 <printf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.option = type { i8*, i8, i32, i32 }
@main.long_otps = internal global [3 x %struct.option] [%struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8 -128, i32 0, i32 115 }, %struct.option { i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i32 0, i32 0), i8 -128, i32 0, i32 100 }, %struct.option zeroinitializer]
@.str = [7 x i8] c"source\00"
@.str.1 = [12 x i8] c"destination\00"
@.str.2 = [5 x i8] c"s:d:\00"
@optarg = global i32 0
@.str.3 = [22 x i8] c"Illegal Option Found\0A\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [3 x i8] c"r+\00"
@.str.7 = [4 x i8] c"%s\0A\00"
@.str.8 = [50 x i8] c"One or more of the specified files were not found\00"
@.str.9 = [2 x i8] c"w\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
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8**
%13 = alloca i8**
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
store i8** null, i8*** %12
store i8** null, i8*** %13
br label %17
17: ; preds = %2, %40
store i32 0, i32* %16
%18 = load i32, i32* %4
%19 = load i8**, i8*** %5
%20 = call i32 @getopt_long(i32 %18, i8** %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %struct.option* getelementptr inbounds ([3 x %struct.option], [3 x %struct.option]* @main.long_otps, i64 0, i64 0), i32* %16)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %17
br label %41
24: ; preds = %17
%25 = load i32, i32* %6
switch i32 %25, label %36 [
i32 115, label %26
i32 100, label %31
]
26: ; preds = %24
%27 = call i8* @malloc(i32 4)
store i8* %27, i8** %10
%28 = load i8*, i8** %10
%29 = load i32, i32* @optarg
%30 = call i32 @strcpy(i8* %28, i32 %29)
br label %40
31: ; preds = %24
%32 = call i8* @malloc(i32 4)
store i8* %32, i8** %9
%33 = load i8*, i8** %9
%34 = load i32, i32* @optarg
%35 = call i32 @strcpy(i8* %33, i32 %34)
br label %40
36: ; preds = %24
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8** %11
%37 = load i8*, i8** %11
%38 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %37)
%39 = call i32 (...) @abort()
unreachable
40: ; preds = %31, %26
br label %17
41: ; preds = %23
%42 = load i8*, i8** %10
%43 = call i32* @fopen(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %43, i32** %14
%44 = load i8*, i8** %9
%45 = call i32* @fopen(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32* %45, i32** %15
%46 = load i32*, i32** %14
%47 = icmp ne i32* %46, null
br i1 %47, label %48, label %51
48: ; preds = %41
%49 = load i32*, i32** %15
%50 = icmp ne i32* %49, null
br i1 %50, label %53, label %51
51: ; preds = %48, %41
%52 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %3
br label %85
53: ; preds = %48
%54 = load i32*, i32** %15
%55 = call i32 @count_ln(i32* %54)
store i32 %55, i32* %7
%56 = load i32*, i32** %14
%57 = call i32 @count_ln(i32* %56)
store i32 %57, i32* %8
%58 = load i32*, i32** %15
%59 = load i32, i32* %7
%60 = call i8** @copy_lines(i32* %58, i32 %59)
store i8** %60, i8*** %12
%61 = load i32*, i32** %14
%62 = load i32, i32* %8
%63 = call i8** @copy_lines(i32* %61, i32 %62)
store i8** %63, i8*** %13
%64 = load i8*, i8** %9
%65 = load i32*, i32** %15
%66 = call i32* @freopen(i8* %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i32* %65)
store i32* %66, i32** %15
%67 = load i32*, i32** %15
%68 = load i8**, i8*** %13
%69 = load i32, i32* %8
%70 = call i32 @fprintln(i32* %67, i8** %68, i32 %69)
%71 = load i32*, i32** %15
%72 = load i8**, i8*** %12
%73 = load i32, i32* %7
%74 = call i32 @fprintln(i32* %71, i8** %72, i32 %73)
%75 = load i8**, i8*** %12
%76 = load i32, i32* %7
%77 = call i32 @free_array(i8** %75, i32 %76)
%78 = load i8**, i8*** %13
%79 = load i32, i32* %8
%80 = call i32 @free_array(i8** %78, i32 %79)
%81 = load i32*, i32** %14
%82 = call i32 @fclose(i32* %81)
%83 = load i32*, i32** %15
%84 = call i32 @fclose(i32* %83)
store i32 0, i32* %3
br label %85
85: ; preds = %53, %51
%86 = load i32, i32* %3
ret i32 %86
}

LLVM IR (-O2):
%struct.option = type { i8*, i8, i32, i32 }
@main.long_otps = internal global [3 x %struct.option] [%struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8 -128, i32 0, i32 115 }, %struct.option { i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i32 0, i32 0), i8 -128, i32 0, i32 100 }, %struct.option zeroinitializer]
@.str = [7 x i8] c"source\00"
@.str.1 = [12 x i8] c"destination\00"
@.str.2 = [5 x i8] c"s:d:\00"
@optarg = global i32 0
@.str.3 = [22 x i8] c"Illegal Option Found\0A\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [3 x i8] c"r+\00"
@.str.7 = [4 x i8] c"%s\0A\00"
@.str.8 = [50 x i8] c"One or more of the specified files were not found\00"
@.str.9 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
br label %5
5: ; preds = %16, %2
%6 = phi i8* [ undef, %2 ], [ %18, %16 ]
%7 = phi i8* [ undef, %2 ], [ %19, %16 ]
store i32 0, i32* %3
%8 = call i32 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %struct.option* getelementptr inbounds ([3 x %struct.option], [3 x %struct.option]* @main.long_otps, i64 0, i64 0), i32* %3)
switch i32 %8, label %13 [
i32 -1, label %22
i32 115, label %9
i32 100, label %11
]
9: ; preds = %5
%10 = call dereferenceable_or_null(4) i8* @malloc(i32 4)
br label %16
11: ; preds = %5
%12 = call dereferenceable_or_null(4) i8* @malloc(i32 4)
br label %16
13: ; preds = %5
%14 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 (...) @abort()
unreachable
16: ; preds = %9, %11
%17 = phi i8* [ %10, %9 ], [ %12, %11 ]
%18 = phi i8* [ %6, %9 ], [ %12, %11 ]
%19 = phi i8* [ %10, %9 ], [ %7, %11 ]
%20 = load i32, i32* @optarg
%21 = call i32 @strcpy(i8* %17, i32 %20)
br label %5
22: ; preds = %5
%23 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%24 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%25 = icmp ne i32* %23, null
%26 = icmp ne i32* %24, null
%27 = and i1 %25, %26
br i1 %27, label %30, label %28
28: ; preds = %22
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.8, i64 0, i64 0))
br label %42
30: ; preds = %22
%31 = call i32 @count_ln(i32* %24)
%32 = call i32 @count_ln(i32* %23)
%33 = call i8** @copy_lines(i32* %24, i32 %31)
%34 = call i8** @copy_lines(i32* %23, i32 %32)
%35 = call i32* @freopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i32* %24)
%36 = call i32 @fprintln(i32* %35, i8** %34, i32 %32)
%37 = call i32 @fprintln(i32* %35, i8** %33, i32 %31)
%38 = call i32 @free_array(i8** %33, i32 %31)
%39 = call i32 @free_array(i8** %34, i32 %32)
%40 = call i32 @fclose(i32* %23)
%41 = call i32 @fclose(i32* %35)
br label %42
42: ; preds = %30, %28
%43 = phi i32 [ 0, %30 ], [ 1, %28 ]
ret i32 %43
}