#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 *);
int /*<<< orphan*/ *strchr(char const *, char);
void fig08_20() {
  const char *string = "This is a test";
  char character1 = 'a';
  char character2 = 'z';
  if (strchr(string, character1) != NULL) {
    printf("\'%c\' was found in \"%s\".\n", character1, string);
  } else {
    printf("\'%c\' was not found in \"%s\".\n", character2, string);
  }
  if (strchr(string, character2) != NULL) {
    printf("\'%c\' was found in \"%s\". \n", character2, string);
  } else {
    printf("\'%c\' was not found in \"%s\".\n", character2, string);
  }
}


x86 assembly (clang, -O0):
<fig08_20>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rax
mov    %rax,-0x8(%rbp)
movb   $0x61,-0x9(%rbp)
movb   $0x7a,-0xa(%rbp)
mov    -0x8(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     116d <fig08_20+0x4d>
mov    -0x9(%rbp),%al
mov    -0x8(%rbp),%rdx
lea    0xeaf(%rip),%rdi
movsbl %al,%esi
call   1040 <printf@plt>
jmp    1183 <fig08_20+0x63>
mov    -0xa(%rbp),%al
mov    -0x8(%rbp),%rdx
lea    0xead(%rip),%rdi
movsbl %al,%esi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
movsbl -0xa(%rbp),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     11b5 <fig08_20+0x95>
mov    -0xa(%rbp),%al
mov    -0x8(%rbp),%rdx
lea    0xe9d(%rip),%rdi
movsbl %al,%esi
call   1040 <printf@plt>
jmp    11cb <fig08_20+0xab>
mov    -0xa(%rbp),%al
mov    -0x8(%rbp),%rdx
lea    0xe65(%rip),%rdi
movsbl %al,%esi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig08_20>:
push   %rbx
lea    0xed8(%rip),%rdi
mov    $0x61,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     114c <fig08_20+0x2c>
lea    0xed1(%rip),%rdi
lea    0xebb(%rip),%rdx
mov    $0x61,%esi
jmp    115f <fig08_20+0x3f>
lea    0xed5(%rip),%rdi
lea    0xea6(%rip),%rdx
mov    $0x7a,%esi
call   1040 <printf@plt>
lea    0xe95(%rip),%rbx
mov    %rbx,%rdi
mov    $0x7a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
lea    0xea6(%rip),%rax
lea    0xebc(%rip),%rdi
cmove  %rax,%rdi
mov    $0x7a,%esi
mov    %rbx,%rdx
pop    %rbx
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"This is a test\00"
@.str.1 = [25 x i8] c"'%c' was found in \22%s\22.\0A\00"
@.str.2 = [29 x i8] c"'%c' was not found in \22%s\22.\0A\00"
@.str.3 = [26 x i8] c"'%c' was found in \22%s\22. \0A\00"
define void @fig08_20() {
%1 = alloca i8*
%2 = alloca i8
%3 = alloca i8
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %1
store i8 97, i8* %2
store i8 122, i8* %3
%4 = load i8*, i8** %1
%5 = load i8, i8* %2
%6 = call i32* @strchr(i8* %4, i8 signext %5)
%7 = icmp ne i32* %6, null
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = load i8, i8* %2
%10 = load i8*, i8** %1
%11 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8 signext %9, i8* %10)
br label %16
12: ; preds = %0
%13 = load i8, i8* %3
%14 = load i8*, i8** %1
%15 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8 signext %13, i8* %14)
br label %16
16: ; preds = %12, %8
%17 = load i8*, i8** %1
%18 = load i8, i8* %3
%19 = call i32* @strchr(i8* %17, i8 signext %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i8, i8* %3
%23 = load i8*, i8** %1
%24 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8 signext %22, i8* %23)
br label %29
25: ; preds = %16
%26 = load i8, i8* %3
%27 = load i8*, i8** %1
%28 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8 signext %26, i8* %27)
br label %29
29: ; preds = %25, %21
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"This is a test\00"
@.str.1 = [25 x i8] c"'%c' was found in \22%s\22.\0A\00"
@.str.2 = [29 x i8] c"'%c' was not found in \22%s\22.\0A\00"
@.str.3 = [26 x i8] c"'%c' was found in \22%s\22. \0A\00"
define void @fig08_20() {
%1 = tail call i32* @strchr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8 signext 97)
%2 = icmp eq i32* %1, null
br i1 %2, label %5, label %3
3: ; preds = %0
%4 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8 signext 97, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %7
5: ; preds = %0
%6 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8 signext 122, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %3
%8 = tail call i32* @strchr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8 signext 122)
%9 = icmp eq i32* %8, null
%10 = select i1 %9, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0)
%11 = tail call i32 @printf(i8* %10, i8 signext 122, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
ret void
}