#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getopt(int, char **, char *);
int optind;
int /*<<< orphan*/ printf(char *, ...);
char **realloc(char **, int);
int /*<<< orphan*/ *stdin;
char *strtok(char *, char *);
int main(int argc, char *argv[]) {
  FILE *input;
  int opt;
  char src[5000];
  while ((opt = getopt(argc, argv, "")) != -1) {
    switch (opt) {}
  }
  if (optind >= argc)
    input = stdin;
  else {
    input = fopen(argv[optind], "r");
    if (input == NULL) {
      printf("Couldn't open file\n");
      return -1;
    }
  }
  int i = 0;
  char c;
  while ((c = fgetc(input)) != EOF) {
    src[i++] = c;
  }
  char **res = NULL;
  char *p = strtok(src, "\n");
  int n_spaces = 0;
  i = 0;
  while (p) {
    res = realloc(res, sizeof(char *) * ++n_spaces);
    if (res == NULL)
      return -1;
    res[n_spaces - 1] = p;
    p = strtok(NULL, "\n");
  }
  for (i = 0; i < (n_spaces + 1); ++i)
    printf("res[%d] = %s\n", i, res[i]);
  fclose(input);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x13d0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe7e(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     11ad <main+0x3d>
jmp    1189 <main+0x19>
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jl     11d2 <main+0x62>
mov    0x2e22(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    121e <main+0xae>
mov    -0x10(%rbp),%rax
mov    0x2dfb(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe15(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1219 <main+0xa9>
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13a1 <main+0x231>
jmp    121e <main+0xae>
movl   $0x0,-0x13b4(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x13b5(%rbp)
movsbl %al,%eax
mov    0x2d9f(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1271 <main+0x101>
mov    -0x13b5(%rbp),%cl
mov    -0x13b4(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x13b4(%rbp)
cltq
mov    %cl,-0x13b0(%rbp,%rax,1)
jmp    1228 <main+0xb8>
movq   $0x0,-0x13c0(%rbp)
lea    -0x13b0(%rbp),%rdi
lea    0xd8a(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x13c8(%rbp)
movl   $0x0,-0x13cc(%rbp)
movl   $0x0,-0x13b4(%rbp)
cmpq   $0x0,-0x13c8(%rbp)
je     1336 <main+0x1c6>
mov    -0x13c0(%rbp),%rdi
mov    -0x13cc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13cc(%rbp)
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1060 <realloc@plt>
mov    %rax,-0x13c0(%rbp)
cmpq   $0x0,-0x13c0(%rbp)
jne    12fc <main+0x18c>
movl   $0xffffffff,-0x4(%rbp)
jmp    13a1 <main+0x231>
mov    -0x13c8(%rbp),%rdx
mov    -0x13c0(%rbp),%rax
mov    -0x13cc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
xor    %eax,%eax
mov    %eax,%edi
lea    0xcef(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x13c8(%rbp)
jmp    12aa <main+0x13a>
movl   $0x0,-0x13b4(%rbp)
mov    -0x13b4(%rbp),%eax
mov    -0x13cc(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1391 <main+0x221>
mov    -0x13b4(%rbp),%esi
mov    -0x13c0(%rbp),%rax
movslq -0x13b4(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xca0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x13b4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13b4(%rbp)
jmp    1340 <main+0x1d0>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x13d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1388,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe72(%rip),%r14
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   10a0 <getopt@plt>
cmp    $0xffffffff,%eax
jne    11a0 <main+0x20>
mov    0x2e1f(%rip),%rax
movslq (%rax),%rax
cmp    %ebp,%eax
jge    11ee <main+0x6e>
mov    (%rbx,%rax,8),%rdi
lea    0xe35(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11f8 <main+0x78>
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    12c4 <main+0x144>
mov    0x2df3(%rip),%rax
mov    (%rax),%r14
mov    %r14,%rdi
call   1060 <fgetc@plt>
mov    0x2dd9(%rip),%rbx
cmp    (%rbx),%al
je     1223 <main+0xa3>
mov    %rsp,%rbp
xchg   %ax,%ax
mov    %al,0x0(%rbp)
mov    %r14,%rdi
call   1060 <fgetc@plt>
add    $0x1,%rbp
cmp    (%rbx),%al
jne    1210 <main+0x90>
lea    0xde4(%rip),%rsi
mov    %rsp,%rdi
call   1090 <strtok@plt>
test   %rax,%rax
je     1284 <main+0x104>
mov    %rax,%r15
mov    $0x1,%ebx
mov    $0x8,%ebp
xor    %r13d,%r13d
lea    0xdc0(%rip),%r12
xchg   %ax,%ax
mov    %r13,%rdi
mov    %ebp,%esi
call   1070 <realloc@plt>
test   %rax,%rax
je     11e4 <main+0x64>
mov    %rax,%r13
mov    %r15,-0x8(%rax,%rbx,8)
xor    %edi,%edi
mov    %r12,%rsi
call   1090 <strtok@plt>
mov    %rax,%r15
add    $0x1,%rbx
add    $0x8,%ebp
test   %rax,%rax
jne    1250 <main+0xd0>
mov    %ebx,%ebx
jmp    128c <main+0x10c>
mov    $0x1,%ebx
xor    %r13d,%r13d
lea    0xd6f(%rip),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%r13,%rbp,8),%rdx
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    12a0 <main+0x120>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x1388,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@optind = global i32 0
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [20 x i8] c"Couldn't open file\0A\00"
@EOF = global i8 0
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [14 x i8] c"res[%d] = %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [5000 x i8]
%9 = alloca i32
%10 = alloca i8
%11 = alloca i8**
%12 = alloca i8*
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %14
14: ; preds = %21, %2
%15 = load i32, i32* %4
%16 = load i8**, i8*** %5
%17 = call i32 @getopt(i32 %15, i8** %16, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 %17, i32* %7
%18 = icmp ne i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i32, i32* %7
switch i32 %20, label %21 [
]
21: ; preds = %19
br label %14
22: ; preds = %14
%23 = load i32, i32* @optind
%24 = load i32, i32* %4
%25 = icmp sge i32 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = load i32*, i32** @stdin
store i32* %27, i32** %6
br label %40
28: ; preds = %22
%29 = load i8**, i8*** %5
%30 = load i32, i32* @optind
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %34, i32** %6
%35 = load i32*, i32** %6
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %39
37: ; preds = %28
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %99
39: ; preds = %28
br label %40
40: ; preds = %39, %26
store i32 0, i32* %9
br label %41
41: ; preds = %48, %40
%42 = load i32*, i32** %6
%43 = call signext i8 @fgetc(i32* %42)
store i8 %43, i8* %10
%44 = sext i8 %43 to i32
%45 = load i8, i8* @EOF
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %44, %46
br i1 %47, label %48, label %54
48: ; preds = %41
%49 = load i8, i8* %10
%50 = load i32, i32* %9
%51 = add nsw i32 %50, 1
store i32 %51, i32* %9
%52 = sext i32 %50 to i64
%53 = getelementptr inbounds [5000 x i8], [5000 x i8]* %8, i64 0, i64 %52
store i8 %49, i8* %53
br label %41
54: ; preds = %41
store i8** null, i8*** %11
%55 = getelementptr inbounds [5000 x i8], [5000 x i8]* %8, i64 0, i64 0
%56 = call i8* @strtok(i8* %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %56, i8** %12
store i32 0, i32* %13
store i32 0, i32* %9
br label %57
57: ; preds = %71, %54
%58 = load i8*, i8** %12
%59 = icmp ne i8* %58, null
br i1 %59, label %60, label %79
60: ; preds = %57
%61 = load i8**, i8*** %11
%62 = load i32, i32* %13
%63 = add nsw i32 %62, 1
store i32 %63, i32* %13
%64 = sext i32 %63 to i64
%65 = mul i64 8, %64
%66 = trunc i64 %65 to i32
%67 = call i8** @realloc(i8** %61, i32 %66)
store i8** %67, i8*** %11
%68 = load i8**, i8*** %11
%69 = icmp eq i8** %68, null
br i1 %69, label %70, label %71
70: ; preds = %60
store i32 -1, i32* %3
br label %99
71: ; preds = %60
%72 = load i8*, i8** %12
%73 = load i8**, i8*** %11
%74 = load i32, i32* %13
%75 = sub nsw i32 %74, 1
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8*, i8** %73, i64 %76
store i8* %72, i8** %77
%78 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %78, i8** %12
br label %57
79: ; preds = %57
store i32 0, i32* %9
br label %80
80: ; preds = %93, %79
%81 = load i32, i32* %9
%82 = load i32, i32* %13
%83 = add nsw i32 %82, 1
%84 = icmp slt i32 %81, %83
br i1 %84, label %85, label %96
85: ; preds = %80
%86 = load i32, i32* %9
%87 = load i8**, i8*** %11
%88 = load i32, i32* %9
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i8*, i8** %87, i64 %89
%91 = load i8*, i8** %90
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %86, i8* %91)
br label %93
93: ; preds = %85
%94 = load i32, i32* %9
%95 = add nsw i32 %94, 1
store i32 %95, i32* %9
br label %80
96: ; preds = %80
%97 = load i32*, i32** %6
%98 = call i32 @fclose(i32* %97)
store i32 0, i32* %3
br label %99
99: ; preds = %96, %70, %37
%100 = load i32, i32* %3
ret i32 %100
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@optind = global i32 0
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [14 x i8] c"res[%d] = %s\0A\00"
@str = [19 x i8] c"Couldn't open file\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [5000 x i8]
%4 = getelementptr inbounds [5000 x i8], [5000 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %5, %2
%6 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %5
8: ; preds = %5
%9 = load i32, i32* @optind
%10 = icmp slt i32 %9, %0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = load i32*, i32** @stdin
br label %21
13: ; preds = %8
%14 = sext i32 %9 to i64
%15 = getelementptr inbounds i8*, i8** %1, i64 %14
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %66
21: ; preds = %13, %11
%22 = phi i32* [ %12, %11 ], [ %17, %13 ]
%23 = tail call signext i8 @fgetc(i32* %22)
%24 = load i8, i8* @EOF
%25 = icmp eq i8 %23, %24
br i1 %25, label %34, label %26
26: ; preds = %21, %26
%27 = phi i64 [ %29, %26 ], [ 0, %21 ]
%28 = phi i8 [ %31, %26 ], [ %23, %21 ]
%29 = add nuw i64 %27, 1
%30 = getelementptr inbounds [5000 x i8], [5000 x i8]* %3, i64 0, i64 %27
store i8 %28, i8* %30
%31 = tail call signext i8 @fgetc(i32* %22)
%32 = load i8, i8* @EOF
%33 = icmp eq i8 %31, %32
br i1 %33, label %34, label %26
34: ; preds = %26, %21
%35 = call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%36 = icmp eq i8* %35, null
br i1 %36, label %40, label %43
37: ; preds = %52
%38 = add i64 %44, 2
%39 = and i64 %38, 4294967295
br label %40
40: ; preds = %37, %34
%41 = phi i8** [ null, %34 ], [ %50, %37 ]
%42 = phi i64 [ 1, %34 ], [ %39, %37 ]
br label %56
43: ; preds = %34, %52
%44 = phi i64 [ %47, %52 ], [ 0, %34 ]
%45 = phi i8* [ %54, %52 ], [ %35, %34 ]
%46 = phi i8** [ %50, %52 ], [ null, %34 ]
%47 = add nuw i64 %44, 1
%48 = trunc i64 %47 to i32
%49 = shl i32 %48, 3
%50 = call i8** @realloc(i8** %46, i32 %49)
%51 = icmp eq i8** %50, null
br i1 %51, label %66, label %52
52: ; preds = %43
%53 = getelementptr inbounds i8*, i8** %50, i64 %44
store i8* %45, i8** %53
%54 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%55 = icmp eq i8* %54, null
br i1 %55, label %37, label %43
56: ; preds = %40, %56
%57 = phi i64 [ 0, %40 ], [ %62, %56 ]
%58 = getelementptr inbounds i8*, i8** %41, i64 %57
%59 = load i8*, i8** %58
%60 = trunc i64 %57 to i32
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %60, i8* %59)
%62 = add nuw nsw i64 %57, 1
%63 = icmp eq i64 %62, %42
br i1 %63, label %64, label %56
64: ; preds = %56
%65 = call i32 @fclose(i32* %22)
br label %66
66: ; preds = %43, %64, %19
%67 = phi i32 [ -1, %19 ], [ 0, %64 ], [ -1, %43 ]
ret i32 %67
}