#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 *strstr(char *, char *);
void main() {
  char haystack[] = "hi hello how are you";
  char needle[] = "you";
  char *pos = strstr(haystack, needle);
  if (pos) {
    printf("There exists a substring\n");
  } else {
    printf("There is no substring\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xed1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xece(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xecc(%rip),%eax
mov    %eax,-0x10(%rbp)
mov    0xec7(%rip),%al
mov    %al,-0xc(%rbp)
mov    0xebf(%rip),%eax
mov    %eax,-0x24(%rbp)
lea    -0x20(%rbp),%rdi
lea    -0x24(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1186 <main+0x66>
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
jmp    1192 <main+0x72>
lea    0xea6(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
movaps 0xed5(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x756f7920657261,%rax
mov    %rax,0xd(%rsp)
lea    0xed0(%rip),%rsi
mov    %rsp,%rdi
call   1040 <strstr@plt>
test   %rax,%rax
lea    0xec2(%rip),%rax
lea    0xed1(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
@__const.main.haystack = [21 x i8] c"hi hello how are you\00"
@__const.main.needle = [4 x i8] c"you\00"
@.str = [26 x i8] c"There exists a substring\0A\00"
@.str.1 = [23 x i8] c"There is no substring\0A\00"
define void @main() {
%1 = alloca [21 x i8]
%2 = alloca [4 x i8]
%3 = alloca i8*
%4 = bitcast [21 x i8]* %1 to i8*
%5 = bitcast [4 x i8]* %2 to i8*
%6 = getelementptr inbounds [21 x i8], [21 x i8]* %1, i64 0, i64 0
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%8 = call i8* @strstr(i8* %6, i8* %7)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %15
13: ; preds = %0
%14 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %11
ret void
}

LLVM IR (-O2):
@__const.main.haystack = [21 x i8] c"hi hello how are you\00"
@__const.main.needle = [4 x i8] c"you\00"
@str = [22 x i8] c"There is no substring\00"
@str.2 = [25 x i8] c"There exists a substring\00"
define void @main() {
%1 = alloca [21 x i8]
%2 = getelementptr inbounds [21 x i8], [21 x i8]* %1, i64 0, i64 0
%3 = call i8* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @__const.main.needle, i64 0, i64 0))
%4 = icmp eq i8* %3, null
%5 = select i1 %4, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @str.2, i64 0, i64 0)
%6 = call i32 @puts(i8* dereferenceable(1) %5)
ret void
}