#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 EOF;
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
char *realloc(char *, int);
char *read_instructions(FILE *in) {
  int i = 0, len = 64;
  char *ret = malloc(sizeof(char) * len);
  if (ret == NULL) {
    return NULL;
  }
  ret[0] = 0;
  int c;
  while ((c = fgetc(in)) != EOF) {
    switch (c) {
    case '^':
    case 'v':
    case '<':
    case '>':
      ret[i++] = c;
    }
    if (i == len) {
      len *= 2;
      char *tmp = realloc(ret, sizeof(char) * len);
      if (tmp == NULL) {
        free(ret);
        return NULL;
      }
      ret = tmp;
    }
  }
  ret[i] = 0;
  return ret;
}


x86 assembly (clang, -O0):
<read_instructions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x40,-0x18(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1185 <read_instructions+0x45>
movq   $0x0,-0x8(%rbp)
jmp    1276 <read_instructions+0x136>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e49(%rip),%rcx
cmp    (%rcx),%eax
je     1262 <read_instructions+0x122>
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x3c,%eax
je     11ee <read_instructions+0xae>
jmp    11bb <read_instructions+0x7b>
mov    -0x34(%rbp),%eax
sub    $0x3e,%eax
je     11ee <read_instructions+0xae>
jmp    11cc <read_instructions+0x8c>
mov    -0x34(%rbp),%eax
sub    $0x5e,%eax
je     11ee <read_instructions+0xae>
jmp    11dd <read_instructions+0x9d>
mov    -0x34(%rbp),%eax
sub    $0x76,%eax
jne    1208 <read_instructions+0xc8>
jmp    11ee <read_instructions+0xae>
mov    -0x24(%rbp),%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    125d <read_instructions+0x11d>
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%esi
call   1060 <realloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1255 <read_instructions+0x115>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1276 <read_instructions+0x136>
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    118c <read_instructions+0x4c>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_instructions>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x40,%edi
call   1050 <malloc@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     11fa <read_instructions+0xba>
mov    %rax,%rbp
movb   $0x0,(%rax)
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    0x2e6f(%rip),%r13
cmp    0x0(%r13),%eax
jne    118b <read_instructions+0x4b>
mov    %rbp,%rbx
movslq %r12d,%rax
movb   $0x0,(%rbx,%rax,1)
jmp    11fc <read_instructions+0xbc>
mov    $0x40,%r15d
xor    %r12d,%r12d
jmp    11b4 <read_instructions+0x74>
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rbx
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    %rbx,%rbp
cmp    0x0(%r13),%eax
je     1182 <read_instructions+0x42>
lea    -0x3c(%rax),%ecx
cmp    $0x3a,%ecx
ja     11d7 <read_instructions+0x97>
movabs $0x400000400000005,%rdx
bt     %rcx,%rdx
jae    11d7 <read_instructions+0x97>
movslq %r12d,%rcx
add    $0x1,%r12d
mov    %al,0x0(%rbp,%rcx,1)
cmp    %r15d,%r12d
jne    11a0 <read_instructions+0x60>
add    %r15d,%r15d
mov    %rbp,%rdi
mov    %r15d,%esi
call   1060 <realloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a3 <read_instructions+0x63>
mov    %rbp,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define i8* @read_instructions(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i32* %0, i32** %3
store i32 0, i32* %4
store i32 64, i32* %5
%9 = load i32, i32* %5
%10 = sext i32 %9 to i64
%11 = mul i64 1, %10
%12 = trunc i64 %11 to i32
%13 = call i8* @malloc(i32 %12)
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %1
store i8* null, i8** %2
br label %62
17: ; preds = %1
%18 = load i8*, i8** %6
%19 = getelementptr inbounds i8, i8* %18, i64 0
store i8 0, i8* %19
br label %20
20: ; preds = %55, %17
%21 = load i32*, i32** %3
%22 = call i32 @fgetc(i32* %21)
store i32 %22, i32* %7
%23 = load i32, i32* @EOF
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %56
25: ; preds = %20
%26 = load i32, i32* %7
switch i32 %26, label %35 [
i32 94, label %27
i32 118, label %27
i32 60, label %27
i32 62, label %27
]
27: ; preds = %25, %25, %25, %25
%28 = load i32, i32* %7
%29 = trunc i32 %28 to i8
%30 = load i8*, i8** %6
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
store i8 %29, i8* %34
br label %35
35: ; preds = %27, %25
%36 = load i32, i32* %4
%37 = load i32, i32* %5
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %55
39: ; preds = %35
%40 = load i32, i32* %5
%41 = mul nsw i32 %40, 2
store i32 %41, i32* %5
%42 = load i8*, i8** %6
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = mul i64 1, %44
%46 = trunc i64 %45 to i32
%47 = call i8* @realloc(i8* %42, i32 %46)
store i8* %47, i8** %8
%48 = load i8*, i8** %8
%49 = icmp eq i8* %48, null
br i1 %49, label %50, label %53
50: ; preds = %39
%51 = load i8*, i8** %6
%52 = call i32 @free(i8* %51)
store i8* null, i8** %2
br label %62
53: ; preds = %39
%54 = load i8*, i8** %8
store i8* %54, i8** %6
br label %55
55: ; preds = %53, %35
br label %20
56: ; preds = %20
%57 = load i8*, i8** %6
%58 = load i32, i32* %4
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
store i8 0, i8* %60
%61 = load i8*, i8** %6
store i8* %61, i8** %2
br label %62
62: ; preds = %56, %50, %16
%63 = load i8*, i8** %2
ret i8* %63
}

LLVM IR (-O2):
@EOF = global i32 0
define i8* @read_instructions(i32* nocapture %0) {
%2 = tail call dereferenceable_or_null(64) i8* @malloc(i32 64)
%3 = icmp eq i8* %2, null
br i1 %3, label %38, label %4
4: ; preds = %1
store i8 0, i8* %2
%5 = tail call i32 @fgetc(i32* %0)
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %33, label %8
8: ; preds = %4, %27
%9 = phi i32 [ %30, %27 ], [ %5, %4 ]
%10 = phi i32 [ %19, %27 ], [ 0, %4 ]
%11 = phi i8* [ %29, %27 ], [ %2, %4 ]
%12 = phi i32 [ %28, %27 ], [ 64, %4 ]
switch i32 %9, label %18 [
i32 94, label %13
i32 118, label %13
i32 60, label %13
i32 62, label %13
]
13: ; preds = %8, %8, %8, %8
%14 = trunc i32 %9 to i8
%15 = add nsw i32 %10, 1
%16 = sext i32 %10 to i64
%17 = getelementptr inbounds i8, i8* %11, i64 %16
store i8 %14, i8* %17
br label %18
18: ; preds = %13, %8
%19 = phi i32 [ %10, %8 ], [ %15, %13 ]
%20 = icmp eq i32 %19, %12
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = shl nsw i32 %12, 1
%23 = tail call i8* @realloc(i8* %11, i32 %22)
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = tail call i32 @free(i8* %11)
br label %38
27: ; preds = %21, %18
%28 = phi i32 [ %12, %18 ], [ %22, %21 ]
%29 = phi i8* [ %11, %18 ], [ %23, %21 ]
%30 = tail call i32 @fgetc(i32* %0)
%31 = load i32, i32* @EOF
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %8
33: ; preds = %27, %4
%34 = phi i8* [ %2, %4 ], [ %29, %27 ]
%35 = phi i32 [ 0, %4 ], [ %19, %27 ]
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 0, i8* %37
br label %38
38: ; preds = %25, %33, %1
%39 = phi i8* [ null, %1 ], [ %34, %33 ], [ null, %25 ]
ret i8* %39
}