#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 *strchr(char *, char);
char *strdup(char const *);
int foreach_pathlist(const char *search_paths,
                     void (*feach)(void *, const char *path), void *userdata) {
  char *paths = strdup(search_paths);
  ;
  char *path = paths;
  while (*path) {
    char *next = strchr(path, ':');
    if (next) {
      *next = '\0';
      next++;
    }
    feach(userdata, path);
    path = next;
    if (!next)
      break;
  }
  free(paths);
  return 0;
}


x86 assembly (clang, -O0):
<foreach_pathlist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     11c1 <foreach_pathlist+0x91>
mov    -0x28(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1196 <foreach_pathlist+0x66>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   *%rax
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11bc <foreach_pathlist+0x8c>
jmp    11c1 <foreach_pathlist+0x91>
jmp    1159 <foreach_pathlist+0x29>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foreach_pathlist>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r15
call   1050 <strdup@plt>
mov    %rax,%r14
cmpb   $0x0,(%rax)
je     119c <foreach_pathlist+0x6c>
mov    %r14,%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1193 <foreach_pathlist+0x63>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    %rax,%rbp
add    $0x1,%rbp
mov    %r12,%rdi
mov    %r13,%rsi
call   *%r15
cmpb   $0x0,0x1(%rbx)
mov    %rbp,%r13
jne    1160 <foreach_pathlist+0x30>
jmp    119c <foreach_pathlist+0x6c>
mov    %r12,%rdi
mov    %r13,%rsi
call   *%r15
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @foreach_pathlist(i8* %0, void (i8*, i8*)* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca void (i8*, i8*)*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store void (i8*, i8*)* %1, void (i8*, i8*)** %5
store i8* %2, i8** %6
%10 = load i8*, i8** %4
%11 = call i8* @strdup(i8* %10)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
store i8* %12, i8** %8
br label %13
13: ; preds = %34, %3
%14 = load i8*, i8** %8
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %35
17: ; preds = %13
%18 = load i8*, i8** %8
%19 = call i8* @strchr(i8* %18, i8 signext 58)
store i8* %19, i8** %9
%20 = load i8*, i8** %9
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i8*, i8** %9
store i8 0, i8* %23
%24 = load i8*, i8** %9
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %9
br label %26
26: ; preds = %22, %17
%27 = load void (i8*, i8*)*, void (i8*, i8*)** %5
%28 = load i8*, i8** %6
%29 = load i8*, i8** %8
%30 = load i8*, i8** %9
store i8* %30, i8** %8
%31 = load i8*, i8** %9
%32 = icmp ne i8* %31, null
br i1 %32, label %34, label %33
33: ; preds = %26
br label %35
34: ; preds = %26
br label %13
35: ; preds = %33, %13
%36 = load i8*, i8** %7
%37 = call i32 @free(i8* %36)
ret i32 0
}

LLVM IR (-O2):
define i32 @foreach_pathlist(i8* nocapture %0, void (i8*, i8*)* nocapture %1, i8* %2) {
%4 = tail call i8* @strdup(i8* %0)
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 0
br i1 %6, label %16, label %7
7: ; preds = %3, %12
%8 = phi i8* [ %13, %12 ], [ %4, %3 ]
%9 = tail call i8* @strchr(i8* %8, i8 signext 58)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %7
tail call void %1(i8* %2, i8* %8)
br label %16
12: ; preds = %7
store i8 0, i8* %9
%13 = getelementptr inbounds i8, i8* %9, i64 1
tail call void %1(i8* %2, i8* %8)
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %7
16: ; preds = %12, %3, %11
%17 = tail call i32 @free(i8* %4)
ret i32 0
}