#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 *mystrstr(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
void test2() {
  char *s = "Hello world";
  char *sub = mystrstr("Hello world", "wo");
  printf("%s\n", sub);
  sub = mystrstr("Hello world", "He");
  printf("%s\n", sub);
  sub = mystrstr("Hello world", "ldf");
  printf("%s\n", sub ? sub : "NULL");
  sub = mystrstr("Hello world", "aaa");
  printf("%s\n", sub ? sub : "NULL");
}


x86 assembly (clang, -O0):
<test2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xed1(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    0xec6(%rip),%rdi
lea    0xecb(%rip),%rsi
call   1030 <mystrstr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xeba(%rip),%rdi
call   1040 <printf@plt>
lea    0xe9f(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1030 <mystrstr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe93(%rip),%rdi
call   1040 <printf@plt>
lea    0xe78(%rip),%rdi
lea    0xe87(%rip),%rsi
call   1030 <mystrstr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b0 <test2+0x90>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11c0 <test2+0xa0>
lea    0xe63(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11c0 <test2+0xa0>
mov    -0x18(%rbp),%rsi
lea    0xe44(%rip),%rdi
call   1040 <printf@plt>
lea    0xe29(%rip),%rdi
lea    0xe41(%rip),%rsi
call   1030 <mystrstr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11ff <test2+0xdf>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    120f <test2+0xef>
lea    0xe14(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    120f <test2+0xef>
mov    -0x20(%rbp),%rsi
lea    0xdf5(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test2>:
push   %r15
push   %r14
push   %rbx
lea    0xed4(%rip),%r15
lea    0xed9(%rip),%rsi
mov    %r15,%rdi
call   1030 <mystrstr@plt>
lea    0xecd(%rip),%r14
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
lea    0xebf(%rip),%rsi
mov    %r15,%rdi
call   1030 <mystrstr@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
lea    0xea8(%rip),%rsi
mov    %r15,%rdi
call   1030 <mystrstr@plt>
test   %rax,%rax
lea    0xe9a(%rip),%rbx
cmove  %rbx,%rax
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
lea    0xe89(%rip),%rsi
mov    %r15,%rdi
call   1030 <mystrstr@plt>
test   %rax,%rax
cmovne %rax,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"Hello world\00"
@.str.1 = [3 x i8] c"wo\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [3 x i8] c"He\00"
@.str.4 = [4 x i8] c"ldf\00"
@.str.5 = [5 x i8] c"NULL\00"
@.str.6 = [4 x i8] c"aaa\00"
define void @test2() {
%1 = alloca i8*
%2 = alloca i8*
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %1
%3 = call i8* @mystrstr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %3, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%6 = call i8* @mystrstr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i8* %6, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%9 = call i8* @mystrstr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
store i8* %9, i8** %2
%10 = load i8*, i8** %2
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = load i8*, i8** %2
br label %15
14: ; preds = %0
br label %15
15: ; preds = %14, %12
%16 = phi i8* [ %13, %12 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), %14 ]
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = call i8* @mystrstr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
store i8* %18, i8** %2
%19 = load i8*, i8** %2
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = load i8*, i8** %2
br label %24
23: ; preds = %15
br label %24
24: ; preds = %23, %21
%25 = phi i8* [ %22, %21 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), %23 ]
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %25)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"Hello world\00"
@.str.1 = [3 x i8] c"wo\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [3 x i8] c"He\00"
@.str.4 = [4 x i8] c"ldf\00"
@.str.5 = [5 x i8] c"NULL\00"
@.str.6 = [4 x i8] c"aaa\00"
define void @test2() {
%1 = tail call i8* @mystrstr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%3 = tail call i8* @mystrstr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%4 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%5 = tail call i8* @mystrstr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%6 = icmp eq i8* %5, null
%7 = select i1 %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %5
%8 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%9 = tail call i8* @mystrstr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%10 = icmp eq i8* %9, null
%11 = select i1 %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %9
%12 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %11)
ret void
}