#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 strlen(char const *);
scalar_t__ strncmp(char const *, char const *, int);
char *strstr(const char *h, const char *n) {
  int hlen = strlen(h);
  int nlen = strlen(n);
  for (int i = 0; i + nlen <= hlen; ++i) {
    if (strncmp(h + i, n, nlen) == 0)
      return (char *)h + i;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<strstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     11a6 <strstr+0x86>
mov    -0x10(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1193 <strstr+0x73>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11ae <strstr+0x8e>
jmp    1198 <strstr+0x78>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114f <strstr+0x2f>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %r15d,%eax
jg     116f <strstr+0x4f>
mov    %eax,%r12d
mov    %eax,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1171 <strstr+0x51>
add    $0x1,%rbx
add    $0x1,%ebp
cmp    %r15d,%ebp
jle    1150 <strstr+0x30>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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