#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*/ assert(int);
char *strstr(char *, char *);
int main() {
  char buf[] = "foo bar baz";
  assert(strstr(buf, "bar") == buf + 4);
  assert(strstr(buf, "baz") == buf + 8);
  assert(strstr(buf, "barney") == 0);
  assert(strstr(buf, "foo") == buf);
  assert(strstr(buf, "") == buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xec8(%rip),%eax
mov    %eax,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
lea    0xebe(%rip),%rsi
call   1040 <strstr@plt>
lea    -0x10(%rbp),%rcx
add    $0x4,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
lea    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1040 <strstr@plt>
lea    -0x10(%rbp),%rcx
add    $0x8,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
lea    -0x10(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1040 <strstr@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
lea    -0x10(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1040 <strstr@plt>
lea    -0x10(%rbp),%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
lea    -0x10(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   1040 <strstr@plt>
lea    -0x10(%rbp),%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movabs $0x20726162206f6f66,%rax
61 72 20
mov    %rax,0x8(%rsp)
movl   $0x7a6162,0x10(%rsp)
lea    0x10(%rsp),%r14
lea    0xec2(%rip),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strstr@plt>
lea    0xc(%rsp),%rcx
xor    %edi,%edi
cmp    %rcx,%rax
sete   %dil
call   1030 <assert@plt>
lea    0xe97(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strstr@plt>
xor    %edi,%edi
cmp    %r14,%rax
sete   %dil
call   1030 <assert@plt>
lea    0xe82(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strstr@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1030 <assert@plt>
mov    $0x6f66,%eax
xor    0x8(%rsp),%eax
movzbl 0xa(%rsp),%ecx
xor    $0x6f,%ecx
xor    %edi,%edi
or     %ax,%cx
sete   %dil
call   1030 <assert@plt>
mov    $0x1,%edi
call   1030 <assert@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.buf = [12 x i8] c"foo bar baz\00"
@.str = [4 x i8] c"bar\00"
@.str.1 = [4 x i8] c"baz\00"
@.str.2 = [7 x i8] c"barney\00"
@.str.3 = [4 x i8] c"foo\00"
@.str.4 = [1 x i8] zeroinitializer
define i32 @main() {
%1 = alloca i32
%2 = alloca [12 x i8]
store i32 0, i32* %1
%3 = bitcast [12 x i8]* %2 to i8*
%4 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%5 = call i8* @strstr(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds i8, i8* %6, i64 4
%8 = icmp eq i8* %5, %7
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%12 = call i8* @strstr(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%13 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%14 = getelementptr inbounds i8, i8* %13, i64 8
%15 = icmp eq i8* %12, %14
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%19 = call i8* @strstr(i8* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i8* %19, null
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%24 = call i8* @strstr(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%25 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%26 = icmp eq i8* %24, %25
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%30 = call i8* @strstr(i8* %29, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%31 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%32 = icmp eq i8* %30, %31
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
ret i32 0
}

LLVM IR (-O2):
@__const.main.buf = [12 x i8] c"foo bar baz\00"
@.str = [4 x i8] c"bar\00"
@.str.1 = [4 x i8] c"baz\00"
@.str.2 = [7 x i8] c"barney\00"
@.str.3 = [4 x i8] c"foo\00"
define i32 @main() {
%1 = alloca [12 x i8]
%2 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%3 = call i8* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 4
%5 = icmp eq i8* %3, %4
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = call i8* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%9 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 8
%10 = icmp eq i8* %8, %9
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = call i8* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i8* %13, null
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = call i32 @bcmp(i8* dereferenceable(3) %2, i8* dereferenceable(3) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 3)
%18 = icmp eq i32 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = call i32 @assert(i32 1)
ret i32 0
}