#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 */
struct ll_node {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ csv_free(struct ll_node *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ *ll_append(struct ll_node **, struct ll_node *);
int /*<<< orphan*/ *ll_csv_append(struct ll_node **, char *, int);
int /*<<< orphan*/ ll_deep_free(struct ll_node **,
                                int /*<<< orphan*/ (*)(char *));
char *read_file(char *);
struct ll_node *read_csv(char *path) {
  char *contents = read_file(path);
  if (!contents) {
    return NULL;
  }
  struct ll_node *csv_data = NULL;
  int ptr;
  int current_word = 0;
  for (ptr = 0; contents[ptr] != '\0'; ptr++) {
    struct ll_node *row = NULL;
    for (;; ptr++) {
      if (contents[ptr] == '\n') {
        contents[ptr] = '\0';
        if (ll_csv_append(&row, contents, current_word) == NULL) {
          free(contents);
          ll_deep_free(&row, free);
          csv_free(csv_data);
          return NULL;
        }
        current_word = ptr + 1;
        break;
      } else if (contents[ptr] == ',') {
        contents[ptr] = '\0';
        if (ll_csv_append(&row, contents, current_word) == NULL) {
          free(contents);
          ll_deep_free(&row, free);
          csv_free(csv_data);
          return NULL;
        }
        current_word = ptr + 1;
      }
    }
    if (ll_append(&csv_data, row) == NULL) {
      free(contents);
      ll_deep_free(&row, free);
      csv_free(csv_data);
      return NULL;
    }
  }
  free(contents);
  return csv_data;
}


x86 assembly (clang, -O0):
<read_csv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <read_file@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1181 <read_csv+0x31>
movq   $0x0,-0x8(%rbp)
jmp    1321 <read_csv+0x1d1>
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1310 <read_csv+0x1c0>
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    122c <read_csv+0xdc>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%edx
lea    -0x30(%rbp),%rdi
call   1070 <ll_csv_append@plt>
cmp    $0x0,%rax
jne    121e <read_csv+0xce>
mov    -0x18(%rbp),%rdi
call   1080 <free@plt>
lea    -0x30(%rbp),%rdi
mov    0x2dd5(%rip),%rsi
call   1050 <ll_deep_free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <csv_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1321 <read_csv+0x1d1>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    12b7 <read_csv+0x167>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2c,%eax
jne    129f <read_csv+0x14f>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%edx
lea    -0x30(%rbp),%rdi
call   1070 <ll_csv_append@plt>
cmp    $0x0,%rax
jne    1296 <read_csv+0x146>
mov    -0x18(%rbp),%rdi
call   1080 <free@plt>
lea    -0x30(%rbp),%rdi
mov    0x2d5d(%rip),%rsi
call   1050 <ll_deep_free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <csv_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1321 <read_csv+0x1d1>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    12a4 <read_csv+0x154>
jmp    12a9 <read_csv+0x159>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b4 <read_csv+0x64>
mov    -0x30(%rbp),%rsi
lea    -0x20(%rbp),%rdi
call   1060 <ll_append@plt>
cmp    $0x0,%rax
jne    12fd <read_csv+0x1ad>
mov    -0x18(%rbp),%rdi
call   1080 <free@plt>
lea    -0x30(%rbp),%rdi
mov    0x2cf6(%rip),%rsi
call   1050 <ll_deep_free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <csv_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1321 <read_csv+0x1d1>
jmp    1302 <read_csv+0x1b2>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1197 <read_csv+0x47>
mov    -0x18(%rbp),%rdi
call   1080 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_csv>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
call   1040 <read_file@plt>
test   %rax,%rax
je     1236 <read_csv+0xe6>
mov    %rax,%r12
movq   $0x0,0x10(%rsp)
cmpb   $0x0,(%rax)
je     1204 <read_csv+0xb4>
xor    %edx,%edx
lea    0x8(%rsp),%r14
lea    0x10(%rsp),%r15
nopw   0x0(%rax,%rax,1)
movq   $0x0,0x8(%rsp)
movslq %edx,%rbx
nopl   0x0(%rax)
add    $0x1,%rbx
movzbl -0x1(%r12,%rbx,1),%eax
cmp    $0xa,%al
je     11d0 <read_csv+0x80>
cmp    $0x2c,%al
jne    11a0 <read_csv+0x50>
movb   $0x0,-0x1(%r12,%rbx,1)
mov    %r14,%rdi
mov    %r12,%rsi
call   1070 <ll_csv_append@plt>
test   %rax,%rax
je     1213 <read_csv+0xc3>
mov    %ebx,%edx
jmp    11a0 <read_csv+0x50>
nopl   0x0(%rax)
movb   $0x0,-0x1(%r12,%rbx,1)
mov    %r14,%rdi
mov    %r12,%rsi
call   1070 <ll_csv_append@plt>
test   %rax,%rax
je     1213 <read_csv+0xc3>
mov    0x8(%rsp),%rsi
mov    %r15,%rdi
call   1060 <ll_append@plt>
test   %rax,%rax
je     1213 <read_csv+0xc3>
movslq %ebx,%rax
cmpb   $0x0,(%r12,%rax,1)
mov    %ebx,%edx
jne    1190 <read_csv+0x40>
mov    %r12,%rdi
call   1080 <free@plt>
mov    0x10(%rsp),%rax
jmp    1238 <read_csv+0xe8>
mov    %r12,%rdi
call   1080 <free@plt>
mov    0x2db6(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1050 <ll_deep_free@plt>
mov    0x10(%rsp),%rdi
call   1030 <csv_free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.ll_node = type { i32 }
define %struct.ll_node* @read_csv(i8* %0) {
%2 = alloca %struct.ll_node*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.ll_node*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.ll_node*
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i8* @read_file(i8* %9)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %1
store %struct.ll_node* null, %struct.ll_node** %2
br label %99
14: ; preds = %1
store %struct.ll_node* null, %struct.ll_node** %5
store i32 0, i32* %7
store i32 0, i32* %6
br label %15
15: ; preds = %92, %14
%16 = load i8*, i8** %4
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %95
23: ; preds = %15
store %struct.ll_node* null, %struct.ll_node** %8
br label %24
24: ; preds = %78, %23
%25 = load i8*, i8** %4
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 10
br i1 %31, label %32, label %50
32: ; preds = %24
%33 = load i8*, i8** %4
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 0, i8* %36
%37 = load i8*, i8** %4
%38 = load i32, i32* %7
%39 = call i32* @ll_csv_append(%struct.ll_node** %8, i8* %37, i32 %38)
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %47
41: ; preds = %32
%42 = load i8*, i8** %4
%43 = call i32 @free(i8* %42)
%44 = call i32 @ll_deep_free(%struct.ll_node** %8, i32 (i8*)* @free)
%45 = load %struct.ll_node*, %struct.ll_node** %5
%46 = call i32 @csv_free(%struct.ll_node* %45)
store %struct.ll_node* null, %struct.ll_node** %2
br label %99
47: ; preds = %32
%48 = load i32, i32* %6
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
br label %81
50: ; preds = %24
%51 = load i8*, i8** %4
%52 = load i32, i32* %6
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 44
br i1 %57, label %58, label %76
58: ; preds = %50
%59 = load i8*, i8** %4
%60 = load i32, i32* %6
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
store i8 0, i8* %62
%63 = load i8*, i8** %4
%64 = load i32, i32* %7
%65 = call i32* @ll_csv_append(%struct.ll_node** %8, i8* %63, i32 %64)
%66 = icmp eq i32* %65, null
br i1 %66, label %67, label %73
67: ; preds = %58
%68 = load i8*, i8** %4
%69 = call i32 @free(i8* %68)
%70 = call i32 @ll_deep_free(%struct.ll_node** %8, i32 (i8*)* @free)
%71 = load %struct.ll_node*, %struct.ll_node** %5
%72 = call i32 @csv_free(%struct.ll_node* %71)
store %struct.ll_node* null, %struct.ll_node** %2
br label %99
73: ; preds = %58
%74 = load i32, i32* %6
%75 = add nsw i32 %74, 1
store i32 %75, i32* %7
br label %76
76: ; preds = %73, %50
br label %77
77: ; preds = %76
br label %78
78: ; preds = %77
%79 = load i32, i32* %6
%80 = add nsw i32 %79, 1
store i32 %80, i32* %6
br label %24
81: ; preds = %47
%82 = load %struct.ll_node*, %struct.ll_node** %8
%83 = call i32* @ll_append(%struct.ll_node** %5, %struct.ll_node* %82)
%84 = icmp eq i32* %83, null
br i1 %84, label %85, label %91
85: ; preds = %81
%86 = load i8*, i8** %4
%87 = call i32 @free(i8* %86)
%88 = call i32 @ll_deep_free(%struct.ll_node** %8, i32 (i8*)* @free)
%89 = load %struct.ll_node*, %struct.ll_node** %5
%90 = call i32 @csv_free(%struct.ll_node* %89)
store %struct.ll_node* null, %struct.ll_node** %2
br label %99
91: ; preds = %81
br label %92
92: ; preds = %91
%93 = load i32, i32* %6
%94 = add nsw i32 %93, 1
store i32 %94, i32* %6
br label %15
95: ; preds = %15
%96 = load i8*, i8** %4
%97 = call i32 @free(i8* %96)
%98 = load %struct.ll_node*, %struct.ll_node** %5
store %struct.ll_node* %98, %struct.ll_node** %2
br label %99
99: ; preds = %95, %85, %67, %41, %13
%100 = load %struct.ll_node*, %struct.ll_node** %2
ret %struct.ll_node* %100
}

LLVM IR (-O2):
%struct.ll_node = type { i32 }
define %struct.ll_node* @read_csv(i8* %0) {
%2 = alloca %struct.ll_node*
%3 = alloca %struct.ll_node*
%4 = tail call i8* @read_file(i8* %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %56, label %6
6: ; preds = %1
%7 = bitcast %struct.ll_node** %2 to i8*
store %struct.ll_node* null, %struct.ll_node** %2
%8 = load i8, i8* %4
%9 = icmp eq i8 %8, 0
br i1 %9, label %51, label %10
10: ; preds = %6
%11 = bitcast %struct.ll_node** %3 to i8*
br label %12
12: ; preds = %10, %45
%13 = phi i32 [ 0, %10 ], [ %46, %45 ]
store %struct.ll_node* null, %struct.ll_node** %3
%14 = sext i32 %13 to i64
br label %15
15: ; preds = %37, %12
%16 = phi i64 [ %38, %37 ], [ %14, %12 ]
%17 = phi i32 [ %39, %37 ], [ %13, %12 ]
br label %18
18: ; preds = %15, %22
%19 = phi i64 [ %23, %22 ], [ %16, %15 ]
%20 = getelementptr inbounds i8, i8* %4, i64 %19
%21 = load i8, i8* %20
switch i8 %21, label %22 [
i8 10, label %24
i8 44, label %33
]
22: ; preds = %18
%23 = add i64 %19, 1
br label %18
24: ; preds = %18
%25 = getelementptr inbounds i8, i8* %4, i64 %19
%26 = trunc i64 %19 to i32
store i8 0, i8* %25
%27 = call i32* @ll_csv_append(%struct.ll_node** %3, i8* %4, i32 %17)
%28 = icmp eq i32* %27, null
br i1 %28, label %40, label %29
29: ; preds = %24
%30 = load %struct.ll_node*, %struct.ll_node** %3
%31 = call i32* @ll_append(%struct.ll_node** %2, %struct.ll_node* %30)
%32 = icmp eq i32* %31, null
br i1 %32, label %40, label %45
33: ; preds = %18
%34 = getelementptr inbounds i8, i8* %4, i64 %19
store i8 0, i8* %34
%35 = call i32* @ll_csv_append(%struct.ll_node** %3, i8* %4, i32 %17)
%36 = icmp eq i32* %35, null
br i1 %36, label %40, label %37
37: ; preds = %33
%38 = add i64 %19, 1
%39 = trunc i64 %38 to i32
br label %15
40: ; preds = %29, %24, %33
%41 = call i32 @free(i8* %4)
%42 = call i32 @ll_deep_free(%struct.ll_node** %3, i32 (i8*)* @free)
%43 = load %struct.ll_node*, %struct.ll_node** %2
%44 = call i32 @csv_free(%struct.ll_node* %43)
br label %54
45: ; preds = %29
%46 = add nsw i32 %26, 1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %4, i64 %47
%49 = load i8, i8* %48
%50 = icmp eq i8 %49, 0
br i1 %50, label %51, label %12
51: ; preds = %45, %6
%52 = call i32 @free(i8* %4)
%53 = load %struct.ll_node*, %struct.ll_node** %2
br label %54
54: ; preds = %40, %51
%55 = phi %struct.ll_node* [ %53, %51 ], [ null, %40 ]
br label %56
56: ; preds = %1, %54
%57 = phi %struct.ll_node* [ %55, %54 ], [ null, %1 ]
ret %struct.ll_node* %57
}