#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 const *, char const *, ...);
char *strstr(char const *, char const *);
void find_str(char const *str, char const *substr) {
  char *pos = strstr(str, substr);
  if (pos) {
    printf("found the string '%s' in '%s' at position: %ld; result: %s\n",
           substr, str, pos - str, pos);
  } else {
    printf("the string '%s' was not found in '%s'\n", substr, str);
  }
}


x86 assembly (clang, -O0):
<find_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1176 <find_str+0x56>
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
sub    %rax,%rcx
mov    -0x18(%rbp),%r8
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    118c <find_str+0x6c>
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_str>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strstr@plt>
test   %rax,%rax
je     1158 <find_str+0x38>
mov    %rax,%rcx
sub    %rbx,%rcx
lea    0xebf(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %rax,%r8
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>
lea    0xedd(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [60 x i8] c"found the string '%s' in '%s' at position: %ld; result: %s\0A\00"
@.str.1 = [39 x i8] c"the string '%s' was not found in '%s'\0A\00"
define void @find_str(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = load i8*, i8** %4
%8 = call i8* @strstr(i8* %6, i8* %7)
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %21
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i8*, i8** %3
%14 = load i8*, i8** %5
%15 = load i8*, i8** %3
%16 = ptrtoint i8* %14 to i64
%17 = ptrtoint i8* %15 to i64
%18 = sub i64 %16, %17
%19 = load i8*, i8** %5
%20 = call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %13, i64 %18, i8* %19)
br label %25
21: ; preds = %2
%22 = load i8*, i8** %4
%23 = load i8*, i8** %3
%24 = call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %22, i8* %23)
br label %25
25: ; preds = %21, %11
ret void
}

LLVM IR (-O2):
@.str = [60 x i8] c"found the string '%s' in '%s' at position: %ld; result: %s\0A\00"
@.str.1 = [39 x i8] c"the string '%s' was not found in '%s'\0A\00"
define void @find_str(i8* %0, i8* %1) {
%3 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = ptrtoint i8* %3 to i64
%7 = ptrtoint i8* %0 to i64
%8 = sub i64 %6, %7
%9 = tail call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %0, i64 %8, i8* %3)
br label %12
10: ; preds = %2
%11 = tail call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %0)
br label %12
12: ; preds = %10, %5
ret void
}