#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 EXIT_SUCCESS;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
char *strchr(char *, char);
int string_match(char *, char *);
int main(void) {
  char pattern[12], text[12];
  char *p;
  int bestPosition;
  printf("please enter pattern string (max %d chars): ", 12 - 2);
  fgets(text, 12, stdin);
  p = strchr(text, '\n');
  *p = '\0';
  printf("please enter text string (max %d chars): ", 12 - 2);
  fgets(pattern, 12, stdin);
  p = strchr(pattern, '\n');
  *p = '\0';
  if ((bestPosition = string_match(text, pattern)) > -1) {
    printf("\nThe best match found in: %d\n", bestPosition);
  } else {
    printf("\nNo match found\n");
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0xa,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1c(%rbp),%rdi
mov    0x2e7b(%rip),%rax
mov    (%rax),%edx
mov    $0xc,%esi
call   1050 <fgets@plt>
lea    -0x1c(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
lea    0xe94(%rip),%rdi
mov    $0xa,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x10(%rbp),%rdi
mov    0x2e38(%rip),%rax
mov    (%rax),%edx
mov    $0xc,%esi
call   1050 <fgets@plt>
lea    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x1c(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <string_match@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
jle    1204 <main+0xc4>
mov    -0x2c(%rbp),%esi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1212 <main+0xd2>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xea2(%rip),%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e77(%rip),%rbx
mov    (%rbx),%edx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   1060 <fgets@plt>
mov    %r14,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
movb   $0x0,(%rax)
lea    0xe93(%rip),%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%edx
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
movb   $0x0,(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <string_match@plt>
test   %eax,%eax
js     11eb <main+0x9b>
lea    0xe77(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11f7 <main+0xa7>
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [45 x i8] c"please enter pattern string (max %d chars): \00"
@stdin = global i32 0
@.str.1 = [42 x i8] c"please enter text string (max %d chars): \00"
@.str.2 = [30 x i8] c"\0AThe best match found in: %d\0A\00"
@.str.3 = [17 x i8] c"\0ANo match found\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [12 x i8]
%3 = alloca [12 x i8]
%4 = alloca i8*
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 10)
%7 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %7, i32 12, i32 %8)
%10 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%11 = call i8* @strchr(i8* %10, i8 signext 10)
store i8* %11, i8** %4
%12 = load i8*, i8** %4
store i8 0, i8* %12
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 10)
%14 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%15 = load i32, i32* @stdin
%16 = call i32 @fgets(i8* %14, i32 12, i32 %15)
%17 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%18 = call i8* @strchr(i8* %17, i8 signext 10)
store i8* %18, i8** %4
%19 = load i8*, i8** %4
store i8 0, i8* %19
%20 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%21 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%22 = call i32 @string_match(i8* %20, i8* %21)
store i32 %22, i32* %5
%23 = icmp sgt i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %0
%25 = load i32, i32* %5
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %29
27: ; preds = %0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %27, %24
%30 = load i32, i32* @EXIT_SUCCESS
ret i32 %30
}

LLVM IR (-O2):
@.str = [45 x i8] c"please enter pattern string (max %d chars): \00"
@stdin = global i32 0
@.str.1 = [42 x i8] c"please enter text string (max %d chars): \00"
@.str.2 = [30 x i8] c"\0AThe best match found in: %d\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [16 x i8] c"\0ANo match found\00"
define i32 @main() {
%1 = alloca [12 x i8]
%2 = alloca [12 x i8]
%3 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 10)
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %4, i32 12, i32 %6)
%8 = call i8* @strchr(i8* %4, i8 signext 10)
store i8 0, i8* %8
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 10)
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %3, i32 12, i32 %10)
%12 = call i8* @strchr(i8* %3, i8 signext 10)
store i8 0, i8* %12
%13 = call i32 @string_match(i8* %4, i8* %3)
%14 = icmp sgt i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %13)
br label %19
17: ; preds = %0
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %19
19: ; preds = %17, %15
%20 = load i32, i32* @EXIT_SUCCESS
ret i32 %20
}