#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 text_list {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *strdup(char const *);
char *strtok(char *, char *);
int /*<<< orphan*/ text_list_append(struct text_list *, char *);
struct text_list *text_list_create();
struct text_list *text_list_load_str(const char *inp_str) {
  if (!inp_str) {
    return NULL;
  }
  struct text_list *t = text_list_create();
  char *pch = NULL;
  char *tmp_str = strdup(inp_str);
  pch = strtok(tmp_str, ",");
  while (pch != NULL) {
    text_list_append(t, pch);
    pch = strtok(NULL, ",");
  }
  free(tmp_str);
  return t;
}


x86 assembly (clang, -O0):
<text_list_load_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1174 <text_list_load_str+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11ea <text_list_load_str+0x9a>
mov    $0x0,%al
call   1070 <text_list_create@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d9 <text_list_load_str+0x89>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <text_list_append@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe35(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    11a8 <text_list_load_str+0x58>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<text_list_load_str>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     11b4 <text_list_load_str+0x64>
mov    %rdi,%r14
xor    %eax,%eax
call   1070 <text_list_create@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1060 <strdup@plt>
mov    %rax,%r14
lea    0xe87(%rip),%rsi
mov    %rax,%rdi
call   1050 <strtok@plt>
test   %rax,%rax
je     11aa <text_list_load_str+0x5a>
lea    0xe73(%rip),%r15
nopl   (%rax)
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <text_list_append@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
jne    1190 <text_list_load_str+0x40>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    11b6 <text_list_load_str+0x66>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.text_list = type { i32 }
@.str = [2 x i8] c",\00"
define %struct.text_list* @text_list_load_str(i8* %0) {
%2 = alloca %struct.text_list*
%3 = alloca i8*
%4 = alloca %struct.text_list*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
store %struct.text_list* null, %struct.text_list** %2
br label %28
10: ; preds = %1
%11 = call %struct.text_list* (...) @text_list_create()
store %struct.text_list* %11, %struct.text_list** %4
store i8* null, i8** %5
%12 = load i8*, i8** %3
%13 = call i8* @strdup(i8* %12)
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = call i8* @strtok(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %5
br label %16
16: ; preds = %19, %10
%17 = load i8*, i8** %5
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load %struct.text_list*, %struct.text_list** %4
%21 = load i8*, i8** %5
%22 = call i32 @text_list_append(%struct.text_list* %20, i8* %21)
%23 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %23, i8** %5
br label %16
24: ; preds = %16
%25 = load i8*, i8** %6
%26 = call i32 @free(i8* %25)
%27 = load %struct.text_list*, %struct.text_list** %4
store %struct.text_list* %27, %struct.text_list** %2
br label %28
28: ; preds = %24, %9
%29 = load %struct.text_list*, %struct.text_list** %2
ret %struct.text_list* %29
}

LLVM IR (-O2):
%struct.text_list = type { i32 }
@.str = [2 x i8] c",\00"
define %struct.text_list* @text_list_load_str(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %15, label %3
3: ; preds = %1
%4 = tail call %struct.text_list* (...) @text_list_create()
%5 = tail call i8* @strdup(i8* %0)
%6 = tail call i8* @strtok(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %13, label %8
8: ; preds = %3, %8
%9 = phi i8* [ %11, %8 ], [ %6, %3 ]
%10 = tail call i32 @text_list_append(%struct.text_list* %4, i8* %9)
%11 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %8
13: ; preds = %8, %3
%14 = tail call i32 @free(i8* %5)
br label %15
15: ; preds = %1, %13
%16 = phi %struct.text_list* [ %4, %13 ], [ null, %1 ]
ret %struct.text_list* %16
}