#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 */
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
char *sse4_strstr_any(char *s1, int n1, char *s2, int n2) {
  char *result;
  uint32_t dummy __attribute__((unused));
  __asm__ volatile("movdqu (%%eax), %%xmm1" : : "a"(s1));
  __asm__ volatile("pxor    %%xmm0, %%xmm0" : :);
  __asm__ volatile("	addl   $-24, %%esp		\n"
                   "	movl   8(%%ebp), %%eax		\n"
                   "	addl         $4, %%eax		\n"
                   "	movl      %%eax, 0(%%esp)	\n"
                   "					\n"
                   "	movl  12(%%ebp), %%eax		\n"
                   "	subl         $4, %%eax		\n"
                   "	movl      %%eax, 8(%%esp)	\n"
                   "					\n"
                   "0:					\n"
                   "	movdqu (%%esi), %%xmm2		\n"
                   "	addl $8, %%esi			\n"
                   "	mpsadbw $0, %%xmm1, %%xmm2	\n"
                   "	pcmpeqw %%xmm0, %%xmm2		\n"
                   "	ptest   %%xmm2, %%xmm0		\n"
                   "	jc      1f			\n"
                   "	pmovmskb %%xmm2, %%edx		\n"
                   "	andl $0b0101010101010101, %%edx	\n"
                   "	2:					\n"
                   "	bsf %%edx, %%eax		\n"
                   "	jz  1f				\n"
                   "					\n"
                   "	btr %%eax, %%edx		\n"
                   "	shr $1, %%eax			\n"
                   "	movl  %%eax, 12(%%esp)		\n"
                   "	movl  %%ecx, 16(%%esp)		\n"
                   "	movl  %%edx, 20(%%esp)		\n"
                   "	leal -4(%%esi, %%eax), %%eax	\n"
                   "	movl  %%eax, 4(%%esp)		\n"
                   "	call  strncmp			\n"
                   "	test  %%eax, %%eax		\n"
                   "	movl  12(%%esp), %%eax		\n"
                   "	movl  16(%%esp), %%ecx		\n"
                   "	movl  20(%%esp), %%edx		\n"
                   "	jnz 2b				\n"
                   "	leal -8(%%eax, %%esi), %%eax	\n"
                   "	jmp 4f				\n"
                   "1:					\n"
                   "	subl $8, %%ecx			\n"
                   "	cmpl $0, %%ecx			\n"
                   "	jg   0b				\n"
                   "	xorl %%eax, %%eax		\n"
                   "4:					\n"
                   "	addl   $24, %%esp		\n"
                   : "=a"(result), "=S"(dummy), "=c"(dummy)
                   : "S"(s2), "c"(n2 - n1));
  return result;
}


