#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*/ chomp(char *);
int /*<<< orphan*/ exit(int);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char **read_input(char ***s, size_t length, FILE *f) {
  char **temp_s;
  char buffer[length];
  char *line;
  int i;
  temp_s = (char **)malloc(sizeof(char *) * 100);
  if (temp_s == NULL) {
    fprintf(stderr, "Error allocating memory in read_input\n");
    exit(1);
  }
  for (i = 0; fgets(buffer, length, f) && i < 100; i++) {
    line = (char *)malloc(sizeof(char) * (strlen(buffer) + 1));
    if (line == NULL) {
      fprintf(stderr, "Error allocating memory in read_inpput\n");
      exit(1);
    }
    strncpy(line, buffer, strlen(buffer) + 1);
    chomp(line);
    temp_s[i] = line;
  }
  temp_s[i] = NULL;
  if (feof(f)) {
    *s = temp_s;
  } else {
    fprintf(stderr, "Error reading input\n");
    exit(1);
  }
  return temp_s;
}


x86 assembly (clang, -O0):
<read_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    $0x320,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f3 <read_input+0x73>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe1c(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x49(%rbp)
je     1227 <read_input+0xa7>
cmpl   $0x64,-0x3c(%rbp)
setl   %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    1237 <read_input+0xb7>
jmp    12c8 <read_input+0x148>
mov    -0x48(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    127e <read_input+0xfe>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
lea    0xdb8(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x48(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    %rax,-0x58(%rbp)
call   1040 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x38(%rbp),%rdi
call   1090 <chomp@plt>
mov    -0x38(%rbp),%rdx
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11fa <read_input+0x7a>
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     12fb <read_input+0x17b>
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    131a <read_input+0x19a>
mov    0x2cde(%rip),%rax
mov    (%rax),%edi
lea    0xd44(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_input>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsp,%r12
lea    0xf(%rsi),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    $0x320,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1298 <read_input+0x118>
mov    %rax,-0x30(%rbp)
mov    %r15,-0x38(%rbp)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1245 <read_input+0xc5>
mov    %rbx,-0x40(%rbp)
xor    %r15d,%r15d
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1279 <read_input+0xf9>
mov    %rax,%r14
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <strncpy@plt>
mov    %r14,%rdi
call   1090 <chomp@plt>
mov    -0x30(%rbp),%rax
mov    %r14,(%rax,%r15,8)
lea    0x1(%r15),%rbx
mov    %r12,%rdi
mov    -0x40(%rbp),%rsi
mov    %r13,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1247 <read_input+0xc7>
cmp    $0x63,%r15
mov    %rbx,%r15
jb     11e0 <read_input+0x60>
jmp    1247 <read_input+0xc7>
xor    %ebx,%ebx
mov    -0x30(%rbp),%r15
movq   $0x0,(%r15,%rbx,8)
mov    %r13,%rdi
call   1070 <feof@plt>
test   %rax,%rax
je     12aa <read_input+0x12a>
mov    -0x38(%rbp),%rax
mov    %r15,(%rax)
mov    %r15,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
lea    0xd9e(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
lea    0xd58(%rip),%rsi
jmp    1289 <read_input+0x109>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
lea    0xd95(%rip),%rsi
jmp    1289 <read_input+0x109>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"Error allocating memory in read_input\0A\00"
@.str.1 = [40 x i8] c"Error allocating memory in read_inpput\0A\00"
@.str.2 = [21 x i8] c"Error reading input\0A\00"
define i8** @read_input(i8*** %0, i64 %1, i32* %2) {
%4 = alloca i8***
%5 = alloca i64
%6 = alloca i32*
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i32
store i8*** %0, i8**** %4
store i64 %1, i64* %5
store i32* %2, i32** %6
%12 = load i64, i64* %5
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %8
%14 = alloca i8, i64 %12
store i64 %12, i64* %9
%15 = call i64 @malloc(i32 800)
%16 = inttoptr i64 %15 to i8**
store i8** %16, i8*** %7
%17 = load i8**, i8*** %7
%18 = icmp eq i8** %17, null
br i1 %18, label %19, label %23
19: ; preds = %3
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %3
store i32 0, i32* %11
br label %24
24: ; preds = %60, %23
%25 = load i64, i64* %5
%26 = load i32*, i32** %6
%27 = call i64 @fgets(i8* %14, i64 %25, i32* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i32, i32* %11
%31 = icmp slt i32 %30, 100
br label %32
32: ; preds = %29, %24
%33 = phi i1 [ false, %24 ], [ %31, %29 ]
br i1 %33, label %34, label %63
34: ; preds = %32
%35 = call i32 @strlen(i8* %14)
%36 = add nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = mul i64 1, %37
%39 = trunc i64 %38 to i32
%40 = call i64 @malloc(i32 %39)
%41 = inttoptr i64 %40 to i8*
store i8* %41, i8** %10
%42 = load i8*, i8** %10
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %48
44: ; preds = %34
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %34
%49 = load i8*, i8** %10
%50 = call i32 @strlen(i8* %14)
%51 = add nsw i32 %50, 1
%52 = call i32 @strncpy(i8* %49, i8* %14, i32 %51)
%53 = load i8*, i8** %10
%54 = call i32 @chomp(i8* %53)
%55 = load i8*, i8** %10
%56 = load i8**, i8*** %7
%57 = load i32, i32* %11
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8*, i8** %56, i64 %58
store i8* %55, i8** %59
br label %60
60: ; preds = %48
%61 = load i32, i32* %11
%62 = add nsw i32 %61, 1
store i32 %62, i32* %11
br label %24
63: ; preds = %32
%64 = load i8**, i8*** %7
%65 = load i32, i32* %11
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8*, i8** %64, i64 %66
store i8* null, i8** %67
%68 = load i32*, i32** %6
%69 = call i64 @feof(i32* %68)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %63
%72 = load i8**, i8*** %7
%73 = load i8***, i8**** %4
store i8** %72, i8*** %73
br label %78
74: ; preds = %63
%75 = load i32, i32* @stderr
%76 = call i32 @fprintf(i32 %75, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %71
%79 = load i8**, i8*** %7
%80 = load i8*, i8** %8
ret i8** %79
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"Error allocating memory in read_input\0A\00"
@.str.1 = [40 x i8] c"Error allocating memory in read_inpput\0A\00"
@.str.2 = [21 x i8] c"Error reading input\0A\00"
define i8** @read_input(i8*** nocapture writeonly %0, i64 %1, i32* nocapture %2) {
%4 = alloca i8, i64 %1
%5 = tail call i64 @malloc(i32 800)
%6 = inttoptr i64 %5 to i8**
%7 = icmp eq i64 %5, 0
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = call i64 @fgets(i8* %4, i64 %1, i32* %2)
%10 = icmp eq i64 %9, 0
br i1 %10, label %39, label %15
11: ; preds = %3
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %8, %26
%16 = phi i64 [ %32, %26 ], [ 0, %8 ]
%17 = call i32 @strlen(i8* %4)
%18 = add nsw i32 %17, 1
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i8*
%21 = icmp eq i64 %19, 0
br i1 %21, label %22, label %26
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %15
%27 = call i32 @strlen(i8* %4)
%28 = add nsw i32 %27, 1
%29 = call i32 @strncpy(i8* %20, i8* %4, i32 %28)
%30 = call i32 @chomp(i8* %20)
%31 = getelementptr inbounds i8*, i8** %6, i64 %16
store i8* %20, i8** %31
%32 = add nuw nsw i64 %16, 1
%33 = call i64 @fgets(i8* %4, i64 %1, i32* %2)
%34 = icmp ne i64 %33, 0
%35 = icmp ult i64 %16, 99
%36 = select i1 %34, i1 %35, i1 false
br i1 %36, label %15, label %37
37: ; preds = %26
%38 = and i64 %32, 4294967295
br label %39
39: ; preds = %37, %8
%40 = phi i64 [ 0, %8 ], [ %38, %37 ]
%41 = getelementptr inbounds i8*, i8** %6, i64 %40
store i8* null, i8** %41
%42 = call i64 @feof(i32* %2)
%43 = icmp eq i64 %42, 0
br i1 %43, label %45, label %44
44: ; preds = %39
store i8** %6, i8*** %0
ret i8** %6
45: ; preds = %39
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
}