#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 const *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(char const *, int /*<<< orphan*/, int,
                          int /*<<< orphan*/ *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcmp(char *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int);
int /*<<< orphan*/ strlen(char const *);
int process_file(FILE *output, const char *path, const char *start_tag,
                 const char *end_tag) {
  FILE *file;
  char *line_buf;
  size_t size;
  int ret;
  int do_copy = 0;
  const char *herring_start =
      "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n";
  const char *herring_end = "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n";
  file = fopen(path, "r");
  if (!file) {
    printf("ERROR: fopen() failed errno: %d (%s)\n", errno, strerror(errno));
    exit(1);
  }
  printf("Processing %s ..\n", path);
  fwrite(path, strlen(path), 1, output);
  fwrite("\n", strlen("\n"), 1, output);
  line_buf = (char *)malloc(1024);
  while ((ret = getline(&line_buf, &size, file)) != -1) {
    if (!(memcmp(line_buf, start_tag, strlen(start_tag)))) {
      fwrite(herring_start, strlen(herring_start), 1, output);
      do_copy = 1;
      continue;
    } else if ((do_copy == 1) &&
               !(memcmp(line_buf, end_tag, strlen(end_tag)))) {
      fwrite(herring_end, strlen(herring_end), 1, output);
      do_copy = 0;
    }
    if (do_copy) {
      fwrite(line_buf, strlen(line_buf), 1, output);
    }
  }
  free(line_buf);
  return 0;
}


