#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 */
char *duplicate_string(char const *);
int find_unquoted_character(char *, char);
int /*<<< orphan*/ free(char *);
char **malloc(int);
char **realloc(char **, int);
int strcspn(char *, char *);
int strspn(char *, char *);
char *trim_string(char *);
char **extract_components_from_line(const char *line) {
  char *copy = duplicate_string(line);
  int pos = find_unquoted_character(copy, ';');
  if (pos >= 0)
    copy[pos] = 0;
  char *current = copy + strspn(copy, " \t");
  if ((!*current)) {
    free(copy);
    return NULL;
  }
  pos = strcspn(current, " \t");
  char **result;
  if (!current[pos]) {
    result = malloc(sizeof(char *) * 2);
    *result = duplicate_string(current);
    result[1] = NULL;
    return result;
  }
  result = malloc(sizeof(char *));
  current[pos] = 0;
  *result = duplicate_string(current);
  current += pos + 1;
  unsigned components = 1;
  char *component;
  while (pos >= 0) {
    pos = find_unquoted_character(current, ',');
    if (pos >= 0)
      current[pos] = 0;
    component = trim_string(current);
    if (pos >= 0)
      current += pos + 1;
    if (*component) {
      result = realloc(result, sizeof(char *) * (components + 1));
      result[components++] = component;
    } else
      free(component);
  }
  result = realloc(result, sizeof(char *) * (components + 1));
  result[components] = NULL;
  return result;
}


