#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*/ ft_strlen(char const *);
scalar_t__ ft_strncmp(char const *, char const *, int /*<<< orphan*/);
char *ft_strstr(char const *s1, char const *s2) {
  if (*s2 == 0)
    return ((char *)s1);
  else if (*s1 == 0)
    return (0);
  else if (ft_strncmp(s1, s2, ft_strlen(s2)) == 0)
    return ((char *)s1);
  else
    return (ft_strstr(s1 + 1, s2));
}


x86 assembly (clang, -O0):
<ft_strstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    115d <ft_strstr+0x2d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ce <ft_strstr+0x9e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    117a <ft_strstr+0x4a>
movq   $0x0,-0x8(%rbp)
jmp    11ce <ft_strstr+0x9e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <ft_strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1050 <ft_strncmp@plt>
cmp    $0x0,%rax
jne    11b9 <ft_strstr+0x89>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ce <ft_strstr+0x9e>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
call   1040 <ft_strstr@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_strstr>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
cmpb   $0x0,(%rsi)
je     115d <ft_strstr+0x3d>
mov    %rsi,%r14
nop
cmpb   $0x0,(%rbx)
je     115b <ft_strstr+0x3b>
mov    %r14,%rdi
call   1030 <ft_strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <ft_strncmp@plt>
test   %rax,%rax
je     115d <ft_strstr+0x3d>
add    $0x1,%rbx
cmpb   $0x0,(%r14)
jne    1130 <ft_strstr+0x10>
jmp    115d <ft_strstr+0x3d>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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