#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 errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ is_dir(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ process_dir(int /*<<< orphan*/ *, char *, char *, char *);
int /*<<< orphan*/ process_file(int /*<<< orphan*/ *, char *, char *, char *);
char *strerror(int);
int main(int argc, char *argv[]) {
  char *start_tag;
  char *end_tag;
  char *output_file;
  char *path;
  FILE *output;
  if (argc != 5) {
    printf("ERROR: incorrect number of command-line arguments\n");
    exit(1);
  }
  start_tag = argv[1];
  end_tag = argv[2];
  output_file = argv[3];
  path = argv[4];
  output = fopen(output_file, "w+");
  if (!output) {
    printf("ERROR: fopen() failed errno: %d (%s)\n", errno, strerror(errno));
    exit(1);
  }
  if (is_dir(path)) {
    process_dir(output, path, start_tag, end_tag);
  } else {
    process_file(output, path, start_tag, end_tag);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     11a8 <main+0x38>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    122f <main+0xbf>
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x3c(%rbp),%esi
mov    %rax,%rdx
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x30(%rbp),%rdi
call   1050 <is_dir@plt>
cmp    $0x0,%rax
je     125c <main+0xec>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1060 <process_dir@plt>
jmp    1271 <main+0x101>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <process_file@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x5,%edi
jne    11e4 <main+0x64>
mov    0x8(%rsi),%r15
mov    0x10(%rsi),%r14
mov    0x18(%rsi),%rdi
mov    0x20(%rsi),%r12
lea    0xe5c(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11fa <main+0x7a>
mov    %rax,%rbx
mov    %r12,%rdi
call   1060 <is_dir@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
test   %rax,%rax
je     11d1 <main+0x51>
call   1070 <process_dir@plt>
jmp    11d6 <main+0x56>
call   1040 <process_file@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe3e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10a0 <strerror@plt>
lea    0xdf2(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [51 x i8] c"ERROR: incorrect number of command-line arguments\0A\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [38 x i8] c"ERROR: fopen() failed errno: %d (%s)\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 5
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %6
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
store i8* %22, i8** %7
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 3
%25 = load i8*, i8** %24
store i8* %25, i8** %8
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 4
%28 = load i8*, i8** %27
store i8* %28, i8** %9
%29 = load i8*, i8** %8
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %30, i32** %10
%31 = load i32*, i32** %10
%32 = icmp ne i32* %31, null
br i1 %32, label %39, label %33
33: ; preds = %16
%34 = load i32, i32* @errno
%35 = load i32, i32* @errno
%36 = call i8* @strerror(i32 %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %34, i8* %36)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %16
%40 = load i8*, i8** %9
%41 = call i64 @is_dir(i8* %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %39
%44 = load i32*, i32** %10
%45 = load i8*, i8** %9
%46 = load i8*, i8** %6
%47 = load i8*, i8** %7
%48 = call i32 @process_dir(i32* %44, i8* %45, i8* %46, i8* %47)
br label %55
49: ; preds = %39
%50 = load i32*, i32** %10
%51 = load i8*, i8** %9
%52 = load i8*, i8** %6
%53 = load i8*, i8** %7
%54 = call i32 @process_file(i32* %50, i8* %51, i8* %52, i8* %53)
br label %55
55: ; preds = %49, %43
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [38 x i8] c"ERROR: fopen() failed errno: %d (%s)\0A\00"
@errno = global i32 0
@str = [50 x i8] c"ERROR: incorrect number of command-line arguments\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 5
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8*, i8** %1, i64 3
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8*, i8** %1, i64 4
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %23
18: ; preds = %7
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %19, i8* %20)
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %7
%24 = tail call i64 @is_dir(i8* %15)
%25 = icmp eq i64 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %23
%27 = tail call i32 @process_dir(i32* %16, i8* %15, i8* %9, i8* %11)
br label %30
28: ; preds = %23
%29 = tail call i32 @process_file(i32* %16, i8* %15, i8* %9, i8* %11)
br label %30
30: ; preds = %28, %26
ret i32 0
}