#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 _mx_strbeginswith(char *, char *, char **, short);
int _mx_strbeginswithany(char *str, char **starts, char **endptr,
                         short ignore_case) {
  char **s;
  char *end;
  char *longestmatch = NULL;
  int res;
  for (s = starts; *s; s++) {
    res = _mx_strbeginswith(str, *s, &end, ignore_case);
    if (res && (!longestmatch || end > longestmatch))
      longestmatch = end;
  }
  if (longestmatch) {
    *endptr = longestmatch;
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<_mx_strbeginswithany>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %cx,%ax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ax,-0x22(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
je     11a5 <_mx_strbeginswithany+0x95>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
lea    -0x38(%rbp),%rdx
movswl -0x22(%rbp),%ecx
call   1030 <_mx_strbeginswith@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     118f <_mx_strbeginswithany+0x7f>
cmpq   $0x0,-0x40(%rbp)
je     1187 <_mx_strbeginswithany+0x77>
mov    -0x38(%rbp),%rax
cmp    -0x40(%rbp),%rax
jbe    118f <_mx_strbeginswithany+0x7f>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    1194 <_mx_strbeginswithany+0x84>
mov    -0x30(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
jmp    113b <_mx_strbeginswithany+0x2b>
cmpq   $0x0,-0x40(%rbp)
je     11c7 <_mx_strbeginswithany+0xb7>
mov    -0x40(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11ce <_mx_strbeginswithany+0xbe>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_mx_strbeginswithany>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    (%rsi),%rsi
test   %rsi,%rsi
je     1187 <_mx_strbeginswithany+0x77>
mov    %rdx,%r14
mov    %rdi,%r15
add    $0x8,%rbx
xor    %ebp,%ebp
movswl %cx,%r13d
mov    %rsp,%r12
jmp    114c <_mx_strbeginswithany+0x3c>
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
je     1178 <_mx_strbeginswithany+0x68>
mov    %r15,%rdi
mov    %r12,%rdx
mov    %r13d,%ecx
call   1030 <_mx_strbeginswith@plt>
test   %eax,%eax
je     1140 <_mx_strbeginswithany+0x30>
mov    (%rsp),%rax
cmp    %rbp,%rax
mov    %rbp,%rcx
cmova  %rax,%rcx
test   %rbp,%rbp
cmove  %rax,%rcx
mov    %rcx,%rbp
jmp    1140 <_mx_strbeginswithany+0x30>
test   %rbp,%rbp
je     1187 <_mx_strbeginswithany+0x77>
mov    %rbp,(%r14)
mov    $0x1,%eax
jmp    1189 <_mx_strbeginswithany+0x79>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @_mx_strbeginswithany(i8* %0, i8** %1, i8** %2, i16 signext %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8**
%9 = alloca i16
%10 = alloca i8**
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
store i8* %0, i8** %6
store i8** %1, i8*** %7
store i8** %2, i8*** %8
store i16 %3, i16* %9
store i8* null, i8** %12
%14 = load i8**, i8*** %7
store i8** %14, i8*** %10
br label %15
15: ; preds = %37, %4
%16 = load i8**, i8*** %10
%17 = load i8*, i8** %16
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %40
19: ; preds = %15
%20 = load i8*, i8** %6
%21 = load i8**, i8*** %10
%22 = load i8*, i8** %21
%23 = load i16, i16* %9
%24 = call i32 @_mx_strbeginswith(i8* %20, i8* %22, i8** %11, i16 signext %23)
store i32 %24, i32* %13
%25 = load i32, i32* %13
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %36
27: ; preds = %19
%28 = load i8*, i8** %12
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load i8*, i8** %11
%32 = load i8*, i8** %12
%33 = icmp ugt i8* %31, %32
br i1 %33, label %34, label %36
34: ; preds = %30, %27
%35 = load i8*, i8** %11
store i8* %35, i8** %12
br label %36
36: ; preds = %34, %30, %19
br label %37
37: ; preds = %36
%38 = load i8**, i8*** %10
%39 = getelementptr inbounds i8*, i8** %38, i32 1
store i8** %39, i8*** %10
br label %15
40: ; preds = %15
%41 = load i8*, i8** %12
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load i8*, i8** %12
%45 = load i8**, i8*** %8
store i8* %44, i8** %45
store i32 1, i32* %5
br label %47
46: ; preds = %40
store i32 0, i32* %5
br label %47
47: ; preds = %46, %43
%48 = load i32, i32* %5
ret i32 %48
}

LLVM IR (-O2):
define i32 @_mx_strbeginswithany(i8* %0, i8** nocapture %1, i8** nocapture writeonly %2, i16 signext %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
%7 = load i8*, i8** %1
%8 = icmp eq i8* %7, null
br i1 %8, label %29, label %9
9: ; preds = %4, %21
%10 = phi i8* [ %24, %21 ], [ %7, %4 ]
%11 = phi i8* [ %22, %21 ], [ null, %4 ]
%12 = phi i8** [ %23, %21 ], [ %1, %4 ]
%13 = call i32 @_mx_strbeginswith(i8* %0, i8* %10, i8** %5, i16 signext %3)
%14 = icmp eq i32 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %9
%16 = icmp eq i8* %11, null
%17 = load i8*, i8** %5
%18 = icmp ugt i8* %17, %11
%19 = select i1 %16, i1 true, i1 %18
%20 = select i1 %19, i8* %17, i8* %11
br label %21
21: ; preds = %15, %9
%22 = phi i8* [ %11, %9 ], [ %20, %15 ]
%23 = getelementptr inbounds i8*, i8** %12, i64 1
%24 = load i8*, i8** %23
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %9
26: ; preds = %21
%27 = icmp eq i8* %22, null
br i1 %27, label %29, label %28
28: ; preds = %26
store i8* %22, i8** %2
br label %29
29: ; preds = %4, %26, %28
%30 = phi i32 [ 1, %28 ], [ 0, %26 ], [ 0, %4 ]
ret i32 %30
}