#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 */
char *strchr(char *, int);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *sindex(char *s1, char *s2) {
  register int s2len = strlen(s2);
  char *s = s1;
  while ((s = strchr(s, (int)*s2)) != 0) {
    if (strncmp(s, s2, s2len) == 0)
      return (s);
    s++;
  }
  return (0);
}


x86 assembly (clang, -O0):
<sindex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
movsbl (%rax),%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11aa <sindex+0x7a>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1199 <sindex+0x69>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b2 <sindex+0x82>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1154 <sindex+0x24>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sindex>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r14d
movsbl (%rbx),%esi
mov    %rbp,%rdi
call   1050 <strchr@plt>
test   %rax,%rax
je     118a <sindex+0x5a>
mov    %rax,%rbp
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     118c <sindex+0x5c>
add    $0x1,%rbp
movsbl (%rbx),%esi
mov    %rbp,%rdi
call   1050 <strchr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1160 <sindex+0x30>
xor    %ebp,%ebp
mov    %rbp,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @sindex(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %6
%10 = load i8*, i8** %4
store i8* %10, i8** %7
br label %11
11: ; preds = %26, %2
%12 = load i8*, i8** %7
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = call i8* @strchr(i8* %12, i32 %15)
store i8* %16, i8** %7
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %29
18: ; preds = %11
%19 = load i8*, i8** %7
%20 = load i8*, i8** %5
%21 = load i32, i32* %6
%22 = call i64 @strncmp(i8* %19, i8* %20, i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = load i8*, i8** %7
store i8* %25, i8** %3
br label %30
26: ; preds = %18
%27 = load i8*, i8** %7
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %7
br label %11
29: ; preds = %11
store i8* null, i8** %3
br label %30
30: ; preds = %29, %24
%31 = load i8*, i8** %3
ret i8* %31
}

LLVM IR (-O2):
define i8* @sindex(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = load i8, i8* %1
%5 = sext i8 %4 to i32
%6 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %18, label %8
8: ; preds = %2, %12
%9 = phi i8* [ %16, %12 ], [ %6, %2 ]
%10 = tail call i64 @strncmp(i8* %9, i8* %1, i32 %3)
%11 = icmp eq i64 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %8
%13 = getelementptr inbounds i8, i8* %9, i64 1
%14 = load i8, i8* %1
%15 = sext i8 %14 to i32
%16 = tail call i8* @strchr(i8* dereferenceable(1) %13, i32 %15)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %8
18: ; preds = %8, %12, %2
%19 = phi i8* [ null, %2 ], [ null, %12 ], [ %9, %8 ]
ret i8* %19
}