#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*/ bfsize(char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int getSize(int /*<<< orphan*/ *);
scalar_t__ isValid(char);
char *malloc(int /*<<< orphan*/);
char ook2bfchar(char, char);
char *ook2bf(char *in_filename) {
  FILE *in_file;
  int filesize;
  int i;
  in_file = fopen(in_filename, "r");
  filesize = getSize(in_file);
  char ook[filesize];
  fread(ook, 1, filesize, in_file);
  fclose(in_file);
  char *bf = malloc(bfsize(ook, filesize));
  int index = 0;
  char c;
  char last_character = '0';
  for (i = 0; i < filesize; i++) {
    if (isValid(ook[i])) {
      if (last_character == '0')
        last_character = ook[i];
      else {
        c = ook2bfchar(last_character, ook[i]);
        bf[index] = c;
        index++;
        last_character = '0';
      }
    }
  }
  return bf;
}


x86 assembly (clang, -O0):
<ook2bf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <getSize@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1080 <bfsize@plt>
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movb   $0x30,-0x36(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12a9 <ook2bf+0x129>
mov    -0x40(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1090 <isValid@plt>
cmp    $0x0,%rax
je     1296 <ook2bf+0x116>
movsbl -0x36(%rbp),%eax
cmp    $0x30,%eax
jne    125c <ook2bf+0xdc>
mov    -0x40(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x36(%rbp)
jmp    1291 <ook2bf+0x111>
mov    -0x40(%rbp),%rax
mov    -0x36(%rbp),%dl
movslq -0x18(%rbp),%rcx
movsbl %dl,%edi
movsbl (%rax,%rcx,1),%esi
call   1050 <ook2bfchar@plt>
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%dl
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
movb   $0x30,-0x36(%rbp)
jmp    1296 <ook2bf+0x116>
jmp    129b <ook2bf+0x11b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1215 <ook2bf+0x95>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ook2bf>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe6b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   10a0 <getSize@plt>
mov    %eax,%r15d
mov    %eax,%r12d
lea    0xf(%r12),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r13
sub    %rax,%r13
mov    %r13,%rsp
mov    %r13,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r13,%rdi
mov    %r15d,%esi
call   1080 <bfsize@plt>
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
test   %r15d,%r15d
jle    1248 <ook2bf+0xc8>
xor    %ebx,%ebx
mov    $0x30,%r14b
xor    %r15d,%r15d
jmp    1227 <ook2bf+0xa7>
nopl   (%rax)
movsbl %r14b,%edi
movsbl %al,%esi
call   1050 <ook2bfchar@plt>
movslq %r15d,%r15
mov    -0x30(%rbp),%rcx
mov    %al,(%rcx,%r15,1)
add    $0x1,%r15d
mov    $0x30,%r14b
add    $0x1,%rbx
cmp    %rbx,%r12
je     1248 <ook2bf+0xc8>
movsbl 0x0(%r13,%rbx,1),%edi
call   1090 <isValid@plt>
test   %rax,%rax
je     121e <ook2bf+0x9e>
movzbl 0x0(%r13,%rbx,1),%eax
cmp    $0x30,%r14b
jne    1200 <ook2bf+0x80>
mov    %eax,%r14d
jmp    121e <ook2bf+0x9e>
mov    -0x30(%rbp),%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i8* @ook2bf(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8
%11 = alloca i8
store i8* %0, i8** %2
%12 = load i8*, i8** %2
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %3
%14 = load i32*, i32** %3
%15 = call i32 @getSize(i32* %14)
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %6
%19 = alloca i8, i64 %17
store i64 %17, i64* %7
%20 = load i32, i32* %4
%21 = load i32*, i32** %3
%22 = call i32 @fread(i8* %19, i32 1, i32 %20, i32* %21)
%23 = load i32*, i32** %3
%24 = call i32 @fclose(i32* %23)
%25 = load i32, i32* %4
%26 = call i32 @bfsize(i8* %19, i32 %25)
%27 = call i8* @malloc(i32 %26)
store i8* %27, i8** %8
store i32 0, i32* %9
store i8 48, i8* %11
store i32 0, i32* %5
br label %28
28: ; preds = %64, %1
%29 = load i32, i32* %5
%30 = load i32, i32* %4
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %67
32: ; preds = %28
%33 = load i32, i32* %5
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %19, i64 %34
%36 = load i8, i8* %35
%37 = call i64 @isValid(i8 signext %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %63
39: ; preds = %32
%40 = load i8, i8* %11
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 48
br i1 %42, label %43, label %48
43: ; preds = %39
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %19, i64 %45
%47 = load i8, i8* %46
store i8 %47, i8* %11
br label %62
48: ; preds = %39
%49 = load i8, i8* %11
%50 = load i32, i32* %5
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %19, i64 %51
%53 = load i8, i8* %52
%54 = call signext i8 @ook2bfchar(i8 signext %49, i8 signext %53)
store i8 %54, i8* %10
%55 = load i8, i8* %10
%56 = load i8*, i8** %8
%57 = load i32, i32* %9
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
store i8 %55, i8* %59
%60 = load i32, i32* %9
%61 = add nsw i32 %60, 1
store i32 %61, i32* %9
store i8 48, i8* %11
br label %62
62: ; preds = %48, %43
br label %63
63: ; preds = %62, %32
br label %64
64: ; preds = %63
%65 = load i32, i32* %5
%66 = add nsw i32 %65, 1
store i32 %66, i32* %5
br label %28
67: ; preds = %28
%68 = load i8*, i8** %8
%69 = load i8*, i8** %6
ret i8* %68
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define noalias i8* @ook2bf(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @getSize(i32* %2)
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @fread(i8* %5, i32 1, i32 %3, i32* %2)
%7 = tail call i32 @fclose(i32* %2)
%8 = call i32 @bfsize(i8* %5, i32 %3)
%9 = call i8* @malloc(i32 %8)
%10 = icmp sgt i32 %3, 0
br i1 %10, label %11, label %32
11: ; preds = %1, %27
%12 = phi i64 [ %30, %27 ], [ 0, %1 ]
%13 = phi i8 [ %29, %27 ], [ 48, %1 ]
%14 = phi i32 [ %28, %27 ], [ 0, %1 ]
%15 = getelementptr inbounds i8, i8* %5, i64 %12
%16 = load i8, i8* %15
%17 = call i64 @isValid(i8 signext %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %27, label %19
19: ; preds = %11
%20 = icmp eq i8 %13, 48
%21 = load i8, i8* %15
br i1 %20, label %27, label %22
22: ; preds = %19
%23 = call signext i8 @ook2bfchar(i8 signext %13, i8 signext %21)
%24 = sext i32 %14 to i64
%25 = getelementptr inbounds i8, i8* %9, i64 %24
store i8 %23, i8* %25
%26 = add nsw i32 %14, 1
br label %27
27: ; preds = %19, %11, %22
%28 = phi i32 [ %26, %22 ], [ %14, %11 ], [ %14, %19 ]
%29 = phi i8 [ 48, %22 ], [ %13, %11 ], [ %21, %19 ]
%30 = add nuw nsw i64 %12, 1
%31 = icmp eq i64 %30, %4
br i1 %31, label %32, label %11
32: ; preds = %27, %1
ret i8* %9
}