#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 fnSearchChar(char *, char, int);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  char acText[30], ch;
  int iLen, iPos;
  printf("\nEnter the string\n");
  gets(acText);
  printf("\nEnter the character\n");
  scanf("%c", &ch);
  for (iLen = 0; acText[iLen] != '\0'; iLen++)
    ;
  iPos = fnSearchChar(acText, ch, iLen - 1);
  if (-1 == iPos)
    printf("\nCharacter not found\n");
  else
    printf("\nCharacter found at position : %d\n", iPos + 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1040 <gets@plt>
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeae(%rip),%rdi
lea    -0x31(%rbp),%rsi
call   1060 <scanf@plt>
movl   $0x0,-0x38(%rbp)
movslq -0x38(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     11b0 <main+0x70>
jmp    11a2 <main+0x62>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    118b <main+0x4b>
lea    -0x30(%rbp),%rdi
mov    -0x31(%rbp),%al
mov    -0x38(%rbp),%edx
sub    $0x1,%edx
movsbl %al,%esi
call   1050 <fnSearchChar@plt>
mov    %eax,-0x3c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x3c(%rbp),%eax
jne    11e9 <main+0xa9>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fd <main+0xbd>
mov    -0x3c(%rbp),%esi
add    $0x1,%esi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
lea    0xeca(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <gets@plt>
lea    0xec3(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7f(%rip),%rdi
lea    0xf(%rsp),%rsi
call   1070 <scanf@plt>
mov    $0xfffffffe,%edx
add    $0x1,%edx
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
jne    1190 <main+0x40>
movsbl 0xf(%rsp),%esi
lea    0x10(%rsp),%rdi
call   1060 <fnSearchChar@plt>
cmp    $0xffffffff,%eax
je     11c5 <main+0x75>
add    $0x1,%eax
lea    0xe49(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11d1 <main+0x81>
lea    0xe81(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"\0AEnter the string\0A\00"
@.str.1 = [22 x i8] c"\0AEnter the character\0A\00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [22 x i8] c"\0ACharacter not found\0A\00"
@.str.4 = [35 x i8] c"\0ACharacter found at position : %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [30 x i8]
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%8 = call i32 @gets(i8* %7)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %3)
store i32 0, i32* %4
br label %11
11: ; preds = %19, %0
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %11
br label %19
19: ; preds = %18
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %11
22: ; preds = %11
%23 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%24 = load i8, i8* %3
%25 = load i32, i32* %4
%26 = sub nsw i32 %25, 1
%27 = call i32 @fnSearchChar(i8* %23, i8 signext %24, i32 %26)
store i32 %27, i32* %5
%28 = load i32, i32* %5
%29 = icmp eq i32 -1, %28
br i1 %29, label %30, label %32
30: ; preds = %22
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %36
32: ; preds = %22
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %32, %30
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"%c\00"
@.str.4 = [35 x i8] c"\0ACharacter found at position : %d\0A\00"
@str = [18 x i8] c"\0AEnter the string\00"
@str.5 = [21 x i8] c"\0AEnter the character\00"
@str.6 = [21 x i8] c"\0ACharacter not found\00"
define i32 @main() {
%1 = alloca [30 x i8]
%2 = alloca i8
%3 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%5 = call i32 @gets(i8* %3)
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.5, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %8
8: ; preds = %8, %0
%9 = phi i64 [ %13, %8 ], [ 0, %0 ]
%10 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
%13 = add nuw i64 %9, 1
br i1 %12, label %14, label %8
14: ; preds = %8
%15 = trunc i64 %9 to i32
%16 = load i8, i8* %2
%17 = add nsw i32 %15, -1
%18 = call i32 @fnSearchChar(i8* %3, i8 signext %16, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.6, i64 0, i64 0))
br label %25
22: ; preds = %14
%23 = add nuw nsw i32 %18, 1
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %22, %20
ret i32 0
}