x86 assembly (clang, -O0):
<sse4_strstr_any>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movdqu (%eax),%xmm1
pxor   %xmm0,%xmm0
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%ecx
sub    -0xc(%rbp),%ecx
add    $0xffffffe8,%esp
mov    0x8(%ebp),%eax
add    $0x4,%eax
mov    %eax,(%esp)
mov    0xc(%ebp),%eax
sub    $0x4,%eax
mov    %eax,0x8(%esp)
movdqu (%esi),%xmm2
add    $0x8,%esi
mpsadbw $0x0,%xmm1,%xmm2
pcmpeqw %xmm0,%xmm2
ptest  %xmm2,%xmm0
jb     11c7 <sse4_strstr_any+0xb7>
pmovmskb %xmm2,%edx
and    $0x5555,%edx
bsf    %edx,%eax
je     11c7 <sse4_strstr_any+0xb7>
btr    %eax,%edx
shr    %eax
mov    %eax,0xc(%esp)
mov    %ecx,0x10(%esp)
mov    %edx,0x14(%esp)
lea    -0x4(%esi,%eax,1),%eax
mov    %eax,0x4(%esp)
call   1030 <strncmp@plt>
test   %eax,%eax
mov    0xc(%esp),%eax
mov    0x10(%esp),%ecx
mov    0x14(%esp),%edx
jne    117a <sse4_strstr_any+0x6a>
lea    -0x8(%eax,%esi,1),%eax
jmp    11d5 <sse4_strstr_any+0xc5>
sub    $0x8,%ecx
cmp    $0x0,%ecx
jg     1153 <sse4_strstr_any+0x43>
xor    %eax,%eax
add    $0x18,%esp
mov    %rax,-0x28(%rbp)
mov    %esi,-0x2c(%rbp)
mov    %ecx,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<sse4_strstr_any>:
mov    %rdi,%rax
movdqu (%eax),%xmm1
pxor   %xmm0,%xmm0
sub    %esi,%ecx
mov    %rdx,%rsi
add    $0xffffffe8,%esp
mov    0x8(%ebp),%eax
add    $0x4,%eax
mov    %eax,(%esp)
mov    0xc(%ebp),%eax
sub    $0x4,%eax
mov    %eax,0x8(%esp)
movdqu (%esi),%xmm2
add    $0x8,%esi
mpsadbw $0x0,%xmm1,%xmm2
pcmpeqw %xmm0,%xmm2
ptest  %xmm2,%xmm0
jb     11a0 <sse4_strstr_any+0x90>
pmovmskb %xmm2,%edx
and    $0x5555,%edx
bsf    %edx,%eax
je     11a0 <sse4_strstr_any+0x90>
btr    %eax,%edx
shr    %eax
mov    %eax,0xc(%esp)
mov    %ecx,0x10(%esp)
mov    %edx,0x14(%esp)
lea    -0x4(%esi,%eax,1),%eax
mov    %eax,0x4(%esp)
call   1030 <strncmp@plt>
test   %eax,%eax
mov    0xc(%esp),%eax
mov    0x10(%esp),%ecx
mov    0x14(%esp),%edx
jne    115e <sse4_strstr_any+0x4e>
lea    -0x8(%eax,%esi,1),%eax
jmp    11aa <sse4_strstr_any+0x9a>
sub    $0x8,%ecx
cmp    $0x0,%ecx
jg     113b <sse4_strstr_any+0x2b>
xor    %eax,%eax
add    $0x18,%esp
ret

LLVM IR (-O0):
define i8* @sse4_strstr_any(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i8*, i8** %5
%12 = load i8*, i8** %7
%13 = load i32, i32* %8
%14 = load i32, i32* %6
%15 = sub nsw i32 %13, %14
%16 = call { i8*, i32, i32 } asm sideeffect "\09addl $$-24, %esp\09\09\0A\09movl 8(%ebp), %eax\09\09\0A\09addl $$4, %eax\09\09\0A\09movl %eax, 0(%esp)\09\0A\09\09\09\09\09\0A\09movl 12(%ebp), %eax\09\09\0A\09subl $$4, %eax\09\09\0A\09movl %eax, 8(%esp)\09\0A\09\09\09\09\09\0A0:\09\09\09\09\09\0A\09movdqu (%esi), %xmm2\09\09\0A\09addl $$8, %esi\09\09\09\0A\09mpsadbw $$0, %xmm1, %xmm2\09\0A\09pcmpeqw %xmm0, %xmm2\09\09\0A\09ptest %xmm2, %xmm0\09\09\0A\09jc 1f\09\09\09\0A\09pmovmskb %xmm2, %edx\09\09\0A\09andl $$0b0101010101010101, %edx\09\0A\092:\09\09\09\09\09\0A\09bsf %edx, %eax\09\09\0A\09jz 1f\09\09\09\09\0A\09\09\09\09\09\0A\09btr %eax, %edx\09\09\0A\09shr $$1, %eax\09\09\09\0A\09movl %eax, 12(%esp)\09\09\0A\09movl %ecx, 16(%esp)\09\09\0A\09movl %edx, 20(%esp)\09\09\0A\09leal -4(%esi, %eax), %eax\09\0A\09movl %eax, 4(%esp)\09\09\0A\09call strncmp\09\09\09\0A\09test %eax, %eax\09\09\0A\09movl 12(%esp), %eax\09\09\0A\09movl 16(%esp), %ecx\09\09\0A\09movl 20(%esp), %edx\09\09\0A\09jnz 2b\09\09\09\09\0A\09leal -8(%eax, %esi), %eax\09\0A\09jmp 4f\09\09\09\09\0A1:\09\09\09\09\09\0A\09subl $$8, %ecx\09\09\09\0A\09cmpl $$0, %ecx\09\09\09\0A\09jg 0b\09\09\09\09\0A\09xorl %eax, %eax\09\09\0A4:\09\09\09\09\09\0A\09addl $$24, %esp\09\09\0A", "={ax},={si},={cx},{si},{cx},~{dirflag},~{fpsr},~{flags}"(i8* %12, i32 %15)
%17 = extractvalue { i8*, i32, i32 } %16, 0
%18 = extractvalue { i8*, i32, i32 } %16, 1
%19 = extractvalue { i8*, i32, i32 } %16, 2
store i8* %17, i8** %9
store i32 %18, i32* %10
store i32 %19, i32* %10
%20 = load i8*, i8** %9
ret i8* %20
}

