#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ stdin;
char *strstr(char *, char *);
int main() {
  char padrao[52], mensagem[52];
  printf("Digite uma palavra:");
  fgets(mensagem, 51, stdin);
  printf("Digite o padrao a ser encontrado:");
  scanf("%s", padrao);
  printf("Palavra digitada: %s", mensagem);
  printf("Padrao digitado: %s", padrao);
  int aux = 0;
  char *tmp = mensagem;
  while ((tmp = strstr(tmp, padrao))) {
    aux++;
    tmp++;
  }
  if (aux > 0)
    printf("****Padrao encontrado %d vezes!****", aux);
  else
    printf("****Padrao nao encontrado!****");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2e7d(%rip),%rax
mov    (%rax),%edx
mov    $0x33,%esi
call   1040 <fgets@plt>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xeb8(%rip),%rdi
call   1050 <scanf@plt>
lea    -0x80(%rbp),%rsi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x84(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x90(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x90(%rbp)
cmp    $0x0,%rax
je     1215 <main+0xd5>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
mov    -0x90(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x90(%rbp)
jmp    11ce <main+0x8e>
cmpl   $0x0,-0x84(%rbp)
jle    123b <main+0xfb>
mov    -0x84(%rbp),%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1249 <main+0x109>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
lea    0xead(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e85(%rip),%rax
mov    (%rax),%edx
lea    0x40(%rsp),%r14
mov    %r14,%rdi
mov    $0x33,%esi
call   1040 <fgets@plt>
lea    0xe96(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xebc(%rip),%rdi
mov    %rsp,%r15
mov    %r15,%rsi
call   1050 <scanf@plt>
lea    0xe98(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe9c(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     11f9 <main+0xb9>
mov    %rsp,%r14
nopl   0x0(%rax)
add    $0x1,%ebx
add    $0x1,%rax
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
jne    11d0 <main+0x90>
lea    0xe71(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1207 <main+0xc7>
lea    0xe83(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Digite uma palavra:\00"
@stdin = global i32 0
@.str.1 = [34 x i8] c"Digite o padrao a ser encontrado:\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [21 x i8] c"Palavra digitada: %s\00"
@.str.4 = [20 x i8] c"Padrao digitado: %s\00"
@.str.5 = [36 x i8] c"****Padrao encontrado %d vezes!****\00"
@.str.6 = [31 x i8] c"****Padrao nao encontrado!****\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [52 x i8]
%3 = alloca [52 x i8]
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [52 x i8], [52 x i8]* %3, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %7, i32 51, i32 %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds [52 x i8], [52 x i8]* %2, i64 0, i64 0
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [52 x i8], [52 x i8]* %3, i64 0, i64 0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [52 x i8], [52 x i8]* %2, i64 0, i64 0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %15)
store i32 0, i32* %4
%17 = getelementptr inbounds [52 x i8], [52 x i8]* %3, i64 0, i64 0
store i8* %17, i8** %5
br label %18
18: ; preds = %23, %0
%19 = load i8*, i8** %5
%20 = getelementptr inbounds [52 x i8], [52 x i8]* %2, i64 0, i64 0
%21 = call i8* @strstr(i8* %19, i8* %20)
store i8* %21, i8** %5
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %5
br label %18
28: ; preds = %18
%29 = load i32, i32* %4
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* %4
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i32 %32)
br label %36
34: ; preds = %28
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
br label %36
36: ; preds = %34, %31
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@.str = [20 x i8] c"Digite uma palavra:\00"
@stdin = global i32 0
@.str.1 = [34 x i8] c"Digite o padrao a ser encontrado:\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [21 x i8] c"Palavra digitada: %s\00"
@.str.4 = [20 x i8] c"Padrao digitado: %s\00"
@.str.5 = [36 x i8] c"****Padrao encontrado %d vezes!****\00"
@.str.6 = [31 x i8] c"****Padrao nao encontrado!****\00"
define i32 @main() {
%1 = alloca [52 x i8]
%2 = alloca [52 x i8]
%3 = getelementptr inbounds [52 x i8], [52 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [52 x i8], [52 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %4, i32 51, i32 %6)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 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* %3)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %3)
%12 = call i8* @strstr(i8* dereferenceable(1) %4, i8* %3)
%13 = icmp eq i8* %12, null
br i1 %13, label %23, label %14
14: ; preds = %0, %14
%15 = phi i8* [ %19, %14 ], [ %12, %0 ]
%16 = phi i32 [ %17, %14 ], [ 0, %0 ]
%17 = add nuw nsw i32 %16, 1
%18 = getelementptr inbounds i8, i8* %15, i64 1
%19 = call i8* @strstr(i8* dereferenceable(1) %18, i8* %3)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %14
21: ; preds = %14
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i32 %17)
br label %25
23: ; preds = %0
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
br label %25
25: ; preds = %23, %21
ret i32 0
}