#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*/ strcpy(char *, char const *);
int /*<<< orphan*/ strlen(char const *);
scalar_t__ strncmp(char *, char const *, int /*<<< orphan*/);
char *strtok(char *, char *);
int string_is_in_list(const char *haystack, const char *needle) {
  char haystack_copy[strlen(haystack) + 1];
  strcpy(haystack_copy, haystack);
  char *token;
  char delimiter[] = ",";
  token = strtok(haystack_copy, delimiter);
  while (token != NULL) {
    if (strncmp(token, needle, strlen(needle)) == 0) {
      return 1;
    }
    token = strtok(NULL, delimiter);
  }
  return 0;
}


x86 assembly (clang, -O0):
<string_is_in_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x40(%rbp),%rdi
mov    0xe6d(%rip),%ax
mov    %ax,-0x32(%rbp)
lea    -0x32(%rbp),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     120a <string_is_in_list+0xca>
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11f4 <string_is_in_list+0xb4>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
jmp    1218 <string_is_in_list+0xd8>
lea    -0x32(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1060 <strtok@plt>
mov    %rax,-0x30(%rbp)
jmp    11a4 <string_is_in_list+0x64>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_is_in_list>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
call   1050 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
movw   $0x2c,-0x22(%rbp)
lea    -0x22(%rbp),%rsi
mov    %rbx,%rdi
call   1060 <strtok@plt>
test   %rax,%rax
je     11d1 <string_is_in_list+0x91>
mov    %rax,%rbx
lea    -0x22(%rbp),%r14
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11d6 <string_is_in_list+0x96>
xor    %r12d,%r12d
xor    %edi,%edi
mov    %r14,%rsi
call   1060 <strtok@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a0 <string_is_in_list+0x60>
jmp    11dc <string_is_in_list+0x9c>
xor    %r12d,%r12d
jmp    11dc <string_is_in_list+0x9c>
mov    $0x1,%r12d
mov    %r12d,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.string_is_in_list.delimiter = [2 x i8] c",\00"
define i32 @string_is_in_list(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca [2 x i8]
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 %12, 1
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %6
%16 = alloca i8, i64 %14
store i64 %14, i64* %7
%17 = load i8*, i8** %4
%18 = call i32 @strcpy(i8* %16, i8* %17)
%19 = bitcast [2 x i8]* %9 to i8*
%20 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%21 = call i8* @strtok(i8* %16, i8* %20)
store i8* %21, i8** %8
br label %22
22: ; preds = %33, %2
%23 = load i8*, i8** %8
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %36
25: ; preds = %22
%26 = load i8*, i8** %8
%27 = load i8*, i8** %5
%28 = load i8*, i8** %5
%29 = call i32 @strlen(i8* %28)
%30 = call i64 @strncmp(i8* %26, i8* %27, i32 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %25
store i32 1, i32* %3
store i32 1, i32* %10
br label %37
33: ; preds = %25
%34 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%35 = call i8* @strtok(i8* null, i8* %34)
store i8* %35, i8** %8
br label %22
36: ; preds = %22
store i32 0, i32* %3
store i32 1, i32* %10
br label %37
37: ; preds = %36, %32
%38 = load i8*, i8** %6
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
define i32 @string_is_in_list(i8* %0, i8* %1) {
%3 = alloca i16
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %4, 1
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = call i32 @strcpy(i8* %7, i8* %0)
%9 = bitcast i16* %3 to i8*
store i16 44, i16* %3
%10 = call i8* @strtok(i8* %7, i8* %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %20, label %12
12: ; preds = %2, %17
%13 = phi i8* [ %18, %17 ], [ %10, %2 ]
%14 = call i32 @strlen(i8* %1)
%15 = call i64 @strncmp(i8* %13, i8* %1, i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %12
%18 = call i8* @strtok(i8* null, i8* %9)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %12
20: ; preds = %12, %17, %2
%21 = phi i32 [ 0, %2 ], [ 0, %17 ], [ 1, %12 ]
ret i32 %21
}