#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int);
void *malloc(int);
int /*<<< orphan*/ printf(char *, int, char const *, int);
int /*<<< orphan*/ realloc(char *, int);
char *strchr(char *, char);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strsep(char **, char *);
char **split(const char *in, int line) {
  int size = strlen(in) + 1;
  char *copy = malloc(size * sizeof(*copy));
  if (copy == NULL)
    return NULL;
  strncpy(copy, in, size);
  char *comment_start = strchr(copy, ';');
  if (comment_start) {
    *comment_start = '\0';
    realloc(copy, comment_start - copy + 1);
  }
  char **buf = &copy;
  char *res;
  char **ret = malloc(4 * sizeof(*ret));
  int idx = 0;
  for (idx = 0; idx < 4; idx++) {
    res = strsep(buf, " \t");
    if (res != NULL) {
      ret[idx] = res;
    } else if (idx < 3) {
      printf("[%d] Error: wrong number of input symbols, must be at least 3. "
             "\"%s\" has %d.",
             line, in, idx);
      exit(-1);
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c9 <split+0x49>
movq   $0x0,-0x8(%rbp)
jmp    12c3 <split+0x143>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rdi
mov    $0x3b,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1217 <split+0x97>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%esi
call   1090 <realloc@plt>
lea    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x20,%edi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x4,-0x44(%rbp)
jge    12bb <split+0x13b>
mov    -0x30(%rbp),%rdi
lea    0xdb0(%rip),%rsi
call   1080 <strsep@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1279 <split+0xf9>
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    12a8 <split+0x128>
cmpl   $0x3,-0x44(%rbp)
jge    12a3 <split+0x123>
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x44(%rbp),%ecx
lea    0xd6f(%rip),%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
jmp    12a8 <split+0x128>
jmp    12ad <split+0x12d>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    123b <split+0xbb>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %eax,%ebp
add    $0x1,%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     124f <split+0xcf>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
mov    $0x3b,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11e0 <split+0x60>
movb   $0x0,(%rax)
mov    (%rsp),%rdi
sub    %edi,%eax
add    $0x1,%eax
mov    %eax,%esi
call   1090 <realloc@plt>
mov    $0x20,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
lea    0xe0c(%rip),%rsi
mov    %rsp,%rdi
call   1080 <strsep@plt>
test   %rax,%rax
je     125f <split+0xdf>
mov    %rax,0x0(%rbp)
lea    0xdf4(%rip),%rsi
mov    %rsp,%rdi
call   1080 <strsep@plt>
test   %rax,%rax
je     1263 <split+0xe3>
mov    %rax,0x8(%rbp)
lea    0xddc(%rip),%rsi
mov    %rsp,%rdi
call   1080 <strsep@plt>
test   %rax,%rax
je     126a <split+0xea>
mov    %rax,0x10(%rbp)
lea    0xdc4(%rip),%rsi
mov    %rsp,%rdi
call   1080 <strsep@plt>
test   %rax,%rax
je     1251 <split+0xd1>
mov    %rax,0x18(%rbp)
jmp    1251 <split+0xd1>
xor    %ebp,%ebp
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ecx,%ecx
jmp    126f <split+0xef>
mov    $0x1,%ecx
jmp    126f <split+0xef>
mov    $0x2,%ecx
lea    0xd8d(%rip),%rdi
mov    %r14d,%esi
mov    %r15,%rdx
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c" \09\00"
@.str.1 = [76 x i8] c"[%d] Error: wrong number of input symbols, must be at least 3. \22%s\22 has %d.\00"
define i8** @split(i8* %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i8*
%11 = alloca i8**
%12 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
%15 = add nsw i32 %14, 1
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 1
%19 = trunc i64 %18 to i32
%20 = call i8* @malloc(i32 %19)
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %24
23: ; preds = %2
store i8** null, i8*** %3
br label %77
24: ; preds = %2
%25 = load i8*, i8** %7
%26 = load i8*, i8** %4
%27 = load i32, i32* %6
%28 = call i32 @strncpy(i8* %25, i8* %26, i32 %27)
%29 = load i8*, i8** %7
%30 = call i8* @strchr(i8* %29, i8 signext 59)
store i8* %30, i8** %8
%31 = load i8*, i8** %8
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %44
33: ; preds = %24
%34 = load i8*, i8** %8
store i8 0, i8* %34
%35 = load i8*, i8** %7
%36 = load i8*, i8** %8
%37 = load i8*, i8** %7
%38 = ptrtoint i8* %36 to i64
%39 = ptrtoint i8* %37 to i64
%40 = sub i64 %38, %39
%41 = add nsw i64 %40, 1
%42 = trunc i64 %41 to i32
%43 = call i32 @realloc(i8* %35, i32 %42)
br label %44
44: ; preds = %33, %24
store i8** %7, i8*** %9
%45 = call i8* @malloc(i32 32)
%46 = bitcast i8* %45 to i8**
store i8** %46, i8*** %11
store i32 0, i32* %12
store i32 0, i32* %12
br label %47
47: ; preds = %72, %44
%48 = load i32, i32* %12
%49 = icmp slt i32 %48, 4
br i1 %49, label %50, label %75
50: ; preds = %47
%51 = load i8**, i8*** %9
%52 = call i8* @strsep(i8** %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %52, i8** %10
%53 = load i8*, i8** %10
%54 = icmp ne i8* %53, null
br i1 %54, label %55, label %61
55: ; preds = %50
%56 = load i8*, i8** %10
%57 = load i8**, i8*** %11
%58 = load i32, i32* %12
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8*, i8** %57, i64 %59
store i8* %56, i8** %60
br label %71
61: ; preds = %50
%62 = load i32, i32* %12
%63 = icmp slt i32 %62, 3
br i1 %63, label %64, label %70
64: ; preds = %61
%65 = load i32, i32* %5
%66 = load i8*, i8** %4
%67 = load i32, i32* %12
%68 = call i32 @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.1, i64 0, i64 0), i32 %65, i8* %66, i32 %67)
%69 = call i32 @exit(i32 -1)
unreachable
70: ; preds = %61
br label %71
71: ; preds = %70, %55
br label %72
72: ; preds = %71
%73 = load i32, i32* %12
%74 = add nsw i32 %73, 1
store i32 %74, i32* %12
br label %47
75: ; preds = %47
%76 = load i8**, i8*** %11
store i8** %76, i8*** %3
br label %77
77: ; preds = %75, %23
%78 = load i8**, i8*** %3
ret i8** %78
}

LLVM IR (-O2):
@.str = [3 x i8] c" \09\00"
@.str.1 = [76 x i8] c"[%d] Error: wrong number of input symbols, must be at least 3. \22%s\22 has %d.\00"
define noalias i8** @split(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %4, 1
%6 = bitcast i8** %3 to i8*
%7 = tail call i8* @malloc(i32 %5)
store i8* %7, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %43, label %9
9: ; preds = %2
%10 = tail call i32 @strncpy(i8* %7, i8* %0, i32 %5)
%11 = tail call i8* @strchr(i8* dereferenceable(1) %7, i8 signext 59)
%12 = icmp eq i8* %11, null
br i1 %12, label %21, label %13
13: ; preds = %9
store i8 0, i8* %11
%14 = load i8*, i8** %3
%15 = ptrtoint i8* %11 to i64
%16 = ptrtoint i8* %14 to i64
%17 = sub i64 %15, %16
%18 = trunc i64 %17 to i32
%19 = add i32 %18, 1
%20 = tail call i32 @realloc(i8* %14, i32 %19)
br label %21
21: ; preds = %13, %9
%22 = tail call dereferenceable_or_null(32) i8* @malloc(i32 32)
%23 = bitcast i8* %22 to i8**
%24 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %30
26: ; preds = %33, %30, %21
%27 = phi i32 [ 0, %21 ], [ 1, %30 ], [ 2, %33 ]
%28 = call i32 @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.1, i64 0, i64 0), i32 %1, i8* %0, i32 %27)
%29 = call i32 @exit(i32 -1)
unreachable
30: ; preds = %21
store i8* %24, i8** %23
%31 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%32 = icmp eq i8* %31, null
br i1 %32, label %26, label %33
33: ; preds = %30
%34 = getelementptr inbounds i8*, i8** %23, i64 1
store i8* %31, i8** %34
%35 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%36 = icmp eq i8* %35, null
br i1 %36, label %26, label %37
37: ; preds = %33
%38 = getelementptr inbounds i8*, i8** %23, i64 2
store i8* %35, i8** %38
%39 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%40 = icmp eq i8* %39, null
br i1 %40, label %43, label %41
41: ; preds = %37
%42 = getelementptr inbounds i8*, i8** %23, i64 3
store i8* %39, i8** %42
br label %43
43: ; preds = %41, %37, %2
%44 = phi i8** [ null, %2 ], [ %23, %37 ], [ %23, %41 ]
ret i8** %44
}