x86 assembly (clang, -O0):
<process_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x40(%rbp)
lea    0xe37(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xe5b(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    122f <process_file+0x8f>
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x54(%rbp),%esi
mov    %rax,%rdx
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rsi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    %eax,%esi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
call   10b0 <fwrite@plt>
lea    0xe16(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%esi
mov    -0x8(%rbp),%rcx
lea    0xe04(%rip),%rdi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1090 <getline@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
je     13c8 <process_file+0x228>
mov    -0x30(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%eax
jne    1316 <process_file+0x176>
mov    -0x48(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x48(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x78(%rbp),%rdi
mov    %eax,%esi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
call   10b0 <fwrite@plt>
movl   $0x1,-0x40(%rbp)
jmp    1297 <process_file+0xf7>
cmpl   $0x1,-0x40(%rbp)
jne    1389 <process_file+0x1e9>
mov    -0x30(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x88(%rbp),%rdi
mov    -0x80(%rbp),%rsi
mov    %eax,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%eax
jne    1389 <process_file+0x1e9>
mov    -0x50(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x90(%rbp),%rdi
mov    %eax,%esi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
call   10b0 <fwrite@plt>
movl   $0x0,-0x40(%rbp)
jmp    138e <process_file+0x1ee>
cmpl   $0x0,-0x40(%rbp)
je     13c3 <process_file+0x223>
mov    -0x30(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x98(%rbp),%rdi
mov    %eax,%esi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
call   10b0 <fwrite@plt>
jmp    1297 <process_file+0xf7>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,0x8(%rsp)
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0xe9a(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1306 <process_file+0x166>
mov    %rax,%r12
lea    0xea7(%rip),%rdi
xor    %r13d,%r13d
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %rbp,%rdi
mov    %eax,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
lea    0xe77(%rip),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %rbp,%rdi
mov    %eax,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,(%rsp)
mov    %rsp,%rdi
lea    0x10(%rsp),%rsi
mov    %r12,%rdx
call   1090 <getline@plt>
jmp    127f <process_file+0xdf>
xor    %ebp,%ebp
lea    0xde0(%rip),%r14
mov    %r13,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
mov    %rsp,%rdi
lea    0x10(%rsp),%rsi
mov    %r12,%rdx
call   1090 <getline@plt>
mov    %ebp,%r13d
cmp    $0xffffffff,%eax
je     12ec <process_file+0x14c>
mov    (%rsp),%rbp
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1060 <memcmp@plt>
lea    0xd5c(%rip),%r14
mov    $0x1,%ebp
test   %eax,%eax
je     1252 <process_file+0xb2>
xor    %ebp,%ebp
cmp    $0x1,%r13d
jne    126c <process_file+0xcc>
mov    %rbx,%r13
mov    (%rsp),%rbp
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <memcmp@plt>
test   %eax,%eax
je     1246 <process_file+0xa6>
mov    (%rsp),%r14
mov    $0x1,%ebp
jmp    124f <process_file+0xaf>
mov    (%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    0x2cd3(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10c0 <strerror@plt>
lea    0xd42(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [47 x i8] c"\0A>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\0A\00"
@.str.1 = [46 x i8] c"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [38 x i8] c"ERROR: fopen() failed errno: %d (%s)\0A\00"
@errno = global i32 0
@.str.4 = [18 x i8] c"Processing %s ..\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @process_file(i32* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
store i32* %0, i32** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
store i32 0, i32* %13
store i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8** %14
store i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8** %15
%16 = load i8*, i8** %6
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %17, i32** %9
%18 = load i32*, i32** %9
%19 = icmp ne i32* %18, null
br i1 %19, label %26, label %20
20: ; preds = %4
%21 = load i32, i32* @errno
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %21, i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %4
%27 = load i8*, i8** %6
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %27)
%29 = load i8*, i8** %6
%30 = load i8*, i8** %6
%31 = call i32 @strlen(i8* %30)
%32 = load i32*, i32** %5
%33 = call i32 @fwrite(i8* %29, i32 %31, i32 1, i32* %32)
%34 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%35 = load i32*, i32** %5
%36 = call i32 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 %34, i32 1, i32* %35)
%37 = call i64 @malloc(i32 1024)
%38 = inttoptr i64 %37 to i8*
store i8* %38, i8** %10
br label %39
39: ; preds = %82, %50, %26
%40 = load i32*, i32** %9
%41 = call i32 @getline(i8** %10, i64* %11, i32* %40)
store i32 %41, i32* %12
%42 = icmp ne i32 %41, -1
br i1 %42, label %43, label %83
43: ; preds = %39
%44 = load i8*, i8** %10
%45 = load i8*, i8** %7
%46 = load i8*, i8** %7
%47 = call i32 @strlen(i8* %46)
%48 = call i32 @memcmp(i8* %44, i8* %45, i32 %47)
%49 = icmp ne i32 %48, 0
br i1 %49, label %56, label %50
50: ; preds = %43
%51 = load i8*, i8** %14
%52 = load i8*, i8** %14
%53 = call i32 @strlen(i8* %52)
%54 = load i32*, i32** %5
%55 = call i32 @fwrite(i8* %51, i32 %53, i32 1, i32* %54)
store i32 1, i32* %13
br label %39
56: ; preds = %43
%57 = load i32, i32* %13
%58 = icmp eq i32 %57, 1
br i1 %58, label %59, label %72
59: ; preds = %56
%60 = load i8*, i8** %10
%61 = load i8*, i8** %8
%62 = load i8*, i8** %8
%63 = call i32 @strlen(i8* %62)
%64 = call i32 @memcmp(i8* %60, i8* %61, i32 %63)
%65 = icmp ne i32 %64, 0
br i1 %65, label %72, label %66
66: ; preds = %59
%67 = load i8*, i8** %15
%68 = load i8*, i8** %15
%69 = call i32 @strlen(i8* %68)
%70 = load i32*, i32** %5
%71 = call i32 @fwrite(i8* %67, i32 %69, i32 1, i32* %70)
store i32 0, i32* %13
br label %72
72: ; preds = %66, %59, %56
br label %73
73: ; preds = %72
%74 = load i32, i32* %13
%75 = icmp ne i32 %74, 0
br i1 %75, label %76, label %82
76: ; preds = %73
%77 = load i8*, i8** %10
%78 = load i8*, i8** %10
%79 = call i32 @strlen(i8* %78)
%80 = load i32*, i32** %5
%81 = call i32 @fwrite(i8* %77, i32 %79, i32 1, i32* %80)
br label %82
82: ; preds = %76, %73
br label %39
83: ; preds = %39
%84 = load i8*, i8** %10
%85 = call i32 @free(i8* %84)
ret i32 0
}

LLVM IR (-O2):
@.str = [47 x i8] c"\0A>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\0A\00"
@.str.1 = [46 x i8] c"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [38 x i8] c"ERROR: fopen() failed errno: %d (%s)\0A\00"
@errno = global i32 0
@.str.4 = [18 x i8] c"Processing %s ..\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @process_file(i32* nocapture %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = bitcast i8** %5 to i8*
%8 = bitcast i64* %6 to i8*
%9 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %16
11: ; preds = %4
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %12, i8* %13)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %4
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %1)
%18 = tail call i32 @strlen(i8* %1)
%19 = tail call i32 @fwrite(i8* %1, i32 %18, i32 1, i32* %0)
%20 = tail call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%21 = tail call i32 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 %20, i32 1, i32* %0)
%22 = tail call i64 @malloc(i32 1024)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %5
%24 = call i32 @getline(i8** %5, i64* %6, i32* %9)
%25 = icmp eq i32 %24, -1
br i1 %25, label %50, label %26
26: ; preds = %16, %37
%27 = phi i32 [ %38, %37 ], [ 0, %16 ]
%28 = load i8*, i8** %5
%29 = call i32 @strlen(i8* %2)
%30 = call i32 @memcmp(i8* %28, i8* %2, i32 %29)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %41
32: ; preds = %26, %43, %48
%33 = phi i8* [ %49, %48 ], [ getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), %43 ], [ getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), %26 ]
%34 = phi i32 [ 1, %48 ], [ 0, %43 ], [ 1, %26 ]
%35 = call i32 @strlen(i8* %33)
%36 = call i32 @fwrite(i8* %33, i32 %35, i32 1, i32* %0)
br label %37
37: ; preds = %32, %41
%38 = phi i32 [ 0, %41 ], [ %34, %32 ]
%39 = call i32 @getline(i8** %5, i64* %6, i32* %9)
%40 = icmp eq i32 %39, -1
br i1 %40, label %50, label %26
41: ; preds = %26
%42 = icmp eq i32 %27, 1
br i1 %42, label %43, label %37
43: ; preds = %41
%44 = load i8*, i8** %5
%45 = call i32 @strlen(i8* %3)
%46 = call i32 @memcmp(i8* %44, i8* %3, i32 %45)
%47 = icmp eq i32 %46, 0
br i1 %47, label %32, label %48
48: ; preds = %43
%49 = load i8*, i8** %5
br label %32
50: ; preds = %37, %16
%51 = load i8*, i8** %5
%52 = call i32 @free(i8* %51)
ret i32 0
}