#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 /*<<< orphan*/ free(char *);
scalar_t__ strcmp(char const *, char *);
char *strdup(char const *);
char *strtok(char *, char const *);
int list_contains(const char *list, const char *value, const char *delim) {
  int ret = 0;
  char *str = strdup(list);
  char *c = strtok(str, delim);
  while (c != NULL) {
    if (strcmp(value, c) == 0) {
      ret = 1;
      break;
    }
    c = strtok(NULL, delim);
  }
  free(str);
  return ret;
}


x86 assembly (clang, -O0):
<list_contains>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11bd <list_contains+0x7d>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11a7 <list_contains+0x67>
movl   $0x1,-0x1c(%rbp)
jmp    11bd <list_contains+0x7d>
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1050 <strtok@plt>
mov    %rax,-0x30(%rbp)
jmp    1179 <list_contains+0x39>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_contains>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r15
call   1060 <strdup@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r12,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
je     1193 <list_contains+0x53>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1197 <list_contains+0x57>
xor    %ebx,%ebx
xor    %edi,%edi
mov    %r12,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
jne    1170 <list_contains+0x30>
jmp    119c <list_contains+0x5c>
xor    %ebx,%ebx
jmp    119c <list_contains+0x5c>
mov    $0x1,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @list_contains(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 0, i32* %7
%10 = load i8*, i8** %4
%11 = call i8* @strdup(i8* %10)
store i8* %11, i8** %8
%12 = load i8*, i8** %8
%13 = load i8*, i8** %6
%14 = call i8* @strtok(i8* %12, i8* %13)
store i8* %14, i8** %9
br label %15
15: ; preds = %24, %3
%16 = load i8*, i8** %9
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %27
18: ; preds = %15
%19 = load i8*, i8** %5
%20 = load i8*, i8** %9
%21 = call i64 @strcmp(i8* %19, i8* %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
store i32 1, i32* %7
br label %27
24: ; preds = %18
%25 = load i8*, i8** %6
%26 = call i8* @strtok(i8* null, i8* %25)
store i8* %26, i8** %9
br label %15
27: ; preds = %23, %15
%28 = load i8*, i8** %8
%29 = call i32 @free(i8* %28)
%30 = load i32, i32* %7
ret i32 %30
}

LLVM IR (-O2):
define i32 @list_contains(i8* nocapture %0, i8* %1, i8* nocapture %2) {
%4 = tail call i8* @strdup(i8* %0)
%5 = tail call i8* @strtok(i8* %4, i8* %2)
%6 = icmp eq i8* %5, null
br i1 %6, label %14, label %7
7: ; preds = %3, %11
%8 = phi i8* [ %12, %11 ], [ %5, %3 ]
%9 = tail call i64 @strcmp(i8* %1, i8* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %7
%12 = tail call i8* @strtok(i8* null, i8* %2)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %7
14: ; preds = %11, %7, %3
%15 = phi i32 [ 0, %3 ], [ 1, %7 ], [ 0, %11 ]
%16 = tail call i32 @free(i8* %4)
ret i32 %15
}