#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*/ fflush(int /*<<< orphan*/);
int position(char *, char, int, int);
int position_char(char *, char, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main(int argc, const char *argv[]) {
  char s[20];
  char c;
  int size, pos, pos2, y;
  printf("Digite a String: ");
  scanf("%[^\n]s", s);
  printf("Digite o caracter: ");
  scanf("\n%c", &c);
  size = strlen(s);
  pos = position_char(s, c, size);
  if (pos != -1) {
    printf("A caracter encontra-se na posicao = %d \n  ", pos);
  } else {
    printf("Caracter nao encontrado. \n ");
  }
  fflush(stdin);
  printf("Deseja procura a partir de qual posicao: ");
  scanf("\n%d", &pos2);
  size = strlen(s);
  y = position(s, c, size, pos2);
  if (y != -1) {
    printf("A caracter encontra-se na posicao = %d \n ", y);
  } else {
    printf("Caracter nao encontrado. \n ");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe82(%rip),%rdi
lea    -0x31(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x31(%rbp),%al
mov    -0x38(%rbp),%edx
movsbl %al,%esi
call   1080 <position_char@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
je     11f7 <main+0x97>
mov    -0x3c(%rbp),%esi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1205 <main+0xa5>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe7a(%rip),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x31(%rbp),%al
mov    -0x38(%rbp),%edx
mov    -0x40(%rbp),%ecx
movsbl %al,%esi
call   1050 <position@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
je     1277 <main+0x117>
mov    -0x44(%rbp),%esi
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1285 <main+0x125>
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
lea    0xe94(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe98(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
lea    0xe89(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe8f(%rip),%rdi
lea    0xb(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
movsbl 0xb(%rsp),%esi
mov    %rbx,%rdi
mov    %eax,%edx
call   1080 <position_char@plt>
cmp    $0xffffffff,%eax
je     11d8 <main+0x78>
lea    0xe64(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11e6 <main+0x86>
lea    0xe7d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    0xe7d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe99(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
movsbl 0xb(%rsp),%esi
mov    0xc(%rsp),%ecx
mov    %rbx,%rdi
mov    %eax,%edx
call   1050 <position@plt>
cmp    $0xffffffff,%eax
je     124c <main+0xec>
lea    0xe65(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    125a <main+0xfa>
lea    0xe09(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Digite a String: \00"
@.str.1 = [7 x i8] c"%[^\0A]s\00"
@.str.2 = [20 x i8] c"Digite o caracter: \00"
@.str.3 = [4 x i8] c"\0A%c\00"
@.str.4 = [43 x i8] c"A caracter encontra-se na posicao = %d \0A \00"
@.str.5 = [28 x i8] c"Caracter nao encontrado. \0A \00"
@stdin = global i32 0
@.str.6 = [42 x i8] c"Deseja procura a partir de qual posicao: \00"
@.str.7 = [4 x i8] c"\0A%d\00"
@.str.8 = [42 x i8] c"A caracter encontra-se na posicao = %d \0A \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [20 x i8]
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
store i32 %18, i32* %8
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%20 = load i8, i8* %7
%21 = load i32, i32* %8
%22 = call i32 @position_char(i8* %19, i8 signext %20, i32 %21)
store i32 %22, i32* %9
%23 = load i32, i32* %9
%24 = icmp ne i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %2
%26 = load i32, i32* %9
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %26)
br label %30
28: ; preds = %2
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %30
30: ; preds = %28, %25
%31 = load i32, i32* @stdin
%32 = call i32 @fflush(i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
%34 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32* %10)
%35 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%36 = call i32 @strlen(i8* %35)
store i32 %36, i32* %8
%37 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%38 = load i8, i8* %7
%39 = load i32, i32* %8
%40 = load i32, i32* %10
%41 = call i32 @position(i8* %37, i8 signext %38, i32 %39, i32 %40)
store i32 %41, i32* %11
%42 = load i32, i32* %11
%43 = icmp ne i32 %42, -1
br i1 %43, label %44, label %47
44: ; preds = %30
%45 = load i32, i32* %11
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.8, i64 0, i64 0), i32 %45)
br label %49
47: ; preds = %30
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %49
49: ; preds = %47, %44
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str = [18 x i8] c"Digite a String: \00"
@.str.1 = [7 x i8] c"%[^\0A]s\00"
@.str.2 = [20 x i8] c"Digite o caracter: \00"
@.str.3 = [4 x i8] c"\0A%c\00"
@.str.4 = [43 x i8] c"A caracter encontra-se na posicao = %d \0A \00"
@.str.5 = [28 x i8] c"Caracter nao encontrado. \0A \00"
@stdin = global i32 0
@.str.6 = [42 x i8] c"Deseja procura a partir de qual posicao: \00"
@.str.7 = [4 x i8] c"\0A%d\00"
@.str.8 = [42 x i8] c"A caracter encontra-se na posicao = %d \0A \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [20 x i8]
%4 = alloca i8
%5 = alloca i32
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%7 = bitcast i32* %5 to i8*
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%12 = call i32 @strlen(i8* %6)
%13 = load i8, i8* %4
%14 = call i32 @position_char(i8* %6, i8 signext %13, i32 %12)
%15 = icmp eq i32 %14, -1
br i1 %15, label %18, label %16
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %14)
br label %20
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %20
20: ; preds = %18, %16
%21 = load i32, i32* @stdin
%22 = call i32 @fflush(i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
%24 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32* %5)
%25 = call i32 @strlen(i8* %6)
%26 = load i8, i8* %4
%27 = load i32, i32* %5
%28 = call i32 @position(i8* %6, i8 signext %26, i32 %25, i32 %27)
%29 = icmp eq i32 %28, -1
br i1 %29, label %32, label %30
30: ; preds = %20
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.8, i64 0, i64 0), i32 %28)
br label %34
32: ; preds = %20
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %34
34: ; preds = %32, %30
ret i32 0
}