#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*/ __fpurge(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main() {
  char frase[50], palavra[50];
  int i, j = 0, len_frase, len_palavra, x = 1, aparece = 0, ocorrencia = 0;
  printf("Digite uma frase: ");
  scanf("%[^\n]s", frase);
  __fpurge(stdin);
  printf("Digite uma palavra para ser verificada na frase: ");
  scanf("%s", palavra);
  len_frase = strlen(frase);
  len_palavra = strlen(palavra);
  for (i = j; i < len_frase; i++) {
    if (palavra[x - 1] == frase[i]) {
      aparece++;
    }
    if (x == len_palavra) {
      if (aparece == len_palavra) {
        ocorrencia++;
      }
      aparece = 0;
      x = 0;
      j++;
      i = j - 1;
    }
    x++;
  }
  printf("\n'%s' aparece %d vezes em '%s'\n", palavra, ocorrencia, frase);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x88(%rbp)
movl   $0x1,-0x94(%rbp)
movl   $0x0,-0x98(%rbp)
movl   $0x0,-0x9c(%rbp)
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xe80(%rip),%rdi
call   1060 <scanf@plt>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
call   1030 <__fpurge@plt>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x80(%rbp),%rsi
lea    0xe8d(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x8c(%rbp)
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x90(%rbp)
mov    -0x88(%rbp),%eax
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%eax
cmp    -0x8c(%rbp),%eax
jge    12bb <main+0x17b>
mov    -0x94(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x80(%rbp,%rax,1),%eax
movslq -0x84(%rbp),%rcx
movsbl -0x40(%rbp,%rcx,1),%ecx
cmp    %ecx,%eax
jne    1233 <main+0xf3>
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
mov    -0x94(%rbp),%eax
cmp    -0x90(%rbp),%eax
jne    1298 <main+0x158>
mov    -0x98(%rbp),%eax
cmp    -0x90(%rbp),%eax
jne    1266 <main+0x126>
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
movl   $0x0,-0x98(%rbp)
movl   $0x0,-0x94(%rbp)
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
mov    -0x88(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x84(%rbp)
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    11ee <main+0xae>
lea    -0x80(%rbp),%rsi
mov    -0x9c(%rbp),%edx
lea    -0x40(%rbp),%rcx
lea    0xd7f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
lea    0xeaa(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeac(%rip),%rdi
mov    %rsp,%rbp
mov    %rbp,%rsi
call   1060 <scanf@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
call   1030 <__fpurge@plt>
lea    0xe93(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb7(%rip),%rdi
lea    0x40(%rsp),%r14
mov    %r14,%rsi
call   1060 <scanf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %r12d,%r12d
jle    1210 <main+0xd0>
mov    $0x1,%edx
xor    %r15d,%r15d
xor    %ebx,%ebx
xor    %r9d,%r9d
xor    %r8d,%r8d
jmp    11ef <main+0xaf>
nopl   0x0(%rax)
xor    %ecx,%ecx
cmp    %eax,%edi
sete   %cl
add    %ecx,%r15d
add    $0x1,%r8d
xor    %edx,%edx
mov    %r8d,%r9d
xor    %edi,%edi
add    $0x1,%edx
mov    %edi,%ebx
cmp    %r12d,%r9d
jge    1210 <main+0xd0>
movslq %edx,%rbp
movzbl -0x1(%rbp,%r14,1),%ecx
movslq %r9d,%rsi
xor    %edi,%edi
cmp    (%rsp,%rsi,1),%cl
sete   %dil
add    %ebx,%edi
cmp    %eax,%ebp
je     11d0 <main+0x90>
add    $0x1,%r9d
jmp    11e5 <main+0xa5>
lea    0xe38(%rip),%rdi
lea    0x40(%rsp),%rsi
mov    %rsp,%rcx
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Digite uma frase: \00"
@.str.1 = [7 x i8] c"%[^\0A]s\00"
@stdin = global i32 0
@.str.2 = [50 x i8] c"Digite uma palavra para ser verificada na frase: \00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [32 x i8] c"\0A'%s' aparece %d vezes em '%s'\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [50 x i8]
%3 = alloca [50 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
store i32 1, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%13 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @stdin
%15 = call i32 @__fpurge(i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
%17 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %6
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
store i32 %22, i32* %7
%23 = load i32, i32* %5
store i32 %23, i32* %4
br label %24
24: ; preds = %63, %0
%25 = load i32, i32* %4
%26 = load i32, i32* %6
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %66
28: ; preds = %24
%29 = load i32, i32* %8
%30 = sub nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = load i32, i32* %4
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %34, %39
br i1 %40, label %41, label %44
41: ; preds = %28
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
br label %44
44: ; preds = %41, %28
%45 = load i32, i32* %8
%46 = load i32, i32* %7
%47 = icmp eq i32 %45, %46
br i1 %47, label %48, label %60
48: ; preds = %44
%49 = load i32, i32* %9
%50 = load i32, i32* %7
%51 = icmp eq i32 %49, %50
br i1 %51, label %52, label %55
52: ; preds = %48
%53 = load i32, i32* %10
%54 = add nsw i32 %53, 1
store i32 %54, i32* %10
br label %55
55: ; preds = %52, %48
store i32 0, i32* %9
store i32 0, i32* %8
%56 = load i32, i32* %5
%57 = add nsw i32 %56, 1
store i32 %57, i32* %5
%58 = load i32, i32* %5
%59 = sub nsw i32 %58, 1
store i32 %59, i32* %4
br label %60
60: ; preds = %55, %44
%61 = load i32, i32* %8
%62 = add nsw i32 %61, 1
store i32 %62, i32* %8
br label %63
63: ; preds = %60
%64 = load i32, i32* %4
%65 = add nsw i32 %64, 1
store i32 %65, i32* %4
br label %24
66: ; preds = %24
%67 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%68 = load i32, i32* %10
%69 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %67, i32 %68, i8* %69)
%71 = load i32, i32* %1
ret i32 %71
}

LLVM IR (-O2):
@.str = [19 x i8] c"Digite uma frase: \00"
@.str.1 = [7 x i8] c"%[^\0A]s\00"
@stdin = global i32 0
@.str.2 = [50 x i8] c"Digite uma palavra para ser verificada na frase: \00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [32 x i8] c"\0A'%s' aparece %d vezes em '%s'\0A\00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = alloca [50 x i8]
%3 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%7 = load i32, i32* @stdin
%8 = call i32 @__fpurge(i32 %7)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%11 = call i32 @strlen(i8* %3)
%12 = call i32 @strlen(i8* %4)
%13 = icmp sgt i32 %11, 0
br i1 %13, label %14, label %46
14: ; preds = %0, %38
%15 = phi i32 [ %43, %38 ], [ 0, %0 ]
%16 = phi i32 [ %42, %38 ], [ 0, %0 ]
%17 = phi i32 [ %44, %38 ], [ 1, %0 ]
%18 = phi i32 [ %39, %38 ], [ 0, %0 ]
%19 = phi i32 [ %40, %38 ], [ 0, %0 ]
%20 = add nsw i32 %17, -1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i32 %18 to i64
%25 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %23, %26
%28 = zext i1 %27 to i32
%29 = add nsw i32 %16, %28
%30 = icmp eq i32 %17, %12
br i1 %30, label %33, label %31
31: ; preds = %14
%32 = add nsw i32 %18, 1
br label %38
33: ; preds = %14
%34 = icmp eq i32 %29, %12
%35 = zext i1 %34 to i32
%36 = add nsw i32 %15, %35
%37 = add nsw i32 %19, 1
br label %38
38: ; preds = %31, %33
%39 = phi i32 [ %32, %31 ], [ %37, %33 ]
%40 = phi i32 [ %19, %31 ], [ %37, %33 ]
%41 = phi i32 [ %17, %31 ], [ 0, %33 ]
%42 = phi i32 [ %29, %31 ], [ 0, %33 ]
%43 = phi i32 [ %15, %31 ], [ %36, %33 ]
%44 = add nsw i32 %41, 1
%45 = icmp slt i32 %39, %11
br i1 %45, label %14, label %46
46: ; preds = %38, %0
%47 = phi i32 [ 0, %0 ], [ %43, %38 ]
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %4, i32 %47, i8* %3)
ret i32 0
}