#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 add_entry(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ perror(char *);
char *strdup(char const *);
char *strtok(char *, char *);
int add_list(const char *list, char sep) {
  char *p = strdup(list);
  char *q;
  char seperator[2];
  seperator[0] = sep;
  seperator[1] = '\0';
  if (!p) {
    perror("strdup");
    return -1;
  }
  q = strtok(p, seperator);
  while (q) {
    int ret = add_entry(q);
    if (ret)
      return ret;
    q = strtok(NULL, seperator);
  }
  free(p);
  return 0;
}


x86 assembly (clang, -O0):
<add_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x11(%rbp),%al
mov    %al,-0x2a(%rbp)
movb   $0x0,-0x29(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119c <add_list+0x4c>
lea    0xe75(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ff <add_list+0xaf>
mov    -0x20(%rbp),%rdi
lea    -0x2a(%rbp),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11ef <add_list+0x9f>
mov    -0x28(%rbp),%rdi
call   1040 <add_entry@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     11d9 <add_list+0x89>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ff <add_list+0xaf>
lea    -0x2a(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1060 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    11ad <add_list+0x5d>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_list>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
call   1070 <strdup@plt>
mov    %bl,0x6(%rsp)
movb   $0x0,0x7(%rsp)
test   %rax,%rax
je     11bd <add_list+0x6d>
mov    %rax,%r14
lea    0x6(%rsp),%rsi
mov    %rax,%rdi
call   1060 <strtok@plt>
test   %rax,%rax
je     11ab <add_list+0x5b>
lea    0x6(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rax,%rdi
call   1040 <add_entry@plt>
test   %eax,%eax
jne    11b5 <add_list+0x65>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
jne    1190 <add_list+0x40>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe3c(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
jmp    11b5 <add_list+0x65>

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

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