#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*/ error(char *);
int /*<<< orphan*/ exit(int);
scalar_t__ ferror(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
void *malloc(int);
char *obfuscate(char *);
char **realloc(char **, int);
char *strcat(char *, char *);
int strlen(char *);
char **readfile(FILE *fin, unsigned int *length) {
  if (fin == NULL) {
    error("error: cannot open file\n");
    exit(1);
  }
  int lines_length = 0;
  int lines_alloc = 16;
  char **lines = malloc(lines_alloc * sizeof(char *));
  char *line = malloc(512 * sizeof(char));
  char *bigline = malloc(512 * sizeof(char));
  bigline[0] = '\0';
  while (fgets(line, 512 * sizeof(char), fin)) {
    line = obfuscate(line);
    bigline = strcat(bigline, line);
    if (line[strlen(line) - 1] != '\\') {
      if (lines_length >= lines_alloc) {
        lines_alloc += 16;
        lines = realloc(lines, lines_alloc * sizeof(char *));
      }
      lines[lines_length] = bigline;
      lines_length++;
      bigline = malloc(512 * sizeof(char));
      bigline[0] = '\0';
    } else {
      bigline[strlen(bigline) - 1] = '\0';
    }
    line = malloc(512 * sizeof(char));
  }
  if (ferror(fin)) {
    error("error: cannot read file\n");
    exit(1);
  }
  *length = lines_length;
  return lines;
}


x86 assembly (clang, -O0):
<readfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11c1 <readfile+0x31>
lea    0xe4e(%rip),%rdi
call   1090 <error@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x10,-0x18(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x200,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x200,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x200,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12fc <readfile+0x16c>
mov    -0x28(%rbp),%rdi
call   1030 <obfuscate@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10a0 <strcat@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
je     12c8 <readfile+0x138>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jl     1295 <readfile+0x105>
mov    -0x18(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1080 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    $0x200,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
jmp    12e9 <readfile+0x159>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    $0x200,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
jmp    1205 <readfile+0x75>
mov    -0x8(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1325 <readfile+0x195>
lea    0xd03(%rip),%rdi
call   1090 <error@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readfile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     12bf <readfile+0x12f>
mov    %rdi,%r12
mov    %rsi,(%rsp)
mov    $0x80,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    $0x200,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    $0x200,%edi
call   1070 <malloc@plt>
mov    %rax,%r13
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     129a <readfile+0x10a>
mov    $0x10,%r14d
jmp    1236 <readfile+0xa6>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1050 <strlen@plt>
cltq
add    %r13,%rax
add    $0xffffffffffffffff,%rax
movb   $0x0,(%rax)
mov    $0x200,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x200,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     129a <readfile+0x10a>
mov    %rbx,%rdi
call   1030 <obfuscate@plt>
mov    %rax,%rbx
mov    %r13,%rdi
mov    %rax,%rsi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0x5c,-0x1(%rax,%rbx,1)
je     1200 <readfile+0x70>
cmp    %r14d,%ebp
jl     127e <readfile+0xee>
mov    %r14d,%ebx
add    $0x10,%ebx
lea    0x80(,%r14,8),%esi
mov    %r15,%rdi
call   1080 <realloc@plt>
mov    %rax,%r15
mov    %ebx,%r14d
movslq %ebp,%rax
mov    %r13,(%r15,%rax,8)
add    $0x1,%ebp
mov    $0x200,%edi
call   1070 <malloc@plt>
mov    %rax,%r13
jmp    1211 <readfile+0x81>
mov    %r12,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    12c8 <readfile+0x138>
mov    (%rsp),%rax
mov    %ebp,(%rax)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd3a(%rip),%rdi
jmp    12cf <readfile+0x13f>
lea    0xd4a(%rip),%rdi
call   1090 <error@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

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

LLVM IR (-O2):
@.str = [25 x i8] c"error: cannot open file\0A\00"
@.str.1 = [25 x i8] c"error: cannot read file\0A\00"
define i8** @readfile(i32* %0, i32* nocapture writeonly %1) {
%3 = icmp eq i32* %0, null
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 @error(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = tail call dereferenceable_or_null(128) i8* @malloc(i32 128)
%9 = bitcast i8* %8 to i8**
%10 = tail call dereferenceable_or_null(512) i8* @malloc(i32 512)
%11 = tail call dereferenceable_or_null(512) i8* @malloc(i32 512)
store i8 0, i8* %11
%12 = tail call i64 @fgets(i8* %10, i32 512, i32* %0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %55, label %14
14: ; preds = %7, %46
%15 = phi i8* [ %51, %46 ], [ %11, %7 ]
%16 = phi i8* [ %52, %46 ], [ %10, %7 ]
%17 = phi i8** [ %50, %46 ], [ %9, %7 ]
%18 = phi i32 [ %49, %46 ], [ 16, %7 ]
%19 = phi i32 [ %48, %46 ], [ 0, %7 ]
%20 = tail call i8* @obfuscate(i8* %16)
%21 = tail call i8* @strcat(i8* dereferenceable(1) %15, i8* dereferenceable(1) %20)
%22 = tail call i32 @strlen(i8* %20)
%23 = add nsw i32 %22, -1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %20, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 92
br i1 %27, label %41, label %28
28: ; preds = %14
%29 = icmp slt i32 %19, %18
br i1 %29, label %34, label %30
30: ; preds = %28
%31 = add nsw i32 %18, 16
%32 = shl i32 %31, 3
%33 = tail call i8** @realloc(i8** %17, i32 %32)
br label %34
34: ; preds = %30, %28
%35 = phi i32 [ %31, %30 ], [ %18, %28 ]
%36 = phi i8** [ %33, %30 ], [ %17, %28 ]
%37 = sext i32 %19 to i64
%38 = getelementptr inbounds i8*, i8** %36, i64 %37
store i8* %15, i8** %38
%39 = add nsw i32 %19, 1
%40 = tail call dereferenceable_or_null(512) i8* @malloc(i32 512)
br label %46
41: ; preds = %14
%42 = tail call i32 @strlen(i8* %15)
%43 = add nsw i32 %42, -1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %15, i64 %44
br label %46
46: ; preds = %41, %34
%47 = phi i8* [ %45, %41 ], [ %40, %34 ]
%48 = phi i32 [ %19, %41 ], [ %39, %34 ]
%49 = phi i32 [ %18, %41 ], [ %35, %34 ]
%50 = phi i8** [ %17, %41 ], [ %36, %34 ]
%51 = phi i8* [ %15, %41 ], [ %40, %34 ]
store i8 0, i8* %47
%52 = tail call dereferenceable_or_null(512) i8* @malloc(i32 512)
%53 = tail call i64 @fgets(i8* %52, i32 512, i32* %0)
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %14
55: ; preds = %46, %7
%56 = phi i32 [ 0, %7 ], [ %48, %46 ]
%57 = phi i8** [ %9, %7 ], [ %50, %46 ]
%58 = tail call i64 @ferror(i32* %0)
%59 = icmp eq i64 %58, 0
br i1 %59, label %63, label %60
60: ; preds = %55
%61 = tail call i32 @error(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%62 = tail call i32 @exit(i32 1)
unreachable
63: ; preds = %55
store i32 %56, i32* %1
ret i8** %57
}