#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 *);
int main(void) {
  char haystack[] = "the quick brown fox jumps over the lazy dog";
  printf("%s\n", haystack);
  char *found = strstr(haystack, "fox");
  if (found) {
    printf("%s\n", found);
    found[0] = 'P';
    found[1] = 'I';
    found[2] = 'G';
  } else
    printf("No match was found\n");
  printf("%s\n", haystack);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xeb6(%rip),%rsi
mov    $0x2c,%edx
call   1040 <memcpy@plt>
lea    -0x30(%rbp),%rsi
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
lea    0xebf(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11b3 <main+0x83>
mov    -0x38(%rbp),%rsi
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
movb   $0x50,(%rax)
mov    -0x38(%rbp),%rax
movb   $0x49,0x1(%rax)
mov    -0x38(%rbp),%rax
movb   $0x47,0x2(%rax)
jmp    11c1 <main+0x91>
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
movups 0xef0(%rip),%xmm0
movups %xmm0,0x1c(%rsp)
movaps 0xed8(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xebc(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xed2(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strstr@plt>
test   %rax,%rax
je     117d <main+0x5d>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <puts@plt>
movw   $0x4950,(%rbx)
movb   $0x47,0x2(%rbx)
jmp    1189 <main+0x69>
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.haystack = [44 x i8] c"the quick brown fox jumps over the lazy dog\00"
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [4 x i8] c"fox\00"
@.str.2 = [20 x i8] c"No match was found\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [44 x i8]
%3 = alloca i8*
store i32 0, i32* %1
%4 = bitcast [44 x i8]* %2 to i8*
%5 = getelementptr inbounds [44 x i8], [44 x i8]* %2, i64 0, i64 0
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = getelementptr inbounds [44 x i8], [44 x i8]* %2, i64 0, i64 0
%8 = call i8* @strstr(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %20
11: ; preds = %0
%12 = load i8*, i8** %3
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 0
store i8 80, i8* %15
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8 73, i8* %17
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 2
store i8 71, i8* %19
br label %22
20: ; preds = %0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20, %11
%23 = getelementptr inbounds [44 x i8], [44 x i8]* %2, i64 0, i64 0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %23)
ret i32 0
}

LLVM IR (-O2):
@__const.main.haystack = [44 x i8] c"the quick brown fox jumps over the lazy dog\00"
@.str.1 = [4 x i8] c"fox\00"
@str = [19 x i8] c"No match was found\00"
define i32 @main() {
%1 = alloca [44 x i8]
%2 = getelementptr inbounds [44 x i8], [44 x i8]* %1, i64 0, i64 0
%3 = call i32 @puts(i8* %2)
%4 = call i8* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %10, label %6
6: ; preds = %0
%7 = call i32 @puts(i8* %4)
store i8 80, i8* %4
%8 = getelementptr inbounds i8, i8* %4, i64 1
store i8 73, i8* %8
%9 = getelementptr inbounds i8, i8* %4, i64 2
store i8 71, i8* %9
br label %12
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %12
12: ; preds = %10, %6
%13 = call i32 @puts(i8* %2)
ret i32 0
}