#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ fgets_unlocked(char *, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
char *malloc(long);
char *realloc(char *, int);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *read_input(int *input_size, const char *input_path) {
  FILE *input = fopen(input_path, "r");
  fseek(input, 0L, SEEK_END);
  long file_size = ftell(input);
  fseek(input, 0L, SEEK_SET);
  char *result = malloc(file_size);
  do {
    fgets_unlocked(result, file_size, input);
  } while (strncmp(result, ">THREE", 6));
  int read = 0;
  while (fgets_unlocked(result + read, file_size - read, input)) {
    int len = strlen(result + read);
    if (len == 0 || result[read] == '>')
      break;
    read += len;
    if (result[read - 1] == '\n')
      read--;
  }
  result[read++] = '>';
  result = realloc(result, read);
  *input_size = read;
  return result;
}


x86 assembly (clang, -O0):
<read_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1050 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e06(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <fgets_unlocked@plt>
mov    -0x28(%rbp),%rdi
lea    0xdfc(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11ea <read_input+0x6a>
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
movslq -0x2c(%rbp),%rax
sub    %rax,%rsi
mov    -0x18(%rbp),%rdx
call   1060 <fgets_unlocked@plt>
cmp    $0x0,%rax
je     12b2 <read_input+0x132>
mov    -0x28(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     127c <read_input+0xfc>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3e,%eax
jne    1281 <read_input+0x101>
jmp    12b2 <read_input+0x132>
mov    -0x30(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    12ad <read_input+0x12d>
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    1221 <read_input+0xa1>
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x2c(%rbp)
movslq %ecx,%rcx
movb   $0x3e,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1090 <realloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_input>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %rdi,%r14
lea    0xe68(%rip),%rsi
mov    %rax,%rdi
call   10a0 <fopen@plt>
mov    %rax,%r15
mov    0x2e3e(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r15,%rdi
call   1050 <ftell@plt>
mov    %rax,%r12
mov    0x2e10(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r12,%rdi
call   1070 <malloc@plt>
mov    %rax,%r13
lea    0xe1c(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1060 <fgets_unlocked@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11f0 <read_input+0x70>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1060 <fgets_unlocked@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1271 <read_input+0xf1>
mov    %r13,%rbp
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     1271 <read_input+0xf1>
cmpb   $0x3e,0x0(%rbp)
je     1271 <read_input+0xf1>
add    %ebx,%eax
movslq %eax,%rbx
lea    -0x1(%rbx),%rax
cmpb   $0xa,-0x1(%r13,%rbx,1)
cmove  %eax,%ebx
movslq %ebx,%rax
lea    (%rax,%r13,1),%rbp
mov    %r12,%rsi
sub    %rax,%rsi
mov    %rbp,%rdi
mov    %r15,%rdx
call   1060 <fgets_unlocked@plt>
test   %rax,%rax
jne    1230 <read_input+0xb0>
movslq %ebx,%rax
add    $0x1,%ebx
movb   $0x3e,0x0(%r13,%rax,1)
mov    %r13,%rdi
mov    %ebx,%esi
call   1090 <realloc@plt>
mov    %ebx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [7 x i8] c">THREE\00"
define i8* @read_input(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %5
%12 = load i32*, i32** %5
%13 = load i32, i32* @SEEK_END
%14 = call i32 @fseek(i32* %12, i64 0, i32 %13)
%15 = load i32*, i32** %5
%16 = call i64 @ftell(i32* %15)
store i64 %16, i64* %6
%17 = load i32*, i32** %5
%18 = load i32, i32* @SEEK_SET
%19 = call i32 @fseek(i32* %17, i64 0, i32 %18)
%20 = load i64, i64* %6
%21 = call i8* @malloc(i64 %20)
store i8* %21, i8** %7
br label %22
22: ; preds = %27, %2
%23 = load i8*, i8** %7
%24 = load i64, i64* %6
%25 = load i32*, i32** %5
%26 = call i64 @fgets_unlocked(i8* %23, i64 %24, i32* %25)
br label %27
27: ; preds = %22
%28 = load i8*, i8** %7
%29 = call i64 @strncmp(i8* %28, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%30 = icmp ne i64 %29, 0
br i1 %30, label %22, label %31
31: ; preds = %27
store i32 0, i32* %8
br label %32
32: ; preds = %76, %31
%33 = load i8*, i8** %7
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i64, i64* %6
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = sub nsw i64 %37, %39
%41 = load i32*, i32** %5
%42 = call i64 @fgets_unlocked(i8* %36, i64 %40, i32* %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %77
44: ; preds = %32
%45 = load i8*, i8** %7
%46 = load i32, i32* %8
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = call i32 @strlen(i8* %48)
store i32 %49, i32* %9
%50 = load i32, i32* %9
%51 = icmp eq i32 %50, 0
br i1 %51, label %60, label %52
52: ; preds = %44
%53 = load i8*, i8** %7
%54 = load i32, i32* %8
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 62
br i1 %59, label %60, label %61
60: ; preds = %52, %44
br label %77
61: ; preds = %52
%62 = load i32, i32* %9
%63 = load i32, i32* %8
%64 = add nsw i32 %63, %62
store i32 %64, i32* %8
%65 = load i8*, i8** %7
%66 = load i32, i32* %8
%67 = sub nsw i32 %66, 1
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %65, i64 %68
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = icmp eq i32 %71, 10
br i1 %72, label %73, label %76
73: ; preds = %61
%74 = load i32, i32* %8
%75 = add nsw i32 %74, -1
store i32 %75, i32* %8
br label %76
76: ; preds = %73, %61
br label %32
77: ; preds = %60, %32
%78 = load i8*, i8** %7
%79 = load i32, i32* %8
%80 = add nsw i32 %79, 1
store i32 %80, i32* %8
%81 = sext i32 %79 to i64
%82 = getelementptr inbounds i8, i8* %78, i64 %81
store i8 62, i8* %82
%83 = load i8*, i8** %7
%84 = load i32, i32* %8
%85 = call i8* @realloc(i8* %83, i32 %84)
store i8* %85, i8** %7
%86 = load i32, i32* %8
%87 = load i32*, i32** %3
store i32 %86, i32* %87
%88 = load i8*, i8** %7
ret i8* %88
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [7 x i8] c">THREE\00"
define i8* @read_input(i32* nocapture writeonly %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @SEEK_END
%5 = tail call i32 @fseek(i32* %3, i64 0, i32 %4)
%6 = tail call i64 @ftell(i32* %3)
%7 = load i32, i32* @SEEK_SET
%8 = tail call i32 @fseek(i32* %3, i64 0, i32 %7)
%9 = tail call i8* @malloc(i64 %6)
br label %10
10: ; preds = %10, %2
%11 = tail call i64 @fgets_unlocked(i8* %9, i64 %6, i32* %3)
%12 = tail call i64 @strncmp(i8* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %10
14: ; preds = %10
%15 = tail call i64 @fgets_unlocked(i8* %9, i64 %6, i32* %3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %38, label %17
17: ; preds = %14, %25
%18 = phi i8* [ %34, %25 ], [ %9, %14 ]
%19 = phi i32 [ %32, %25 ], [ 0, %14 ]
%20 = tail call i32 @strlen(i8* %18)
%21 = icmp eq i32 %20, 0
br i1 %21, label %38, label %22
22: ; preds = %17
%23 = load i8, i8* %18
%24 = icmp eq i8 %23, 62
br i1 %24, label %38, label %25
25: ; preds = %22
%26 = add nsw i32 %20, %19
%27 = add nsw i32 %26, -1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %9, i64 %28
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 10
%32 = select i1 %31, i32 %27, i32 %26
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %9, i64 %33
%35 = sub nsw i64 %6, %33
%36 = tail call i64 @fgets_unlocked(i8* %34, i64 %35, i32* %3)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %17
38: ; preds = %25, %22, %17, %14
%39 = phi i32 [ 0, %14 ], [ %19, %17 ], [ %19, %22 ], [ %32, %25 ]
%40 = add nsw i32 %39, 1
%41 = sext i32 %39 to i64
%42 = getelementptr inbounds i8, i8* %9, i64 %41
store i8 62, i8* %42
%43 = tail call i8* @realloc(i8* %9, i32 %40)
store i32 %40, i32* %0
ret i8* %43
}