#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 find(char *, char);
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  char str1[1000], ch;
  printf("Enter the haystack \n");
  scanf("%s", str1);
  printf("Enter the Needle: ");
  getchar();
  ch = getchar();
  printf("Returned Value: %d \n", find(str1, ch));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x3f0(%rbp),%rsi
lea    0xea7(%rip),%rdi
call   1060 <scanf@plt>
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x3f1(%rbp)
lea    -0x3f0(%rbp),%rdi
movsbl -0x3f1(%rbp),%esi
call   1050 <find@plt>
mov    %eax,%esi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x3f0,%rsp
lea    0xecc(%rip),%rdi
call   1030 <puts@plt>
lea    0xe95(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1070 <scanf@plt>
lea    0xe86(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
movsbl %al,%esi
mov    %rbx,%rdi
call   1060 <find@plt>
lea    0xe72(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x3f0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Enter the haystack \0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [19 x i8] c"Enter the Needle: \00"
@.str.3 = [21 x i8] c"Returned Value: %d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x i8]
%3 = alloca i8
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%8 = call signext i8 (...) @getchar()
%9 = call signext i8 (...) @getchar()
store i8 %9, i8* %3
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%11 = load i8, i8* %3
%12 = call i32 @find(i8* %10, i8 signext %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %12)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [19 x i8] c"Enter the Needle: \00"
@.str.3 = [21 x i8] c"Returned Value: %d \0A\00"
@str = [20 x i8] c"Enter the haystack \00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%6 = call signext i8 (...) @getchar()
%7 = call signext i8 (...) @getchar()
%8 = call i32 @find(i8* %2, i8 signext %7)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %8)
ret i32 0
}