#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 /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, char, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
void ex4() {
  char str1[255], carac;
  int verify = 0;
  puts("Informe uma frase:");
  fflush(stdin);
  gets(str1);
  puts("Informe um caracter:");
  scanf("%c", &carac);
  for (int x = 0; x < strlen(str1); x++) {
    if (str1[x] == carac) {
      printf("caracter: %c encontrado na posicao: %d\n", carac, x);
      verify = 1;
    }
  }
  if (verify == 0) {
    printf("caracter: %c nao encontrado na frase.\n", carac);
  }
}


x86 assembly (clang, -O0):
<ex4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x108(%rbp)
lea    0xe84(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    -0x100(%rbp),%rdi
call   1060 <gets@plt>
lea    0xe71(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7a(%rip),%rdi
lea    -0x101(%rbp),%rsi
call   1080 <scanf@plt>
movl   $0x0,-0x10c(%rbp)
mov    -0x10c(%rbp),%eax
mov    %eax,-0x110(%rbp)
lea    -0x100(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x110(%rbp),%eax
cmp    %ecx,%eax
jge    124a <ex4+0xea>
movslq -0x10c(%rbp),%rax
movsbl -0x100(%rbp,%rax,1),%eax
ff
movsbl -0x101(%rbp),%ecx
cmp    %ecx,%eax
jne    1231 <ex4+0xd1>
mov    -0x101(%rbp),%al
mov    -0x10c(%rbp),%edx
lea    0xe0e(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x108(%rbp)
jmp    1236 <ex4+0xd6>
mov    -0x10c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10c(%rbp)
jmp    11c4 <ex4+0x64>
cmpl   $0x0,-0x108(%rbp)
jne    126c <ex4+0x10c>
lea    0xdf5(%rip),%rdi
movsbl -0x101(%rbp),%esi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ex4>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x118,%rsp
lea    0xe8c(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <gets@plt>
lea    0xe78(%rip),%rdi
call   1030 <puts@plt>
lea    0xe81(%rip),%rdi
lea    0xf(%rsp),%rsi
call   1080 <scanf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1208 <ex4+0xa8>
lea    0xe67(%rip),%r14
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    11e3 <ex4+0x83>
nop
add    $0x1,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    1204 <ex4+0xa4>
movzbl 0x10(%rsp,%rbx,1),%eax
cmp    0xf(%rsp),%al
jne    11d0 <ex4+0x70>
movsbl %al,%esi
mov    %r14,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebp
jmp    11d0 <ex4+0x70>
test   %ebp,%ebp
jne    121b <ex4+0xbb>
movsbl 0xf(%rsp),%esi
lea    0xe3f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Informe uma frase:\00"
@stdin = global i32 0
@.str.1 = [21 x i8] c"Informe um caracter:\00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [40 x i8] c"caracter: %c encontrado na posicao: %d\0A\00"
@.str.4 = [39 x i8] c"caracter: %c nao encontrado na frase.\0A\00"
define void @ex4() {
%1 = alloca [255 x i8]
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %3
%5 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i32 @fflush(i32 %6)
%8 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%9 = call i32 @gets(i8* %8)
%10 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
store i32 0, i32* %4
br label %12
12: ; preds = %31, %0
%13 = load i32, i32* %4
%14 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %34
17: ; preds = %12
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = load i8, i8* %2
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %22, %24
br i1 %25, label %26, label %30
26: ; preds = %17
%27 = load i8, i8* %2
%28 = load i32, i32* %4
%29 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8 signext %27, i32 %28)
store i32 1, i32* %3
br label %30
30: ; preds = %26, %17
br label %31
31: ; preds = %30
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %12
34: ; preds = %12
%35 = load i32, i32* %3
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i8, i8* %2
%39 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8 signext %38)
br label %40
40: ; preds = %37, %34
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"Informe uma frase:\00"
@stdin = global i32 0
@.str.1 = [21 x i8] c"Informe um caracter:\00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [40 x i8] c"caracter: %c encontrado na posicao: %d\0A\00"
@.str.4 = [39 x i8] c"caracter: %c nao encontrado na frase.\0A\00"
define void @ex4() {
%1 = alloca [255 x i8]
%2 = alloca i8
%3 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @stdin
%6 = tail call i32 @fflush(i32 %5)
%7 = call i32 @gets(i8* %3)
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%10 = call i32 @strlen(i8* %3)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %14, label %30
12: ; preds = %24
%13 = icmp eq i32 %25, 0
br i1 %13, label %30, label %33
14: ; preds = %0, %24
%15 = phi i64 [ %26, %24 ], [ 0, %0 ]
%16 = phi i32 [ %25, %24 ], [ 0, %0 ]
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 %15
%18 = load i8, i8* %17
%19 = load i8, i8* %2
%20 = icmp eq i8 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = trunc i64 %15 to i32
%23 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8 signext %18, i32 %22)
br label %24
24: ; preds = %14, %21
%25 = phi i32 [ 1, %21 ], [ %16, %14 ]
%26 = add nuw nsw i64 %15, 1
%27 = call i32 @strlen(i8* %3)
%28 = sext i32 %27 to i64
%29 = icmp slt i64 %26, %28
br i1 %29, label %14, label %12
30: ; preds = %0, %12
%31 = load i8, i8* %2
%32 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8 signext %31)
br label %33
33: ; preds = %30, %12
ret void
}