#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*/ EINVAL;
int /*<<< orphan*/ errno;
int stub1(char const);
int AnyWithPredicate(const char *str, int (*pred)(int)) {
  if (!str || !pred) {
    errno = EINVAL;
    return -1;
  }
  for (int i = 0; str[i] != '\0'; ++i) {
    if ((*pred)(str[i])) {
      return i;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<AnyWithPredicate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1126 <AnyWithPredicate+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1144 <AnyWithPredicate+0x44>
mov    0x2eab(%rip),%rax
mov    (%rax),%ecx
mov    0x2eaa(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11a0 <AnyWithPredicate+0xa0>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1199 <AnyWithPredicate+0x99>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
movsbl (%rcx,%rdx,1),%edi
call   *%rax
cmp    $0x0,%eax
je     1186 <AnyWithPredicate+0x86>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a0 <AnyWithPredicate+0xa0>
jmp    118b <AnyWithPredicate+0x8b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114b <AnyWithPredicate+0x4b>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AnyWithPredicate>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1149 <AnyWithPredicate+0x49>
mov    %rsi,%r15
test   %rsi,%rsi
je     1149 <AnyWithPredicate+0x49>
mov    %rdi,%rbp
mov    (%rdi),%al
mov    $0xffffffff,%r14d
test   %al,%al
je     1166 <AnyWithPredicate+0x66>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movsbl %al,%edi
call   *%r15
test   %eax,%eax
jne    1163 <AnyWithPredicate+0x63>
movzbl 0x1(%rbp,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
jne    1130 <AnyWithPredicate+0x30>
jmp    1166 <AnyWithPredicate+0x66>
mov    0x2e88(%rip),%rax
mov    (%rax),%eax
mov    0x2e87(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%r14d
jmp    1166 <AnyWithPredicate+0x66>
mov    %ebx,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
define i32 @AnyWithPredicate(i8* %0, i32 (i32)* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32 (i32)*
%6 = alloca i32
store i8* %0, i8** %4
store i32 (i32)* %1, i32 (i32)** %5
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32 (i32)*, i32 (i32)** %5
%11 = icmp ne i32 (i32)* %10, null
br i1 %11, label %14, label %12
12: ; preds = %9, %2
%13 = load i32, i32* @EINVAL
store i32 %13, i32* @errno
store i32 -1, i32* %3
br label %40
14: ; preds = %9
store i32 0, i32* %6
br label %15
15: ; preds = %36, %14
%16 = load i8*, i8** %4
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %39
23: ; preds = %15
%24 = load i32 (i32)*, i32 (i32)** %5
%25 = load i8*, i8** %4
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = call i32 %24(i32 %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %23
%34 = load i32, i32* %6
store i32 %34, i32* %3
br label %40
35: ; preds = %23
br label %36
36: ; preds = %35
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %15
39: ; preds = %15
store i32 -1, i32* %3
br label %40
40: ; preds = %39, %33, %12
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
define i32 @AnyWithPredicate(i8* %0, i32 (i32)* %1) {
%3 = icmp ne i8* %0, null
%4 = icmp ne i32 (i32)* %1, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %24, label %11
9: ; preds = %2
%10 = load i32, i32* @EINVAL
store i32 %10, i32* @errno
br label %24
11: ; preds = %6, %17
%12 = phi i64 [ %18, %17 ], [ 0, %6 ]
%13 = phi i8 [ %20, %17 ], [ %7, %6 ]
%14 = sext i8 %13 to i32
%15 = tail call i32 %1(i32 %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %11
%18 = add nuw i64 %12, 1
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %24, label %11
22: ; preds = %11
%23 = trunc i64 %12 to i32
br label %24
24: ; preds = %17, %22, %6, %9
%25 = phi i32 [ -1, %9 ], [ -1, %6 ], [ %23, %22 ], [ -1, %17 ]
ret i32 %25
}