#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(char *, int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
int getopt(int, char **, char *);
scalar_t__ in_source(int /*<<< orphan*/ *, char **, int *);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ perror(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  FILE *fin = NULL;
  char verbose_opt = 0;
  int opt;
  while ((opt = getopt(argc, argv, "+vhcs:")) != -1) {
    switch (opt) {
    case 's':
      fin = fopen(optarg, "r");
      if (!fin) {
        perror(optarg);
        exit(2);
      }
      break;
    case 'v':
      verbose_opt = 1;
      break;
    case 'h':
    default:
      usage();
    }
  }
  if (!fin) {
    fin = stdin;
    fprintf(stderr, "Reading from stdin, press ^D to quit.\n");
  }
  char *in_buf = NULL;
  int in_buflen = 0;
  if (in_source(fin, &in_buf, &in_buflen) != 0 || !in_buf || in_buflen <= 0) {
    return 1;
  }
  while (optind < argc) {
    if (verbose_opt)
      fprintf(stderr, "Writing to file: %s\n", argv[optind]);
    append(in_buf, in_buflen, argv[optind], strlen(argv[optind]));
    optind++;
  }
  free(in_buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe30(%rip),%rdx
call   10b0 <getopt@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
je     1272 <main+0xd2>
mov    -0x20(%rbp),%eax
mov    %eax,-0x30(%rbp)
sub    $0x68,%eax
je     1261 <main+0xc1>
jmp    11f5 <main+0x55>
mov    -0x30(%rbp),%eax
sub    $0x73,%eax
je     1217 <main+0x77>
jmp    1206 <main+0x66>
mov    -0x30(%rbp),%eax
sub    $0x76,%eax
je     1258 <main+0xb8>
jmp    1266 <main+0xc6>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xde0(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1253 <main+0xb3>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
call   10a0 <perror@plt>
mov    $0x2,%edi
call   10c0 <exit@plt>
jmp    126d <main+0xcd>
movb   $0x1,-0x19(%rbp)
jmp    126d <main+0xcd>
jmp    1266 <main+0xc6>
mov    $0x0,%al
call   1080 <usage@plt>
jmp    11c2 <main+0x22>
cmpq   $0x0,-0x18(%rbp)
jne    12a2 <main+0x102>
mov    0x2d5c(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
lea    0xd6e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1060 <in_source@plt>
cmp    $0x0,%rax
jne    12e1 <main+0x141>
cmpq   $0x0,-0x28(%rbp)
je     12e1 <main+0x141>
cmpl   $0x0,-0x2c(%rbp)
jg     12ed <main+0x14d>
movl   $0x1,-0x4(%rbp)
jmp    13ae <main+0x20e>
jmp    12f2 <main+0x152>
mov    0x2cdf(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    139e <main+0x1fe>
cmpb   $0x0,-0x19(%rbp)
je     1337 <main+0x197>
mov    0x2cb3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x2cb6(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd00(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2c88(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2c72(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x38(%rbp),%rdx
mov    %eax,%ecx
call   1040 <append@plt>
mov    0x2c4d(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    0x2c41(%rip),%rax
mov    %ecx,(%rax)
jmp    12f2 <main+0x152>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%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,%r12
mov    %edi,%r13d
lea    0xe45(%rip),%r15
mov    0x2e36(%rip),%rbp
lea    0xe3e(%rip),%rbx
xor    %r14d,%r14d
xor    %eax,%eax
mov    %rax,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r13d,%edi
mov    %r12,%rsi
mov    %r15,%rdx
call   10b0 <getopt@plt>
cmp    $0xffffffff,%eax
je     1224 <main+0x84>
cmp    $0x76,%eax
je     1220 <main+0x80>
cmp    $0x73,%eax
je     1206 <main+0x66>
xor    %eax,%eax
call   1080 <usage@plt>
jmp    11e0 <main+0x40>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
call   1090 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11e0 <main+0x40>
jmp    132a <main+0x18a>
xchg   %ax,%ax
mov    $0x1,%al
jmp    11ce <main+0x2e>
test   %r14,%r14
jne    124a <main+0xaa>
mov    0x2db0(%rip),%rax
mov    (%rax),%r14
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
lea    0xdc6(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
movq   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
call   1060 <in_source@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    131b <main+0x17b>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     131b <main+0x17b>
cmpl   $0x0,0x4(%rsp)
jle    131b <main+0x17b>
mov    0x2d3a(%rip),%r14
mov    (%r14),%eax
cmp    %r13d,%eax
jl     12e6 <main+0x146>
jmp    1314 <main+0x174>
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rbp
mov    0x4(%rsp),%r15d
cltq
mov    (%r12,%rax,8),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbp,%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1040 <append@plt>
mov    (%r14),%eax
add    $0x1,%eax
mov    %eax,(%r14)
cmp    %r13d,%eax
jge    130f <main+0x16f>
cmpb   $0x0,0x10(%rsp)
je     12b0 <main+0x110>
mov    0x2cd4(%rip),%rcx
mov    (%rcx),%edi
cltq
mov    (%r12,%rax,8),%rdx
lea    0xd2d(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%r14),%eax
jmp    12b0 <main+0x110>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x0(%rbp),%edi
call   10a0 <perror@plt>
mov    $0x2,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"+vhcs:\00"
@optarg = global i32 0
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32* null
@stderr = global i32 0
@.str.2 = [39 x i8] c"Reading from stdin, press ^D to quit.\0A\00"
@optind = global i32 0
@.str.3 = [21 x i8] c"Writing to file: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i8 0, i8* %7
br label %11
11: ; preds = %32, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %8
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %33
16: ; preds = %11
%17 = load i32, i32* %8
switch i32 %17, label %30 [
i32 115, label %18
i32 118, label %28
i32 104, label %29
]
18: ; preds = %16
%19 = load i32, i32* @optarg
%20 = call i32* @fopen(i32 %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %6
%21 = load i32*, i32** %6
%22 = icmp ne i32* %21, null
br i1 %22, label %27, label %23
23: ; preds = %18
%24 = load i32, i32* @optarg
%25 = call i32 @perror(i32 %24)
%26 = call i32 @exit(i32 2)
unreachable
27: ; preds = %18
br label %32
28: ; preds = %16
store i8 1, i8* %7
br label %32
29: ; preds = %16
br label %30
30: ; preds = %16, %29
%31 = call i32 (...) @usage()
br label %32
32: ; preds = %30, %28, %27
br label %11
33: ; preds = %11
%34 = load i32*, i32** %6
%35 = icmp ne i32* %34, null
br i1 %35, label %40, label %36
36: ; preds = %33
%37 = load i32*, i32** @stdin
store i32* %37, i32** %6
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %36, %33
store i8* null, i8** %9
store i32 0, i32* %10
%41 = load i32*, i32** %6
%42 = call i64 @in_source(i32* %41, i8** %9, i32* %10)
%43 = icmp ne i64 %42, 0
br i1 %43, label %50, label %44
44: ; preds = %40
%45 = load i8*, i8** %9
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i32, i32* %10
%49 = icmp sle i32 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %47, %44, %40
store i32 1, i32* %3
br label %87
51: ; preds = %47
br label %52
52: ; preds = %67, %51
%53 = load i32, i32* @optind
%54 = load i32, i32* %4
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %84
56: ; preds = %52
%57 = load i8, i8* %7
%58 = icmp ne i8 %57, 0
br i1 %58, label %59, label %67
59: ; preds = %56
%60 = load i32, i32* @stderr
%61 = load i8**, i8*** %5
%62 = load i32, i32* @optind
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8*, i8** %61, i64 %63
%65 = load i8*, i8** %64
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %65)
br label %67
67: ; preds = %59, %56
%68 = load i8*, i8** %9
%69 = load i32, i32* %10
%70 = load i8**, i8*** %5
%71 = load i32, i32* @optind
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8*, i8** %70, i64 %72
%74 = load i8*, i8** %73
%75 = load i8**, i8*** %5
%76 = load i32, i32* @optind
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8*, i8** %75, i64 %77
%79 = load i8*, i8** %78
%80 = call i32 @strlen(i8* %79)
%81 = call i32 @append(i8* %68, i32 %69, i8* %74, i32 %80)
%82 = load i32, i32* @optind
%83 = add nsw i32 %82, 1
store i32 %83, i32* @optind
br label %52
84: ; preds = %52
%85 = load i8*, i8** %9
%86 = call i32 @free(i8* %85)
store i32 0, i32* %3
br label %87
87: ; preds = %84, %50
%88 = load i32, i32* %3
ret i32 %88
}

LLVM IR (-O2):
@.str = [7 x i8] c"+vhcs:\00"
@optarg = global i32 0
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32* null
@stderr = global i32 0
@.str.2 = [39 x i8] c"Reading from stdin, press ^D to quit.\0A\00"
@optind = global i32 0
@.str.3 = [21 x i8] c"Writing to file: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i32
br label %5
5: ; preds = %12, %2
%6 = phi i32* [ %14, %12 ], [ null, %2 ]
%7 = phi i8 [ %9, %12 ], [ 0, %2 ]
br label %8
8: ; preds = %10, %5
%9 = phi i8 [ %7, %5 ], [ 1, %10 ]
br label %10
10: ; preds = %8, %20
%11 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
switch i32 %11, label %20 [
i32 -1, label %22
i32 115, label %12
i32 118, label %8
]
12: ; preds = %10
%13 = load i32, i32* @optarg
%14 = tail call i32* @fopen(i32 %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %5
16: ; preds = %12
%17 = load i32, i32* @optarg
%18 = tail call i32 @perror(i32 %17)
%19 = tail call i32 @exit(i32 2)
unreachable
20: ; preds = %10
%21 = tail call i32 (...) @usage()
br label %10
22: ; preds = %10
%23 = icmp eq i32* %6, null
br i1 %23, label %24, label %28
24: ; preds = %22
%25 = load i32*, i32** @stdin
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %24, %22
%29 = phi i32* [ %6, %22 ], [ %25, %24 ]
%30 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%31 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%32 = call i64 @in_source(i32* %29, i8** %3, i32* %4)
%33 = icmp ne i64 %32, 0
%34 = load i8*, i8** %3
%35 = icmp eq i8* %34, null
%36 = select i1 %33, i1 true, i1 %35
%37 = load i32, i32* %4
%38 = icmp slt i32 %37, 1
%39 = select i1 %36, i1 true, i1 %38
br i1 %39, label %71, label %40
40: ; preds = %28
%41 = load i32, i32* @optind
%42 = icmp slt i32 %41, %0
br i1 %42, label %43, label %68
43: ; preds = %40
%44 = icmp eq i8 %9, 0
br label %45
45: ; preds = %43, %54
%46 = phi i32 [ %41, %43 ], [ %64, %54 ]
br i1 %44, label %54, label %47
47: ; preds = %45
%48 = load i32, i32* @stderr
%49 = sext i32 %46 to i64
%50 = getelementptr inbounds i8*, i8** %1, i64 %49
%51 = load i8*, i8** %50
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %51)
%53 = load i32, i32* @optind
br label %54
54: ; preds = %47, %45
%55 = phi i32 [ %53, %47 ], [ %46, %45 ]
%56 = load i8*, i8** %3
%57 = load i32, i32* %4
%58 = sext i32 %55 to i64
%59 = getelementptr inbounds i8*, i8** %1, i64 %58
%60 = load i8*, i8** %59
%61 = call i32 @strlen(i8* %60)
%62 = call i32 @append(i8* %56, i32 %57, i8* %60, i32 %61)
%63 = load i32, i32* @optind
%64 = add nsw i32 %63, 1
store i32 %64, i32* @optind
%65 = icmp slt i32 %64, %0
br i1 %65, label %45, label %66
66: ; preds = %54
%67 = load i8*, i8** %3
br label %68
68: ; preds = %66, %40
%69 = phi i8* [ %67, %66 ], [ %34, %40 ]
%70 = call i32 @free(i8* %69)
br label %71
71: ; preds = %28, %68
%72 = phi i32 [ 0, %68 ], [ 1, %28 ]
ret i32 %72
}