#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ find_substring(char *, int, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  char *input_string, *pattern;
  int len_input_string, len_pattern;
  printf("Enter the length of the input string:\n");
  scanf("%d", &len_input_string);
  printf("Enter the length of the pattern:\n");
  scanf("%d", &len_pattern);
  input_string = (char *)calloc(len_input_string + 1, sizeof(char));
  pattern = (char *)calloc(len_pattern + 1, sizeof(char));
  printf("Enter the input string:");
  scanf("%s", input_string);
  input_string[len_input_string] = 0;
  printf("Enter the pattern string:");
  scanf("%s", pattern);
  pattern[len_pattern] = 0;
  printf("The input string is: %s$\n", input_string);
  printf("The pattern is: %s$\n", pattern);
  find_substring(input_string, len_input_string, pattern, len_pattern);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec3(%rip),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea3(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rsi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%ecx
call   1050 <find_substring@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xf07(%rip),%rdi
call   1030 <puts@plt>
lea    0xe94(%rip),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <scanf@plt>
lea    0xf0b(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0xc(%rsp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r14
mov    0x8(%rsp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
lea    0xe3e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe48(%rip),%r15
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
movslq 0xc(%rsp),%rax
movb   $0x0,(%r14,%rax,1)
lea    0xe2d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
movslq 0x8(%rsp),%rax
movb   $0x0,(%rbx,%rax,1)
lea    0xe23(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe2c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%ecx
mov    %r14,%rdi
mov    %rbx,%rdx
call   1060 <find_substring@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Enter the length of the input string:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [34 x i8] c"Enter the length of the pattern:\0A\00"
@.str.3 = [24 x i8] c"Enter the input string:\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [26 x i8] c"Enter the pattern string:\00"
@.str.6 = [26 x i8] c"The input string is: %s$\0A\00"
@.str.7 = [21 x i8] c"The pattern is: %s$\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%10 = load i32, i32* %4
%11 = add nsw i32 %10, 1
%12 = call i64 @calloc(i32 %11, i32 1)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %2
%14 = load i32, i32* %5
%15 = add nsw i32 %14, 1
%16 = call i64 @calloc(i32 %15, i32 1)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %3
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%19 = load i8*, i8** %2
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %19)
%21 = load i8*, i8** %2
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 0, i8* %24
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%26 = load i8*, i8** %3
%27 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %26)
%28 = load i8*, i8** %3
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 0, i8* %31
%32 = load i8*, i8** %2
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %32)
%34 = load i8*, i8** %3
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i8* %34)
%36 = load i8*, i8** %2
%37 = load i32, i32* %4
%38 = load i8*, i8** %3
%39 = load i32, i32* %5
%40 = call i32 @find_substring(i8* %36, i32 %37, i8* %38, i32 %39)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [24 x i8] c"Enter the input string:\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [26 x i8] c"Enter the pattern string:\00"
@.str.6 = [26 x i8] c"The input string is: %s$\0A\00"
@.str.7 = [21 x i8] c"The pattern is: %s$\0A\00"
@str = [38 x i8] c"Enter the length of the input string:\00"
@str.8 = [33 x i8] c"Enter the length of the pattern:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.8, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %1
%10 = add nsw i32 %9, 1
%11 = call i64 @calloc(i32 %10, i32 1)
%12 = inttoptr i64 %11 to i8*
%13 = load i32, i32* %2
%14 = add nsw i32 %13, 1
%15 = call i64 @calloc(i32 %14, i32 1)
%16 = inttoptr i64 %15 to i8*
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %12)
%19 = load i32, i32* %1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %12, i64 %20
store i8 0, i8* %21
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %16)
%24 = load i32, i32* %2
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %16, i64 %25
store i8 0, i8* %26
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %12)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i8* %16)
%29 = load i32, i32* %1
%30 = load i32, i32* %2
%31 = call i32 @find_substring(i8* %12, i32 %29, i8* %16, i32 %30)
ret i32 0
}