x86 assembly (clang, -O0):
<extract_components_from_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <duplicate_string@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x3b,%esi
call   1080 <find_unquoted_character@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     11c0 <extract_components_from_line+0x40>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe2d(%rip),%rsi
call   1060 <strspn@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
jne    120b <extract_components_from_line+0x8b>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1394 <extract_components_from_line+0x214>
mov    -0x28(%rbp),%rdi
lea    0xdea(%rip),%rsi
call   1070 <strcspn@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
jne    126a <extract_components_from_line+0xea>
mov    $0x10,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <duplicate_string@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1394 <extract_components_from_line+0x214>
mov    $0x8,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
call   1040 <duplicate_string@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x34(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1362 <extract_components_from_line+0x1e2>
mov    -0x28(%rbp),%rdi
mov    $0x2c,%esi
call   1080 <find_unquoted_character@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     12e3 <extract_components_from_line+0x163>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
call   1050 <trim_string@plt>
mov    %rax,-0x40(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     130e <extract_components_from_line+0x18e>
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x40(%rbp),%rax
cmpb   $0x0,(%rax)
je     1354 <extract_components_from_line+0x1d4>
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,%eax
shl    $0x3,%rax
mov    %eax,%esi
call   10a0 <realloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x40(%rbp),%rdx
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x34(%rbp)
mov    %ecx,%ecx
mov    %rdx,(%rax,%rcx,8)
jmp    135d <extract_components_from_line+0x1dd>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
jmp    12b2 <extract_components_from_line+0x132>
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,%eax
shl    $0x3,%rax
mov    %eax,%esi
call   10a0 <realloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
movq   $0x0,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_components_from_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
call   1040 <duplicate_string@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x3b,%esi
call   1080 <find_unquoted_character@plt>
test   %eax,%eax
js     11aa <extract_components_from_line+0x2a>
mov    %eax,%eax
movb   $0x0,(%rbx,%rax,1)
lea    0xe4f(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strspn@plt>
cltq
cmpb   $0x0,(%rbx,%rax,1)
je     1294 <extract_components_from_line+0x114>
add    %rax,%rbx
lea    0xe31(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcspn@plt>
movslq %eax,%rbp
cmpb   $0x0,(%rbx,%rbp,1)
je     12a1 <extract_components_from_line+0x121>
mov    %eax,%r15d
mov    $0x8,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
movb   $0x0,(%rbx,%rbp,1)
mov    %rbx,%rdi
call   1040 <duplicate_string@plt>
mov    %r14,(%rsp)
mov    %rax,(%r14)
test   %ebp,%ebp
js     12c3 <extract_components_from_line+0x143>
mov    %r15d,%eax
add    %rax,%rbx
add    $0x1,%rbx
mov    $0x1,%ebp
jmp    1234 <extract_components_from_line+0xb4>
mov    %r12,%rdi
call   1030 <free@plt>
add    %r13,%rbx
test   %r15d,%r15d
js     12c8 <extract_components_from_line+0x148>
mov    %rbx,%rdi
mov    $0x2c,%esi
call   1080 <find_unquoted_character@plt>
mov    %eax,%r15d
test   %eax,%eax
js     124f <extract_components_from_line+0xcf>
mov    %r15d,%eax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
call   1050 <trim_string@plt>
mov    %rax,%r12
lea    0x1(%r15),%r13d
test   %r15d,%r15d
mov    $0x0,%eax
cmovs  %eax,%r13d
cmpb   $0x0,(%r12)
je     1220 <extract_components_from_line+0xa0>
lea    0x1(%rbp),%r14d
lea    0x8(,%rbp,8),%esi
mov    (%rsp),%rdi
call   10a0 <realloc@plt>
mov    %ebp,%ecx
mov    %rax,(%rsp)
mov    %r12,(%rax,%rcx,8)
mov    %r14d,%ebp
jmp    1228 <extract_components_from_line+0xa8>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
jmp    12e5 <extract_components_from_line+0x165>
mov    $0x10,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <duplicate_string@plt>
mov    %rax,(%r14)
movq   $0x0,0x8(%r14)
jmp    12e5 <extract_components_from_line+0x165>
mov    $0x1,%ebp
lea    0x8(,%rbp,8),%esi
mov    (%rsp),%rdi
call   10a0 <realloc@plt>
mov    %rax,%r14
mov    %ebp,%eax
movq   $0x0,(%r14,%rax,8)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c" \09\00"
define i8** @extract_components_from_line(i8* %0) {
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %3
%10 = load i8*, i8** %3
%11 = call i8* @duplicate_string(i8* %10)
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = call i32 @find_unquoted_character(i8* %12, i8 signext 59)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %1
%17 = load i8*, i8** %4
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
store i8 0, i8* %20
br label %21
21: ; preds = %16, %1
%22 = load i8*, i8** %4
%23 = load i8*, i8** %4
%24 = call i32 @strspn(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
store i8* %26, i8** %6
%27 = load i8*, i8** %6
%28 = load i8, i8* %27
%29 = icmp ne i8 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %21
%31 = load i8*, i8** %4
%32 = call i32 @free(i8* %31)
store i8** null, i8*** %2
br label %123
33: ; preds = %21
%34 = load i8*, i8** %6
%35 = call i32 @strcspn(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %35, i32* %5
%36 = load i8*, i8** %6
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i8, i8* %39
%41 = icmp ne i8 %40, 0
br i1 %41, label %50, label %42
42: ; preds = %33
%43 = call i8** @malloc(i32 16)
store i8** %43, i8*** %7
%44 = load i8*, i8** %6
%45 = call i8* @duplicate_string(i8* %44)
%46 = load i8**, i8*** %7
store i8* %45, i8** %46
%47 = load i8**, i8*** %7
%48 = getelementptr inbounds i8*, i8** %47, i64 1
store i8* null, i8** %48
%49 = load i8**, i8*** %7
store i8** %49, i8*** %2
br label %123
50: ; preds = %33
%51 = call i8** @malloc(i32 8)
store i8** %51, i8*** %7
%52 = load i8*, i8** %6
%53 = load i32, i32* %5
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
store i8 0, i8* %55
%56 = load i8*, i8** %6
%57 = call i8* @duplicate_string(i8* %56)
%58 = load i8**, i8*** %7
store i8* %57, i8** %58
%59 = load i32, i32* %5
%60 = add nsw i32 %59, 1
%61 = load i8*, i8** %6
%62 = sext i32 %60 to i64
%63 = getelementptr inbounds i8, i8* %61, i64 %62
store i8* %63, i8** %6
store i32 1, i32* %8
br label %64
64: ; preds = %109, %50
%65 = load i32, i32* %5
%66 = icmp sge i32 %65, 0
br i1 %66, label %67, label %110
67: ; preds = %64
%68 = load i8*, i8** %6
%69 = call i32 @find_unquoted_character(i8* %68, i8 signext 44)
store i32 %69, i32* %5
%70 = load i32, i32* %5
%71 = icmp sge i32 %70, 0
br i1 %71, label %72, label %77
72: ; preds = %67
%73 = load i8*, i8** %6
%74 = load i32, i32* %5
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %73, i64 %75
store i8 0, i8* %76
br label %77
77: ; preds = %72, %67
%78 = load i8*, i8** %6
%79 = call i8* @trim_string(i8* %78)
store i8* %79, i8** %9
%80 = load i32, i32* %5
%81 = icmp sge i32 %80, 0
br i1 %81, label %82, label %88
82: ; preds = %77
%83 = load i32, i32* %5
%84 = add nsw i32 %83, 1
%85 = load i8*, i8** %6
%86 = sext i32 %84 to i64
%87 = getelementptr inbounds i8, i8* %85, i64 %86
store i8* %87, i8** %6
br label %88
88: ; preds = %82, %77
%89 = load i8*, i8** %9
%90 = load i8, i8* %89
%91 = icmp ne i8 %90, 0
br i1 %91, label %92, label %106
92: ; preds = %88
%93 = load i8**, i8*** %7
%94 = load i32, i32* %8
%95 = add i32 %94, 1
%96 = zext i32 %95 to i64
%97 = mul i64 8, %96
%98 = trunc i64 %97 to i32
%99 = call i8** @realloc(i8** %93, i32 %98)
store i8** %99, i8*** %7
%100 = load i8*, i8** %9
%101 = load i8**, i8*** %7
%102 = load i32, i32* %8
%103 = add i32 %102, 1
store i32 %103, i32* %8
%104 = zext i32 %102 to i64
%105 = getelementptr inbounds i8*, i8** %101, i64 %104
store i8* %100, i8** %105
br label %109
106: ; preds = %88
%107 = load i8*, i8** %9
%108 = call i32 @free(i8* %107)
br label %109
109: ; preds = %106, %92
br label %64
110: ; preds = %64
%111 = load i8**, i8*** %7
%112 = load i32, i32* %8
%113 = add i32 %112, 1
%114 = zext i32 %113 to i64
%115 = mul i64 8, %114
%116 = trunc i64 %115 to i32
%117 = call i8** @realloc(i8** %111, i32 %116)
store i8** %117, i8*** %7
%118 = load i8**, i8*** %7
%119 = load i32, i32* %8
%120 = zext i32 %119 to i64
%121 = getelementptr inbounds i8*, i8** %118, i64 %120
store i8* null, i8** %121
%122 = load i8**, i8*** %7
store i8** %122, i8*** %2
br label %123
123: ; preds = %110, %42, %30
%124 = load i8**, i8*** %2
ret i8** %124
}

LLVM IR (-O2):
@.str = [3 x i8] c" \09\00"
define i8** @extract_components_from_line(i8* %0) {
%2 = tail call i8* @duplicate_string(i8* %0)
%3 = tail call i32 @find_unquoted_character(i8* %2, i8 signext 59)
%4 = icmp sgt i32 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = zext i32 %3 to i64
%7 = getelementptr inbounds i8, i8* %2, i64 %6
store i8 0, i8* %7
br label %8
8: ; preds = %5, %1
%9 = tail call i32 @strspn(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %2, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = tail call i32 @free(i8* %2)
br label %70
16: ; preds = %8
%17 = tail call i32 @strcspn(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %11, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = tail call i8** @malloc(i32 16)
%24 = tail call i8* @duplicate_string(i8* %11)
store i8* %24, i8** %23
%25 = getelementptr inbounds i8*, i8** %23, i64 1
store i8* null, i8** %25
br label %70
26: ; preds = %16
%27 = tail call i8** @malloc(i32 8)
store i8 0, i8* %19
%28 = tail call i8* @duplicate_string(i8* %11)
store i8* %28, i8** %27
%29 = icmp sgt i32 %17, -1
br i1 %29, label %30, label %62
30: ; preds = %26
%31 = add nuw nsw i32 %17, 1
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %11, i64 %32
br label %34
34: ; preds = %30, %59
%35 = phi i32 [ %61, %59 ], [ 1, %30 ]
%36 = phi i8** [ %60, %59 ], [ %27, %30 ]
%37 = phi i8* [ %48, %59 ], [ %33, %30 ]
%38 = tail call i32 @find_unquoted_character(i8* %37, i8 signext 44)
%39 = icmp sgt i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %34
%41 = zext i32 %38 to i64
%42 = getelementptr inbounds i8, i8* %37, i64 %41
store i8 0, i8* %42
br label %43
43: ; preds = %40, %34
%44 = tail call i8* @trim_string(i8* %37)
%45 = add nsw i32 %38, 1
%46 = select i1 %39, i32 %45, i32 0
%47 = zext i32 %46 to i64
%48 = getelementptr i8, i8* %37, i64 %47
%49 = load i8, i8* %44
%50 = icmp eq i8 %49, 0
br i1 %50, label %57, label %51
51: ; preds = %43
%52 = add i32 %35, 1
%53 = shl i32 %52, 3
%54 = tail call i8** @realloc(i8** %36, i32 %53)
%55 = zext i32 %35 to i64
%56 = getelementptr inbounds i8*, i8** %54, i64 %55
store i8* %44, i8** %56
br label %59
57: ; preds = %43
%58 = tail call i32 @free(i8* %44)
br label %59
59: ; preds = %57, %51
%60 = phi i8** [ %54, %51 ], [ %36, %57 ]
%61 = phi i32 [ %52, %51 ], [ %35, %57 ]
br i1 %39, label %34, label %62
62: ; preds = %59, %26
%63 = phi i8** [ %27, %26 ], [ %60, %59 ]
%64 = phi i32 [ 1, %26 ], [ %61, %59 ]
%65 = shl i32 %64, 3
%66 = add i32 %65, 8
%67 = tail call i8** @realloc(i8** %63, i32 %66)
%68 = zext i32 %64 to i64
%69 = getelementptr inbounds i8*, i8** %67, i64 %68
store i8* null, i8** %69
br label %70
70: ; preds = %22, %62, %14
%71 = phi i8** [ null, %14 ], [ %67, %62 ], [ %23, %22 ]
ret i8** %71
}