#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 FindExpression(char *, char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
char *strchr(char *, char);
int main() {
  printf("Podaj docelowy ciag znakow: \n");
  char *BaseText = (char *)malloc(255 * sizeof(*BaseText));
  fgets(BaseText, 255, stdin);
  *strchr(BaseText, '\n') = '\0';
  printf("Podaj fraze do wyszukania: \n");
  char *DestText = (char *)malloc(255 * sizeof(*DestText));
  fgets(DestText, 255, stdin);
  *strchr(DestText, '\n') = '\0';
  int FoundIndex = FindExpression(BaseText, DestText);
  if (FoundIndex >= 0) {
    printf("Znaleziono wystapienie podanego ciagu pod indeksem %d\n",
           FoundIndex);
  } else {
    printf("Nie znaleziono wystapienia podanego ciagu\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xff,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e62(%rip),%rax
mov    (%rax),%edx
mov    $0xff,%esi
call   1050 <fgets@plt>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
movb   $0x0,(%rax)
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xff,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e1e(%rip),%rax
mov    (%rax),%edx
mov    $0xff,%esi
call   1050 <fgets@plt>
mov    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <FindExpression@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1217 <main+0xc7>
mov    -0x1c(%rbp),%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1225 <main+0xd5>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xecb(%rip),%rdi
call   1030 <puts@plt>
mov    $0xff,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    0x2e63(%rip),%r15
mov    (%r15),%edx
mov    %rax,%rdi
mov    $0xff,%esi
call   1060 <fgets@plt>
mov    %r14,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
movb   $0x0,(%rax)
lea    0xea8(%rip),%rdi
call   1030 <puts@plt>
mov    $0xff,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    (%r15),%edx
mov    %rax,%rdi
mov    $0xff,%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   1080 <FindExpression@plt>
test   %eax,%eax
js     11ff <main+0x9f>
lea    0xe0c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    120b <main+0xab>
lea    0xe6a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Podaj docelowy ciag znakow: \0A\00"
@stdin = global i32 0
@.str.1 = [29 x i8] c"Podaj fraze do wyszukania: \0A\00"
@.str.2 = [55 x i8] c"Znaleziono wystapienie podanego ciagu pod indeksem %d\0A\00"
@.str.3 = [43 x i8] c"Nie znaleziono wystapienia podanego ciagu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%6 = call i64 @malloc(i32 255)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %2
%8 = load i8*, i8** %2
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %8, i32 255, i32 %9)
%11 = load i8*, i8** %2
%12 = call i8* @strchr(i8* %11, i8 signext 10)
store i8 0, i8* %12
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%14 = call i64 @malloc(i32 255)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %3
%16 = load i8*, i8** %3
%17 = load i32, i32* @stdin
%18 = call i32 @fgets(i8* %16, i32 255, i32 %17)
%19 = load i8*, i8** %3
%20 = call i8* @strchr(i8* %19, i8 signext 10)
store i8 0, i8* %20
%21 = load i8*, i8** %2
%22 = load i8*, i8** %3
%23 = call i32 @FindExpression(i8* %21, i8* %22)
store i32 %23, i32* %4
%24 = load i32, i32* %4
%25 = icmp sge i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %0
%27 = load i32, i32* %4
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i32 %27)
br label %31
29: ; preds = %0
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %29, %26
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.2 = [55 x i8] c"Znaleziono wystapienie podanego ciagu pod indeksem %d\0A\00"
@str = [29 x i8] c"Podaj docelowy ciag znakow: \00"
@str.4 = [28 x i8] c"Podaj fraze do wyszukania: \00"
@str.5 = [42 x i8] c"Nie znaleziono wystapienia podanego ciagu\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%2 = tail call i64 @malloc(i32 255)
%3 = inttoptr i64 %2 to i8*
%4 = load i32, i32* @stdin
%5 = tail call i32 @fgets(i8* %3, i32 255, i32 %4)
%6 = tail call i8* @strchr(i8* dereferenceable(1) %3, i8 signext 10)
store i8 0, i8* %6
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.4, i64 0, i64 0))
%8 = tail call i64 @malloc(i32 255)
%9 = inttoptr i64 %8 to i8*
%10 = load i32, i32* @stdin
%11 = tail call i32 @fgets(i8* %9, i32 255, i32 %10)
%12 = tail call i8* @strchr(i8* dereferenceable(1) %9, i8 signext 10)
store i8 0, i8* %12
%13 = tail call i32 @FindExpression(i8* %3, i8* %9)
%14 = icmp sgt i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i32 %13)
br label %19
17: ; preds = %0
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.5, i64 0, i64 0))
br label %19
19: ; preds = %17, %15
ret i32 0
}