/	Copyright (c) 1984, 1986, 1987, 1988 AT&T
/	  All Rights Reserved

/	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
/	The copyright notice above does not evidence any
/	actual or intended publication of such source code.
	.file	"strchr.s"

	.ident	"@(#)libc-i386:libc-i386/gen/strchr.s	1.2"

	.globl	strchr
	.align	4

strchr:
	MCOUNT			/ profiling
	pushl	%esi		/ save register variable
	movl	8(%esp),%esi	/ %eax = string address
	movb	12(%esp),%dl	/ %dl = byte sought
.loop:
/ a dual scan is a lose because you have to find the end first.
	slodb			/ %al = byte of string
	cmpb	%dl,%al		/ Find it?
	je	.found		/ Yes.
	testb	%al,%al		/ Is it null?
	je	.notfound

	slodb			/ %al = byte of string
	cmpb	%dl,%al		/ Find it?
	je	.found		/ Yes.
	testb	%al,%al		/ Is it null?
	je	.notfound

	slodb			/ %al = byte of string
	cmpb	%dl,%al		/ Find it?
	je	.found		/ Yes.
	testb	%al,%al		/ Is it null?
	je	.notfound

	slodb			/ %al = byte of string
	cmpb	%dl,%al		/ Find it?
	je	.found		/ Yes.
	testb	%al,%al		/ Is it null?
	jne	.loop

.notfound:
	xorl	%eax,%eax	/ %eax = NULL
	popl	%esi		/ restore register variable
	ret	
.found:
	movl	%esi,%eax
	decl	%eax
	popl	%esi		/ restore register variable
	ret	
