#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 *, char const *, char *, char const *,
                          char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strstr(char const *, char const *);
void fig08_25() {
  const char *string1 = "abcdabcdef";
  const char *string2 = "def";
  printf("%s%s\n%s%s\n\n%s\n%s%s\n", "string1 = ", string1,
         "string2 = ", string2, "The reminder of string1 beginning with the",
         "first occurrence of string2 is: ", strstr(string1, string2));
}


x86 assembly (clang, -O0):
<fig08_25>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xed1(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    0xecd(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strstr@plt>
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%r8
lea    0xea1(%rip),%rdi
lea    0xeae(%rip),%rsi
lea    0xeb2(%rip),%rcx
lea    0xeb6(%rip),%r9
lea    0xeda(%rip),%r10
mov    %r10,(%rsp)
mov    %eax,0x8(%rsp)
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig08_25>:
push   %r14
push   %rbx
push   %rax
lea    0xed5(%rip),%rbx
lea    0xed5(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strstr@plt>
lea    0xf1c(%rip),%r10
lea    0xec0(%rip),%rdi
lea    0xecd(%rip),%rsi
lea    0xed1(%rip),%rcx
lea    0xed5(%rip),%r9
mov    %rbx,%rdx
mov    %r14,%r8
push   %rax
push   %r10
call   1030 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"abcdabcdef\00"
@.str.1 = [4 x i8] c"def\00"
@.str.2 = [20 x i8] c"%s%s\0A%s%s\0A\0A%s\0A%s%s\0A\00"
@.str.3 = [11 x i8] c"string1 = \00"
@.str.4 = [11 x i8] c"string2 = \00"
@.str.5 = [43 x i8] c"The reminder of string1 beginning with the\00"
@.str.6 = [33 x i8] c"first occurrence of string2 is: \00"
define void @fig08_25() {
%1 = alloca i8*
%2 = alloca i8*
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %2
%3 = load i8*, i8** %1
%4 = load i8*, i8** %2
%5 = load i8*, i8** %1
%6 = load i8*, i8** %2
%7 = call i32 @strstr(i8* %5, i8* %6)
%8 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %4, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i32 %7)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"abcdabcdef\00"
@.str.1 = [4 x i8] c"def\00"
@.str.2 = [20 x i8] c"%s%s\0A%s%s\0A\0A%s\0A%s%s\0A\00"
@.str.3 = [11 x i8] c"string1 = \00"
@.str.4 = [11 x i8] c"string2 = \00"
@.str.5 = [43 x i8] c"The reminder of string1 beginning with the\00"
@.str.6 = [33 x i8] c"first occurrence of string2 is: \00"
define void @fig08_25() {
%1 = tail call i32 @strstr(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i32 %1)
ret void
}