#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*/ fgets(char *, int, int /*<<< orphan*/);
char *find_char(char *, char *);
int /*<<< orphan*/ printf(char *, char *, char);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
int main(void) {
  char srs[100];
  char chr[10];
  puts("\n\tSay something nice:");
  fgets(srs, 100, stdin);
  puts("\tNow what do you want to search for in it?");
  fgets(chr, 10, stdin);
  int x = 0;
  for (; srs[x] != '\0'; ++x)
    printf("%p says %c\n", &srs[x], srs[x]);
  char *temp = find_char(srs, chr);
  printf("\nThe first match is at %p - %c\n\n", temp, *temp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
call   1030 <puts@plt>
lea    -0x70(%rbp),%rdi
mov    0x2e7f(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1050 <fgets@plt>
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
lea    -0x7a(%rbp),%rdi
mov    0x2e5c(%rip),%rax
mov    (%rax),%edx
mov    $0xa,%esi
call   1050 <fgets@plt>
movl   $0x0,-0x80(%rbp)
movslq -0x80(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     11df <main+0x9f>
movslq -0x80(%rbp),%rax
lea    -0x70(%rbp),%rsi
add    %rax,%rsi
movslq -0x80(%rbp),%rax
lea    0xe7a(%rip),%rdi
movsbl -0x70(%rbp,%rax,1),%edx
call   1040 <printf@plt>
mov    -0x80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80(%rbp)
jmp    119f <main+0x5f>
lea    -0x70(%rbp),%rdi
lea    -0x7a(%rbp),%rsi
call   1060 <find_char@plt>
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rsi
mov    -0x88(%rbp),%rax
lea    0xe45(%rip),%rdi
movsbl (%rax),%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x78,%rsp
lea    0xeb2(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e8e(%rip),%r14
mov    (%r14),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1050 <fgets@plt>
lea    0xea0(%rip),%rdi
call   1030 <puts@plt>
mov    (%r14),%edx
lea    0x6(%rsp),%rdi
mov    $0xa,%esi
call   1050 <fgets@plt>
mov    0x10(%rsp),%al
test   %al,%al
je     11ba <main+0x7a>
lea    0xea5(%rip),%r14
nopl   0x0(%rax)
movsbl %al,%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    11a0 <main+0x60>
lea    0x10(%rsp),%rdi
lea    0x6(%rsp),%rsi
call   1060 <find_char@plt>
movsbl (%rax),%edx
lea    0xe7a(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [22 x i8] c"\0A\09Say something nice:\00"
@stdin = global i32 0
@.str.1 = [43 x i8] c"\09Now what do you want to search for in it?\00"
@.str.2 = [12 x i8] c"%p says %c\0A\00"
@.str.3 = [33 x i8] c"\0AThe first match is at %p - %c\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca [10 x i8]
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %1
%6 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %7, i32 100, i32 %8)
%10 = call i32 @puts(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%12 = load i32, i32* @stdin
%13 = call i32 @fgets(i8* %11, i32 10, i32 %12)
store i32 0, i32* %4
br label %14
14: ; preds = %30, %0
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %33
21: ; preds = %14
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %23
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %24, i8 signext %28)
br label %30
30: ; preds = %21
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %14
33: ; preds = %14
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%35 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%36 = call i8* @find_char(i8* %34, i8* %35)
store i8* %36, i8** %5
%37 = load i8*, i8** %5
%38 = load i8*, i8** %5
%39 = load i8, i8* %38
%40 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %37, i8 signext %39)
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"\0A\09Say something nice:\00"
@stdin = global i32 0
@.str.1 = [43 x i8] c"\09Now what do you want to search for in it?\00"
@.str.2 = [12 x i8] c"%p says %c\0A\00"
@.str.3 = [33 x i8] c"\0AThe first match is at %p - %c\0A\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %3, i32 100, i32 %6)
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %4, i32 10, i32 %9)
%11 = load i8, i8* %3
%12 = icmp eq i8 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %0, %13
%14 = phi i64 [ %18, %13 ], [ 0, %0 ]
%15 = phi i8 [ %20, %13 ], [ %11, %0 ]
%16 = phi i8* [ %19, %13 ], [ %3, %0 ]
%17 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %16, i8 signext %15)
%18 = add nuw i64 %14, 1
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %13
22: ; preds = %13, %0
%23 = call i8* @find_char(i8* %3, i8* %4)
%24 = load i8, i8* %23
%25 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %23, i8 signext %24)
ret i32 0
}