#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*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
int contains_tok(char *s1, char *s2, char *delims) {
  char *p;
  char tempstr[(4 * 8192)];
  int i;
  strcpy(tempstr, s1);
  p = strtok(tempstr, delims);
  i = 0;
  while (p != NULL) {
    if (!strcmp(p, s2)) {
      return (i);
    }
    i++;
    p = strtok(NULL, delims);
  }
  return (0);
}


x86 assembly (clang, -O0):
<contains_tok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8040,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x8030(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x8030(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x8034(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11c9 <contains_tok+0x99>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11a4 <contains_tok+0x74>
mov    -0x8034(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d0 <contains_tok+0xa0>
mov    -0x8034(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8034(%rbp)
mov    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1050 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    1175 <contains_tok+0x45>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x8040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<contains_tok>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x8008,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
je     1195 <contains_tok+0x65>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1199 <contains_tok+0x69>
add    $0x1,%ebp
xor    %ebx,%ebx
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
jne    1170 <contains_tok+0x40>
jmp    119b <contains_tok+0x6b>
xor    %ebx,%ebx
jmp    119b <contains_tok+0x6b>
mov    %ebp,%ebx
mov    %ebx,%eax
add    $0x8008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @contains_tok(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [32768 x i8]
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%11 = getelementptr inbounds [32768 x i8], [32768 x i8]* %9, i64 0, i64 0
%12 = load i8*, i8** %5
%13 = call i32 @strcpy(i8* %11, i8* %12)
%14 = getelementptr inbounds [32768 x i8], [32768 x i8]* %9, i64 0, i64 0
%15 = load i8*, i8** %7
%16 = call i8* @strtok(i8* %14, i8* %15)
store i8* %16, i8** %8
store i32 0, i32* %10
br label %17
17: ; preds = %27, %3
%18 = load i8*, i8** %8
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %32
20: ; preds = %17
%21 = load i8*, i8** %8
%22 = load i8*, i8** %6
%23 = call i32 @strcmp(i8* %21, i8* %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %20
%26 = load i32, i32* %10
store i32 %26, i32* %4
br label %33
27: ; preds = %20
%28 = load i32, i32* %10
%29 = add nsw i32 %28, 1
store i32 %29, i32* %10
%30 = load i8*, i8** %7
%31 = call i8* @strtok(i8* null, i8* %30)
store i8* %31, i8** %8
br label %17
32: ; preds = %17
store i32 0, i32* %4
br label %33
33: ; preds = %32, %25
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
define i32 @contains_tok(i8* %0, i8* nocapture %1, i8* nocapture %2) {
%4 = alloca [32768 x i8]
%5 = getelementptr inbounds [32768 x i8], [32768 x i8]* %4, i64 0, i64 0
%6 = call i32 @strcpy(i8* %5, i8* %0)
%7 = call i8* @strtok(i8* %5, i8* %2)
%8 = icmp eq i8* %7, null
br i1 %8, label %18, label %9
9: ; preds = %3, %14
%10 = phi i32 [ %15, %14 ], [ 0, %3 ]
%11 = phi i8* [ %16, %14 ], [ %7, %3 ]
%12 = call i32 @strcmp(i8* %11, i8* dereferenceable(1) %1)
%13 = icmp eq i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %9
%15 = add nuw nsw i32 %10, 1
%16 = call i8* @strtok(i8* null, i8* %2)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %9
18: ; preds = %9, %14, %3
%19 = phi i32 [ 0, %3 ], [ 0, %14 ], [ %10, %9 ]
ret i32 %19
}