#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 *fgets(char *, int const, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(int const);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
char *strsep(char **, char *);
char *readsplit(char **a, FILE *fp, char *sep) {
  const int size = 256;
  char *s = malloc(size);
  char *buf = malloc(128);
  while ((buf = fgets(buf, size, fp)) != NULL)
    sprintf(s, "%s%s", s, buf);
  if (strcmp(s, "") == 0) {
    a = NULL;
    return "";
  }
  char *lchar = &s[strlen(s) - 1];
  if (*lchar == '\n' && *sep != '\n')
    *lchar = '\0';
  if (sep == NULL)
    return s;
  if (strcmp(sep, "\n") == 0)
    puts("kats");
  int i = 0;
  if (s[1] == 'm') {
    char *vol = malloc(4);
    sprintf(vol, "%c%c", s[6], s[7]);
    a[0] = vol;
    strsep(&s, sep);
    i++;
  }
  char *token;
  while ((token = strsep(&s, sep)) != NULL) {
    a[i] = token;
    i++;
  }
  free(s);
  return "";
}


x86 assembly (clang, -O0):
<readsplit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x100,-0x24(%rbp)
mov    $0x100,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    $0x80,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     11f6 <readsplit+0x76>
mov    -0x30(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
jmp    11b7 <readsplit+0x37>
mov    -0x30(%rbp),%rdi
lea    0xe05(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1228 <readsplit+0xa8>
movq   $0x0,-0x10(%rbp)
lea    0xde7(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    136c <readsplit+0x1ec>
mov    -0x30(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x60(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1273 <readsplit+0xf3>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     1273 <readsplit+0xf3>
mov    -0x40(%rbp),%rax
movb   $0x0,(%rax)
cmpq   $0x0,-0x20(%rbp)
jne    128b <readsplit+0x10b>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    136c <readsplit+0x1ec>
mov    -0x20(%rbp),%rdi
lea    0xd6f(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12b1 <readsplit+0x131>
lea    0xd5b(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x30(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x6d,%eax
jne    131a <readsplit+0x19a>
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x30(%rbp),%rax
movsbl 0x6(%rax),%edx
mov    -0x30(%rbp),%rax
movsbl 0x7(%rax),%ecx
lea    0xd1a(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    -0x50(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rsi
lea    -0x30(%rbp),%rdi
call   1090 <strsep@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    131f <readsplit+0x19f>
mov    -0x20(%rbp),%rsi
lea    -0x30(%rbp),%rdi
call   1090 <strsep@plt>
mov    %rax,-0x58(%rbp)
cmp    $0x0,%rax
je     1358 <readsplit+0x1d8>
mov    -0x58(%rbp),%rdx
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    131f <readsplit+0x19f>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
lea    0xc9e(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readsplit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r14
mov    $0x100,%edi
call   1080 <malloc@plt>
mov    %rax,%r13
mov    %rax,(%rsp)
mov    $0x80,%edi
call   1080 <malloc@plt>
mov    %rax,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11fb <readsplit+0x7b>
mov    %rax,%rbx
lea    0xe32(%rip),%rbp
xchg   %ax,%ax
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11d0 <readsplit+0x50>
lea    0xe04(%rip),%r15
mov    %r13,%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12f6 <readsplit+0x176>
mov    %r13,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%r13,1)
jne    1237 <readsplit+0xb7>
cmpb   $0xa,(%r12)
je     1240 <readsplit+0xc0>
movb   $0x0,-0x1(%r13,%rax,1)
jmp    1240 <readsplit+0xc0>
test   %r12,%r12
je     12f3 <readsplit+0x173>
lea    0xdbe(%rip),%rsi
mov    %r12,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1298 <readsplit+0x118>
cmpb   $0x6d,0x1(%r13)
jne    12ab <readsplit+0x12b>
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
movsbl 0x6(%r13),%edx
movsbl 0x7(%r13),%ecx
lea    0xd93(%rip),%rsi
mov    %rax,%rdi
xor    %eax,%eax
call   10a0 <sprintf@plt>
mov    %rbx,(%r14)
mov    %rsp,%rdi
mov    %r12,%rsi
call   1090 <strsep@plt>
mov    $0x1,%ebx
jmp    12ad <readsplit+0x12d>
lea    0xd68(%rip),%rdi
call   1040 <puts@plt>
cmpb   $0x6d,0x1(%r13)
je     125b <readsplit+0xdb>
xor    %ebx,%ebx
mov    %rsp,%rdi
mov    %r12,%rsi
call   1090 <strsep@plt>
test   %rax,%rax
je     12e8 <readsplit+0x168>
lea    (%r14,%rbx,8),%rbp
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rax,0x0(%rbp)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <strsep@plt>
add    $0x8,%rbp
test   %rax,%rax
jne    12d0 <readsplit+0x150>
mov    (%rsp),%rdi
call   1030 <free@plt>
jmp    12f6 <readsplit+0x176>
mov    %r13,%r15
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [5 x i8] c"kats\00"
@.str.4 = [5 x i8] c"%c%c\00"
define i8* @readsplit(i8** %0, i32* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
store i8** %0, i8*** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
store i32 256, i32* %8
%15 = call i8* @malloc(i32 256)
store i8* %15, i8** %9
%16 = call i8* @malloc(i32 128)
store i8* %16, i8** %10
br label %17
17: ; preds = %22, %3
%18 = load i8*, i8** %10
%19 = load i32*, i32** %6
%20 = call i8* @fgets(i8* %18, i32 256, i32* %19)
store i8* %20, i8** %10
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load i8*, i8** %9
%24 = load i8*, i8** %9
%25 = load i8*, i8** %10
%26 = call i32 (i8*, i8*, ...) @sprintf(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %24, i8* %25)
br label %17
27: ; preds = %17
%28 = load i8*, i8** %9
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
store i8** null, i8*** %5
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8** %4
br label %102
32: ; preds = %27
%33 = load i8*, i8** %9
%34 = load i8*, i8** %9
%35 = call i32 @strlen(i8* %34)
%36 = sub nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %33, i64 %37
store i8* %38, i8** %11
%39 = load i8*, i8** %11
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 10
br i1 %42, label %43, label %50
43: ; preds = %32
%44 = load i8*, i8** %7
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %46, 10
br i1 %47, label %48, label %50
48: ; preds = %43
%49 = load i8*, i8** %11
store i8 0, i8* %49
br label %50
50: ; preds = %48, %43, %32
%51 = load i8*, i8** %7
%52 = icmp eq i8* %51, null
br i1 %52, label %53, label %55
53: ; preds = %50
%54 = load i8*, i8** %9
store i8* %54, i8** %4
br label %102
55: ; preds = %50
%56 = load i8*, i8** %7
%57 = call i64 @strcmp(i8* %56, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %55
%60 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %61
61: ; preds = %59, %55
store i32 0, i32* %12
%62 = load i8*, i8** %9
%63 = getelementptr inbounds i8, i8* %62, i64 1
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp eq i32 %65, 109
br i1 %66, label %67, label %86
67: ; preds = %61
%68 = call i8* @malloc(i32 4)
store i8* %68, i8** %13
%69 = load i8*, i8** %13
%70 = load i8*, i8** %9
%71 = getelementptr inbounds i8, i8* %70, i64 6
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = load i8*, i8** %9
%75 = getelementptr inbounds i8, i8* %74, i64 7
%76 = load i8, i8* %75
%77 = sext i8 %76 to i32
%78 = call i32 (i8*, i8*, ...) @sprintf(i8* %69, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %73, i32 %77)
%79 = load i8*, i8** %13
%80 = load i8**, i8*** %5
%81 = getelementptr inbounds i8*, i8** %80, i64 0
store i8* %79, i8** %81
%82 = load i8*, i8** %7
%83 = call i8* @strsep(i8** %9, i8* %82)
%84 = load i32, i32* %12
%85 = add nsw i32 %84, 1
store i32 %85, i32* %12
br label %86
86: ; preds = %67, %61
br label %87
87: ; preds = %91, %86
%88 = load i8*, i8** %7
%89 = call i8* @strsep(i8** %9, i8* %88)
store i8* %89, i8** %14
%90 = icmp ne i8* %89, null
br i1 %90, label %91, label %99
91: ; preds = %87
%92 = load i8*, i8** %14
%93 = load i8**, i8*** %5
%94 = load i32, i32* %12
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i8*, i8** %93, i64 %95
store i8* %92, i8** %96
%97 = load i32, i32* %12
%98 = add nsw i32 %97, 1
store i32 %98, i32* %12
br label %87
99: ; preds = %87
%100 = load i8*, i8** %9
%101 = call i32 @free(i8* %100)
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8** %4
br label %102
102: ; preds = %99, %53, %31
%103 = load i8*, i8** %4
ret i8* %103
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [5 x i8] c"kats\00"
@.str.4 = [5 x i8] c"%c%c\00"
define i8* @readsplit(i8** nocapture writeonly %0, i32* nocapture %1, i8* %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
store i8* %6, i8** %4
%7 = tail call dereferenceable_or_null(128) i8* @malloc(i32 128)
%8 = tail call i8* @fgets(i8* %7, i32 256, i32* %1)
%9 = icmp eq i8* %8, null
br i1 %9, label %15, label %10
10: ; preds = %3, %10
%11 = phi i8* [ %13, %10 ], [ %8, %3 ]
%12 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %11)
%13 = tail call i8* @fgets(i8* %11, i32 256, i32* %1)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %10
15: ; preds = %10, %3
%16 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %64, label %18
18: ; preds = %15
%19 = tail call i32 @strlen(i8* %6)
%20 = add nsw i32 %19, -1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %6, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 10
br i1 %24, label %25, label %29
25: ; preds = %18
%26 = load i8, i8* %2
%27 = icmp eq i8 %26, 10
br i1 %27, label %31, label %28
28: ; preds = %25
store i8 0, i8* %22
br label %31
29: ; preds = %18
%30 = icmp eq i8* %2, null
br i1 %30, label %64, label %31
31: ; preds = %25, %28, %29
%32 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %34, %31
%37 = getelementptr inbounds i8, i8* %6, i64 1
%38 = load i8, i8* %37
%39 = icmp eq i8 %38, 109
br i1 %39, label %40, label %50
40: ; preds = %36
%41 = tail call dereferenceable_or_null(4) i8* @malloc(i32 4)
%42 = getelementptr inbounds i8, i8* %6, i64 6
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = getelementptr inbounds i8, i8* %6, i64 7
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %41, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %44, i32 %47)
store i8* %41, i8** %0
%49 = call i8* @strsep(i8** %4, i8* %2)
br label %50
50: ; preds = %40, %36
%51 = phi i64 [ 1, %40 ], [ 0, %36 ]
%52 = call i8* @strsep(i8** %4, i8* %2)
%53 = icmp eq i8* %52, null
br i1 %53, label %61, label %54
54: ; preds = %50, %54
%55 = phi i64 [ %58, %54 ], [ %51, %50 ]
%56 = phi i8* [ %59, %54 ], [ %52, %50 ]
%57 = getelementptr inbounds i8*, i8** %0, i64 %55
store i8* %56, i8** %57
%58 = add nuw i64 %55, 1
%59 = call i8* @strsep(i8** %4, i8* %2)
%60 = icmp eq i8* %59, null
br i1 %60, label %61, label %54
61: ; preds = %54, %50
%62 = load i8*, i8** %4
%63 = call i32 @free(i8* %62)
br label %64
64: ; preds = %29, %61, %15
%65 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %15 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %61 ], [ %6, %29 ]
ret i8* %65
}