#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 *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *strtok(char *, char *);
int string_is_in_list(char *haystack, char *needle) {
  char haystack_copy[strlen(haystack)];
  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>
mov    %eax,%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    0xe6e(%rip),%ax
mov    %ax,-0x32(%rbp)
lea    -0x32(%rbp),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1209 <string_is_in_list+0xc9>
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    11f3 <string_is_in_list+0xb3>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
jmp    1217 <string_is_in_list+0xd7>
lea    -0x32(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1060 <strtok@plt>
mov    %rax,-0x30(%rbp)
jmp    11a3 <string_is_in_list+0x63>
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>
mov    %eax,%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
cs 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 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %6
%15 = alloca i8, i64 %13
store i64 %13, i64* %7
%16 = load i8*, i8** %4
%17 = call i32 @strcpy(i8* %15, i8* %16)
%18 = bitcast [2 x i8]* %9 to i8*
%19 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%20 = call i8* @strtok(i8* %15, i8* %19)
store i8* %20, i8** %8
br label %21
21: ; preds = %32, %2
%22 = load i8*, i8** %8
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %35
24: ; preds = %21
%25 = load i8*, i8** %8
%26 = load i8*, i8** %5
%27 = load i8*, i8** %5
%28 = call i32 @strlen(i8* %27)
%29 = call i64 @strncmp(i8* %25, i8* %26, i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %24
store i32 1, i32* %3
store i32 1, i32* %10
br label %36
32: ; preds = %24
%33 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%34 = call i8* @strtok(i8* null, i8* %33)
store i8* %34, i8** %8
br label %21
35: ; preds = %21
store i32 0, i32* %3
store i32 1, i32* %10
br label %36
36: ; preds = %35, %31
%37 = load i8*, i8** %6
%38 = load i32, i32* %3
ret i32 %38
}

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