#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 */
char const *strchr(char const *, char const);
int /*<<< orphan*/ string_empty(char const *);
char const *strstr(char const *, char const *);
const char *string_find(const char *string, const char *substring) {
  if (!string_empty(string) && !string_empty(substring)) {
    if (substring[1] != 0)
      return strstr(string, substring);
    else
      return strchr(string, substring[0]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<string_find>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <string_empty@plt>
cmp    $0x0,%eax
jne    11a4 <string_find+0x74>
mov    -0x18(%rbp),%rdi
call   1040 <string_empty@plt>
cmp    $0x0,%eax
jne    11a4 <string_find+0x74>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     118b <string_find+0x5b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x8(%rbp)
jmp    11ac <string_find+0x7c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
movsbl (%rax),%esi
call   1030 <strchr@plt>
mov    %rax,-0x8(%rbp)
jmp    11ac <string_find+0x7c>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_find>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <string_empty@plt>
test   %eax,%eax
jne    114f <string_find+0x1f>
mov    %r14,%rdi
call   1040 <string_empty@plt>
test   %eax,%eax
je     1159 <string_find+0x29>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
cmpb   $0x0,0x1(%r14)
je     1172 <string_find+0x42>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <strstr@plt>
movsbl (%r14),%esi
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <strchr@plt>

LLVM IR (-O0):
define i8* @string_find(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** %4
%7 = call i32 @string_empty(i8* %6)
%8 = icmp ne i32 %7, 0
br i1 %8, label %29, label %9
9: ; preds = %2
%10 = load i8*, i8** %5
%11 = call i32 @string_empty(i8* %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %29, label %13
13: ; preds = %9
%14 = load i8*, i8** %5
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = load i8*, i8** %4
%21 = load i8*, i8** %5
%22 = call i8* @strstr(i8* %20, i8* %21)
store i8* %22, i8** %3
br label %30
23: ; preds = %13
%24 = load i8*, i8** %4
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = call i8* @strchr(i8* %24, i8 signext %27)
store i8* %28, i8** %3
br label %30
29: ; preds = %9, %2
store i8* null, i8** %3
br label %30
30: ; preds = %29, %23, %19
%31 = load i8*, i8** %3
ret i8* %31
}

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