#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 *const);
scalar_t__ path_starts_with(char const *, char *);
char *split_and_get(char *, char, char **);
char *strdup(char const *);
int find_path_prefix_index(const char path[], const char list[]) {
  char *const list_copy = strdup(list);
  char *prefix = list_copy, *state = NULL;
  int i = 0;
  while ((prefix = split_and_get(prefix, ',', &state)) != NULL) {
    if (path_starts_with(path, prefix)) {
      break;
    }
    ++i;
  }
  free(list_copy);
  return (prefix == NULL) ? -1 : i;
}


x86 assembly (clang, -O0):
<find_path_prefix_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2c,%esi
lea    -0x28(%rbp),%rdx
call   1040 <split_and_get@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11be <find_path_prefix_index+0x7e>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <path_starts_with@plt>
cmp    $0x0,%rax
je     11b0 <find_path_prefix_index+0x70>
jmp    11be <find_path_prefix_index+0x7e>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1174 <find_path_prefix_index+0x34>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x20(%rbp)
jne    11df <find_path_prefix_index+0x9f>
mov    $0xffffffff,%eax
mov    %eax,-0x30(%rbp)
jmp    11e5 <find_path_prefix_index+0xa5>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_path_prefix_index>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
mov    %rsi,%rdi
call   1060 <strdup@plt>
mov    %rax,%r14
movq   $0x0,(%rsp)
mov    %rsp,%rdx
mov    %rax,%rdi
mov    $0x2c,%esi
call   1040 <split_and_get@plt>
mov    $0xffffffff,%r15d
test   %rax,%rax
je     11c0 <find_path_prefix_index+0x80>
mov    %rax,%rbp
xor    %ebx,%ebx
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
mov    %rbp,%rsi
call   1050 <path_starts_with@plt>
test   %rax,%rax
jne    11bd <find_path_prefix_index+0x7d>
add    $0x1,%ebx
mov    %rbp,%rdi
mov    $0x2c,%esi
mov    %r12,%rdx
call   1040 <split_and_get@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1190 <find_path_prefix_index+0x50>
jmp    11c0 <find_path_prefix_index+0x80>
mov    %ebx,%r15d
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @find_path_prefix_index(i8* %0, i8* nocapture %1) {
%3 = alloca i8*
%4 = tail call i8* @strdup(i8* %1)
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = call i8* @split_and_get(i8* %4, i8 signext 44, i8** %3)
%7 = icmp eq i8* %6, null
br i1 %7, label %17, label %8
8: ; preds = %2, %13
%9 = phi i8* [ %15, %13 ], [ %6, %2 ]
%10 = phi i32 [ %14, %13 ], [ 0, %2 ]
%11 = call i64 @path_starts_with(i8* %0, i8* %9)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = add nuw nsw i32 %10, 1
%15 = call i8* @split_and_get(i8* %9, i8 signext 44, i8** %3)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %8
17: ; preds = %13, %8, %2
%18 = phi i32 [ -1, %2 ], [ %10, %8 ], [ -1, %13 ]
%19 = call i32 @free(i8* %4)
ret i32 %18
}