#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 *);
char *malloc(scalar_t__);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *strtok(char *, char *);
int cmp_param(char *str, char *delim, int index, char *str2) {
  char *buf = malloc(strlen(str) + 1), *token;
  strcpy(buf, str);
  token = strtok(buf, delim);
  while (index > 0 && token != NULL) {
    token = strtok(NULL, delim);
    index--;
  }
  if (token == NULL)
    goto err;
  int res = !strcmp(token, str2);
  free(buf);
  return res;
err:
  free(buf);
  return 0;
}


x86 assembly (clang, -O0):
<cmp_param>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x3d(%rbp)
jle    11c8 <cmp_param+0x68>
cmpq   $0x0,-0x38(%rbp)
setne  %al
mov    %al,-0x3d(%rbp)
mov    -0x3d(%rbp),%al
test   $0x1,%al
jne    11d8 <cmp_param+0x78>
jmp    11f7 <cmp_param+0x97>
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1080 <strtok@plt>
mov    %rax,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ae <cmp_param+0x4e>
cmpq   $0x0,-0x38(%rbp)
jne    1207 <cmp_param+0xa7>
jmp    1238 <cmp_param+0xd8>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1248 <cmp_param+0xe8>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmp_param>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r12
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <strtok@plt>
test   %ebp,%ebp
jle    11bc <cmp_param+0x5c>
xchg   %ax,%ax
test   %rax,%rax
je     11bc <cmp_param+0x5c>
xor    %edi,%edi
mov    %rbx,%rsi
call   1080 <strtok@plt>
cmp    $0x2,%ebp
jb     11bc <cmp_param+0x5c>
add    $0xffffffff,%ebp
test   %rax,%rax
jne    11a5 <cmp_param+0x45>
test   %rax,%rax
je     11d5 <cmp_param+0x75>
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
xor    %ebx,%ebx
test   %eax,%eax
sete   %bl
jmp    11d7 <cmp_param+0x77>
xor    %ebx,%ebx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @cmp_param(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%13 = load i8*, i8** %6
%14 = call i64 @strlen(i8* %13)
%15 = add nsw i64 %14, 1
%16 = call i8* @malloc(i64 %15)
store i8* %16, i8** %10
%17 = load i8*, i8** %10
%18 = load i8*, i8** %6
%19 = call i32 @strcpy(i8* %17, i8* %18)
%20 = load i8*, i8** %10
%21 = load i8*, i8** %7
%22 = call i8* @strtok(i8* %20, i8* %21)
store i8* %22, i8** %11
br label %23
23: ; preds = %31, %4
%24 = load i32, i32* %8
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i8*, i8** %11
%28 = icmp ne i8* %27, null
br label %29
29: ; preds = %26, %23
%30 = phi i1 [ false, %23 ], [ %28, %26 ]
br i1 %30, label %31, label %36
31: ; preds = %29
%32 = load i8*, i8** %7
%33 = call i8* @strtok(i8* null, i8* %32)
store i8* %33, i8** %11
%34 = load i32, i32* %8
%35 = add nsw i32 %34, -1
store i32 %35, i32* %8
br label %23
36: ; preds = %29
%37 = load i8*, i8** %11
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %40
39: ; preds = %36
br label %50
40: ; preds = %36
%41 = load i8*, i8** %11
%42 = load i8*, i8** %9
%43 = call i32 @strcmp(i8* %41, i8* %42)
%44 = icmp ne i32 %43, 0
%45 = xor i1 %44, true
%46 = zext i1 %45 to i32
store i32 %46, i32* %12
%47 = load i8*, i8** %10
%48 = call i32 @free(i8* %47)
%49 = load i32, i32* %12
store i32 %49, i32* %5
br label %53
50: ; preds = %39
%51 = load i8*, i8** %10
%52 = call i32 @free(i8* %51)
store i32 0, i32* %5
br label %53
53: ; preds = %50, %40
%54 = load i32, i32* %5
ret i32 %54
}

LLVM IR (-O2):
define i32 @cmp_param(i8* %0, i8* nocapture %1, i32 %2, i8* nocapture %3) {
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = add nsw i64 %5, 1
%7 = tail call i8* @malloc(i64 %6)
%8 = tail call i32 @strcpy(i8* %7, i8* %0)
%9 = tail call i8* @strtok(i8* %7, i8* %1)
%10 = icmp sgt i32 %2, 0
%11 = icmp ne i8* %9, null
%12 = select i1 %10, i1 %11, i1 false
br i1 %12, label %13, label %20
13: ; preds = %4, %13
%14 = phi i32 [ %16, %13 ], [ %2, %4 ]
%15 = tail call i8* @strtok(i8* null, i8* %1)
%16 = add nsw i32 %14, -1
%17 = icmp ugt i32 %14, 1
%18 = icmp ne i8* %15, null
%19 = select i1 %17, i1 %18, i1 false
br i1 %19, label %13, label %20
20: ; preds = %13, %4
%21 = phi i8* [ %9, %4 ], [ %15, %13 ]
%22 = icmp eq i8* %21, null
br i1 %22, label %27, label %23
23: ; preds = %20
%24 = tail call i32 @strcmp(i8* %21, i8* dereferenceable(1) %3)
%25 = icmp eq i32 %24, 0
%26 = zext i1 %25 to i32
br label %27
27: ; preds = %20, %23
%28 = phi i32 [ %26, %23 ], [ 0, %20 ]
%29 = tail call i32 @free(i8* %7)
ret i32 %28
}