#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 *, ...);
void *strchr(char const *, char);
int main() {
  char str[] = "I love this world!";
  char *p = strchr(str, 'I');
  printf("%s\n", p);
  printf("%c\n", *p);
  printf("%d\n", (int)(p - str));
  p = strchr(str, 'l');
  printf("%s\n", p);
  printf("%c\n", *p);
  printf("%d\n", (int)(p - str));
  const char *str2 = "Try not. Do, or do not. There is no try.";
  char target = 'T';
  const char *result = str2;
  while ((result = strchr(result, target)) != NULL) {
    printf("Found '%c' starting at '%s'\n", target, result);
    ++result;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xec4(%rip),%ax
mov    %ax,-0x10(%rbp)
mov    0xebc(%rip),%al
mov    %al,-0xe(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x49,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
movsbl (%rax),%esi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
lea    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
mov    $0x6c,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
movsbl (%rax),%esi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
lea    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe17(%rip),%rax
mov    %rax,-0x30(%rbp)
movb   $0x54,-0x31(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
movsbl -0x31(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     125a <main+0x13a>
movsbl -0x31(%rbp),%esi
mov    -0x40(%rbp),%rdx
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1218 <main+0xf8>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movaps 0xebe(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x21646c,0xf(%rsp)
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x49,%esi
call   1040 <strchr@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <puts@plt>
movsbl (%rbx),%esi
lea    0xea0(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
sub    %r15d,%ebx
lea    0xe90(%rip),%r12
mov    %r12,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    $0x6c,%esi
call   1040 <strchr@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <puts@plt>
movsbl (%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
sub    %r15d,%ebx
mov    %r12,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe4d(%rip),%rbx
lea    0xe6f(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    $0x54,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x54,%esi
call   1040 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11e0 <main+0xb0>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.str = [19 x i8] c"I love this world!\00"
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [4 x i8] c"%c\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [41 x i8] c"Try not. Do, or do not. There is no try.\00"
@.str.4 = [29 x i8] c"Found '%c' starting at '%s'\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [19 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8*
store i32 0, i32* %1
%7 = bitcast [19 x i8]* %2 to i8*
%8 = getelementptr inbounds [19 x i8], [19 x i8]* %2, i64 0, i64 0
%9 = call i8* @strchr(i8* %8, i8 signext 73)
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load i8*, i8** %3
%17 = getelementptr inbounds [19 x i8], [19 x i8]* %2, i64 0, i64 0
%18 = ptrtoint i8* %16 to i64
%19 = ptrtoint i8* %17 to i64
%20 = sub i64 %18, %19
%21 = trunc i64 %20 to i32
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds [19 x i8], [19 x i8]* %2, i64 0, i64 0
%24 = call i8* @strchr(i8* %23, i8 signext 108)
store i8* %24, i8** %3
%25 = load i8*, i8** %3
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = load i8*, i8** %3
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = load i8*, i8** %3
%32 = getelementptr inbounds [19 x i8], [19 x i8]* %2, i64 0, i64 0
%33 = ptrtoint i8* %31 to i64
%34 = ptrtoint i8* %32 to i64
%35 = sub i64 %33, %34
%36 = trunc i64 %35 to i32
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %36)
store i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8** %4
store i8 84, i8* %5
%38 = load i8*, i8** %4
store i8* %38, i8** %6
br label %39
39: ; preds = %44, %0
%40 = load i8*, i8** %6
%41 = load i8, i8* %5
%42 = call i8* @strchr(i8* %40, i8 signext %41)
store i8* %42, i8** %6
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %51
44: ; preds = %39
%45 = load i8, i8* %5
%46 = sext i8 %45 to i32
%47 = load i8*, i8** %6
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %46, i8* %47)
%49 = load i8*, i8** %6
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %6
br label %39
51: ; preds = %39
ret i32 0
}

LLVM IR (-O2):
@__const.main.str = [19 x i8] c"I love this world!\00"
@.str.1 = [4 x i8] c"%c\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [41 x i8] c"Try not. Do, or do not. There is no try.\00"
@.str.4 = [29 x i8] c"Found '%c' starting at '%s'\0A\00"
define i32 @main() {
%1 = alloca [19 x i8]
%2 = getelementptr inbounds [19 x i8], [19 x i8]* %1, i64 0, i64 0
%3 = call i8* @strchr(i8* %2, i8 signext 73)
%4 = call i32 @puts(i8* dereferenceable(1) %3)
%5 = load i8, i8* %3
%6 = sext i8 %5 to i32
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = ptrtoint i8* %3 to i64
%9 = ptrtoint [19 x i8]* %1 to i64
%10 = sub i64 %8, %9
%11 = trunc i64 %10 to i32
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = call i8* @strchr(i8* %2, i8 signext 108)
%14 = call i32 @puts(i8* dereferenceable(1) %13)
%15 = load i8, i8* %13
%16 = sext i8 %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = ptrtoint i8* %13 to i64
%19 = sub i64 %18, %9
%20 = trunc i64 %19 to i32
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %0, %22
%23 = phi i8* [ %26, %22 ], [ getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), %0 ]
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 84, i8* %23)
%25 = getelementptr inbounds i8, i8* %23, i64 1
%26 = call i8* @strchr(i8* dereferenceable(1) %25, i8 signext 84)
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %22
28: ; preds = %22
ret i32 0
}