#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*/ freestring(char **);
int /*<<< orphan*/ mkupper(char *);
char *strdup(char *);
char *strstr(char *, char *);
char *strstrx(char *s1, char *s2) {
  char *ss1, *ss2, *spt;
  ss1 = strdup(s1);
  ss2 = strdup(s2);
  mkupper(ss1);
  mkupper(ss2);
  spt = strstr(ss1, ss2);
  if (spt != NULL) {
    spt = s1 + (spt - ss1);
  }
  freestring(&ss1);
  freestring(&ss2);
  return spt;
}


x86 assembly (clang, -O0):
<strstrx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <mkupper@plt>
mov    -0x20(%rbp),%rdi
call   1040 <mkupper@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11ae <strstrx+0x6e>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rdx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
lea    -0x18(%rbp),%rdi
call   1030 <freestring@plt>
lea    -0x20(%rbp),%rdi
call   1030 <freestring@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstrx>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
call   1050 <strdup@plt>
mov    %rax,%r12
mov    %rax,0x10(%rsp)
mov    %r15,%rdi
call   1050 <strdup@plt>
mov    %rax,%rbx
mov    %rax,0x8(%rsp)
mov    %r12,%rdi
call   1040 <mkupper@plt>
mov    %rbx,%rdi
call   1040 <mkupper@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <strstr@plt>
mov    %rax,%rbx
sub    %r12,%rax
add    %r14,%rax
test   %rbx,%rbx
cmovne %rax,%rbx
lea    0x10(%rsp),%rdi
call   1030 <freestring@plt>
lea    0x8(%rsp),%rdi
call   1030 <freestring@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @strstrx(i8* %0, i8* nocapture %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = bitcast i8** %3 to i8*
%6 = bitcast i8** %4 to i8*
%7 = tail call i8* @strdup(i8* %0)
store i8* %7, i8** %3
%8 = tail call i8* @strdup(i8* %1)
store i8* %8, i8** %4
%9 = tail call i32 @mkupper(i8* %7)
%10 = tail call i32 @mkupper(i8* %8)
%11 = tail call i8* @strstr(i8* dereferenceable(1) %7, i8* dereferenceable(1) %8)
%12 = icmp eq i8* %11, null
%13 = ptrtoint i8* %11 to i64
%14 = ptrtoint i8* %7 to i64
%15 = sub i64 %13, %14
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = select i1 %12, i8* null, i8* %16
%18 = call i32 @freestring(i8** %3)
%19 = call i32 @freestring(i8** %4)
ret i8* %17
}