#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*/ printf(char *, char *, char *, size_t);
size_t strings_search(char *, char *, size_t);
void example_search() {
  char *s = "this is a simple example";
  char *sub = "mp";
  size_t first_idx = strings_search(s, sub, 0);
  size_t second_idx = strings_search(s, sub, first_idx + 1);
  printf("'%s' is seen in '%s' at index %zu\n", sub, s, first_idx);
  printf("'%s' is seen in '%s' again at index %zu\n", sub, s, second_idx);
}


x86 assembly (clang, -O0):
<example_search>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xed1(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    0xedf(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <strings_search@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
add    $0x1,%rdx
call   1030 <strings_search@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe9d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xea8(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<example_search>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xed1(%rip),%r14
lea    0xee3(%rip),%r15
mov    %r14,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1030 <strings_search@plt>
mov    %rax,%rbx
lea    0x1(%rax),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strings_search@plt>
mov    %rax,%r12
lea    0xebd(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1040 <printf@plt>
lea    0xecb(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %r12,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"this is a simple example\00"
@.str.1 = [3 x i8] c"mp\00"
@.str.2 = [35 x i8] c"'%s' is seen in '%s' at index %zu\0A\00"
@.str.3 = [41 x i8] c"'%s' is seen in '%s' again at index %zu\0A\00"
define void @example_search() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8** %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %2
%5 = load i8*, i8** %1
%6 = load i8*, i8** %2
%7 = call i64 @strings_search(i8* %5, i8* %6, i64 0)
store i64 %7, i64* %3
%8 = load i8*, i8** %1
%9 = load i8*, i8** %2
%10 = load i64, i64* %3
%11 = add i64 %10, 1
%12 = call i64 @strings_search(i8* %8, i8* %9, i64 %11)
store i64 %12, i64* %4
%13 = load i8*, i8** %2
%14 = load i8*, i8** %1
%15 = load i64, i64* %3
%16 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %13, i8* %14, i64 %15)
%17 = load i8*, i8** %2
%18 = load i8*, i8** %1
%19 = load i64, i64* %4
%20 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %17, i8* %18, i64 %19)
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"this is a simple example\00"
@.str.1 = [3 x i8] c"mp\00"
@.str.2 = [35 x i8] c"'%s' is seen in '%s' at index %zu\0A\00"
@.str.3 = [41 x i8] c"'%s' is seen in '%s' again at index %zu\0A\00"
define void @example_search() {
%1 = tail call i64 @strings_search(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64 0)
%2 = add i64 %1, 1
%3 = tail call i64 @strings_search(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64 %2)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i64 %1)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i64 %3)
ret void
}