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

/* Variables and functions */
struct path_list *alloc_entry();
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ free_entry(struct path_list *);
scalar_t__ insert_entry(struct path_list *, char *);
int /*<<< orphan*/ perror(char *);
char *strdup(char const *);
char *strtok(char *, char *);
struct path_list *split_path(const char *list, char sep) {
  struct path_list *pl;
  char *p, *q;
  char ss[2];
  ss[0] = sep;
  ss[1] = '\0';
  pl = alloc_entry();
  if (!pl)
    return NULL;
  p = strdup(list);
  if (!p) {
    perror("strdup");
    free_entry(pl);
    return NULL;
  }
  q = strtok(p, ss);
  while (q) {
    if (insert_entry(pl, q)) {
      free(p);
      free_entry(pl);
      return NULL;
    }
    q = strtok(NULL, ss);
  }
  free(p);
  return pl;
}


x86 assembly (clang, -O0):
<split_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
mov    %al,-0x32(%rbp)
movb   $0x0,-0x31(%rbp)
mov    $0x0,%al
call   1040 <alloc_entry@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11af <split_path+0x3f>
movq   $0x0,-0x8(%rbp)
jmp    1262 <split_path+0xf2>
mov    -0x10(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11e9 <split_path+0x79>
lea    0xe32(%rip),%rdi
call   1070 <perror@plt>
mov    -0x20(%rbp),%rdi
call   1060 <free_entry@plt>
movq   $0x0,-0x8(%rbp)
jmp    1262 <split_path+0xf2>
mov    -0x28(%rbp),%rdi
lea    -0x32(%rbp),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1251 <split_path+0xe1>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <insert_entry@plt>
cmp    $0x0,%rax
je     123b <split_path+0xcb>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1060 <free_entry@plt>
movq   $0x0,-0x8(%rbp)
jmp    1262 <split_path+0xf2>
lea    -0x32(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1080 <strtok@plt>
mov    %rax,-0x30(%rbp)
jmp    11fa <split_path+0x8a>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_path>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    %sil,0xe(%rsp)
movb   $0x0,0xf(%rsp)
xor    %eax,%eax
call   1040 <alloc_entry@plt>
test   %rax,%rax
je     11f9 <split_path+0x89>
mov    %rax,%rbx
mov    %r14,%rdi
call   1090 <strdup@plt>
test   %rax,%rax
je     1208 <split_path+0x98>
mov    %rax,%r14
lea    0xe(%rsp),%rsi
mov    %rax,%rdi
call   1080 <strtok@plt>
test   %rax,%rax
je     11df <split_path+0x6f>
lea    0xe(%rsp),%r15
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <insert_entry@plt>
test   %rax,%rax
jne    11e9 <split_path+0x79>
xor    %edi,%edi
mov    %r15,%rsi
call   1080 <strtok@plt>
test   %rax,%rax
jne    11c0 <split_path+0x50>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    11fb <split_path+0x8b>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1060 <free_entry@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdf1(%rip),%rdi
call   1070 <perror@plt>
jmp    11f1 <split_path+0x81>

LLVM IR (-O0):
%struct.path_list = type { i32 }
@.str = [7 x i8] c"strdup\00"
define %struct.path_list* @split_path(i8* %0, i8 signext %1) {
%3 = alloca %struct.path_list*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca %struct.path_list*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [2 x i8]
store i8* %0, i8** %4
store i8 %1, i8* %5
%10 = load i8, i8* %5
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
store i8 %10, i8* %11
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 1
store i8 0, i8* %12
%13 = call %struct.path_list* (...) @alloc_entry()
store %struct.path_list* %13, %struct.path_list** %6
%14 = load %struct.path_list*, %struct.path_list** %6
%15 = icmp ne %struct.path_list* %14, null
br i1 %15, label %17, label %16
16: ; preds = %2
store %struct.path_list* null, %struct.path_list** %3
br label %50
17: ; preds = %2
%18 = load i8*, i8** %4
%19 = call i8* @strdup(i8* %18)
store i8* %19, i8** %7
%20 = load i8*, i8** %7
%21 = icmp ne i8* %20, null
br i1 %21, label %26, label %22
22: ; preds = %17
%23 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%24 = load %struct.path_list*, %struct.path_list** %6
%25 = call i32 @free_entry(%struct.path_list* %24)
store %struct.path_list* null, %struct.path_list** %3
br label %50
26: ; preds = %17
%27 = load i8*, i8** %7
%28 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%29 = call i8* @strtok(i8* %27, i8* %28)
store i8* %29, i8** %8
br label %30
30: ; preds = %43, %26
%31 = load i8*, i8** %8
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %46
33: ; preds = %30
%34 = load %struct.path_list*, %struct.path_list** %6
%35 = load i8*, i8** %8
%36 = call i64 @insert_entry(%struct.path_list* %34, i8* %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %33
%39 = load i8*, i8** %7
%40 = call i32 @free(i8* %39)
%41 = load %struct.path_list*, %struct.path_list** %6
%42 = call i32 @free_entry(%struct.path_list* %41)
store %struct.path_list* null, %struct.path_list** %3
br label %50
43: ; preds = %33
%44 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%45 = call i8* @strtok(i8* null, i8* %44)
store i8* %45, i8** %8
br label %30
46: ; preds = %30
%47 = load i8*, i8** %7
%48 = call i32 @free(i8* %47)
%49 = load %struct.path_list*, %struct.path_list** %6
store %struct.path_list* %49, %struct.path_list** %3
br label %50
50: ; preds = %46, %38, %22, %16
%51 = load %struct.path_list*, %struct.path_list** %3
ret %struct.path_list* %51
}

LLVM IR (-O2):
%struct.path_list = type { i32 }
@.str = [7 x i8] c"strdup\00"
define %struct.path_list* @split_path(i8* nocapture %0, i8 signext %1) {
%3 = alloca [2 x i8]
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
store i8 %1, i8* %4
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
store i8 0, i8* %5
%6 = tail call %struct.path_list* (...) @alloc_entry()
%7 = icmp eq %struct.path_list* %6, null
br i1 %7, label %29, label %8
8: ; preds = %2
%9 = tail call i8* @strdup(i8* %0)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @free_entry(%struct.path_list* %6)
br label %29
14: ; preds = %8
%15 = call i8* @strtok(i8* %9, i8* %4)
%16 = icmp eq i8* %15, null
br i1 %16, label %27, label %17
17: ; preds = %14, %24
%18 = phi i8* [ %25, %24 ], [ %15, %14 ]
%19 = tail call i64 @insert_entry(%struct.path_list* %6, i8* %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %17
%22 = tail call i32 @free(i8* %9)
%23 = tail call i32 @free_entry(%struct.path_list* %6)
br label %29
24: ; preds = %17
%25 = call i8* @strtok(i8* null, i8* %4)
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %17
27: ; preds = %24, %14
%28 = tail call i32 @free(i8* %9)
br label %29
29: ; preds = %2, %27, %21, %11
%30 = phi %struct.path_list* [ null, %21 ], [ %6, %27 ], [ null, %11 ], [ null, %2 ]
ret %struct.path_list* %30
}