LLVM IR (-O2):
define i8* @sse4_strstr_any(i8* %0, i32 %1, i8* %2, i32 %3) {
tail call void asm sideeffect "movdqu (%eax), %xmm1", "{ax},~{dirflag},~{fpsr},~{flags}"(i8* %0)
tail call void asm sideeffect "pxor %xmm0, %xmm0", "~{dirflag},~{fpsr},~{flags}"()
%5 = sub nsw i32 %3, %1
%6 = tail call { i8*, i32, i32 } asm sideeffect "\09addl $$-24, %esp\09\09\0A\09movl 8(%ebp), %eax\09\09\0A\09addl $$4, %eax\09\09\0A\09movl %eax, 0(%esp)\09\0A\09\09\09\09\09\0A\09movl 12(%ebp), %eax\09\09\0A\09subl $$4, %eax\09\09\0A\09movl %eax, 8(%esp)\09\0A\09\09\09\09\09\0A0:\09\09\09\09\09\0A\09movdqu (%esi), %xmm2\09\09\0A\09addl $$8, %esi\09\09\09\0A\09mpsadbw $$0, %xmm1, %xmm2\09\0A\09pcmpeqw %xmm0, %xmm2\09\09\0A\09ptest %xmm2, %xmm0\09\09\0A\09jc 1f\09\09\09\0A\09pmovmskb %xmm2, %edx\09\09\0A\09andl $$0b0101010101010101, %edx\09\0A\092:\09\09\09\09\09\0A\09bsf %edx, %eax\09\09\0A\09jz 1f\09\09\09\09\0A\09\09\09\09\09\0A\09btr %eax, %edx\09\09\0A\09shr $$1, %eax\09\09\09\0A\09movl %eax, 12(%esp)\09\09\0A\09movl %ecx, 16(%esp)\09\09\0A\09movl %edx, 20(%esp)\09\09\0A\09leal -4(%esi, %eax), %eax\09\0A\09movl %eax, 4(%esp)\09\09\0A\09call strncmp\09\09\09\0A\09test %eax, %eax\09\09\0A\09movl 12(%esp), %eax\09\09\0A\09movl 16(%esp), %ecx\09\09\0A\09movl 20(%esp), %edx\09\09\0A\09jnz 2b\09\09\09\09\0A\09leal -8(%eax, %esi), %eax\09\0A\09jmp 4f\09\09\09\09\0A1:\09\09\09\09\09\0A\09subl $$8, %ecx\09\09\09\0A\09cmpl $$0, %ecx\09\09\09\0A\09jg 0b\09\09\09\09\0A\09xorl %eax, %eax\09\09\0A4:\09\09\09\09\09\0A\09addl $$24, %esp\09\09\0A", "={ax},={si},={cx},{si},{cx},~{dirflag},~{fpsr},~{flags}"(i8* %2, i32 %5)
%7 = extractvalue { i8*, i32, i32 } %6, 0
ret i8* %7
}