#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 getchar();
int /*<<< orphan*/ printf(char *, char *);
char *subString(char *, char *);
int main(int argc, char const *argv[]) {
  printf("%s", "Enter the source string:");
  int x;
  char buffer1[2048];
  char buffer2[2048];
  int i = 0;
  while ((x = getchar())) {
    if (x == '\n' || x == '\0') {
      break;
    } else {
      buffer1[i++] = x;
    }
  }
  buffer1[i] = 0;
  printf("%s", "Enter the substring:");
  i = 0;
  while ((x = getchar())) {
    if (x == '\n' || x == '\0') {
      break;
    } else {
      buffer2[i++] = x;
    }
  }
  buffer2[i] = 0;
  char *out = subString(buffer1, buffer2);
  if (out == NULL) {
    printf("%s\n", "Cannot find substring");
    return 0;
  }
  printf("Returned String:%s\n", out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb0(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1030 <printf@plt>
movl   $0x0,-0x1024(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     11b6 <main+0x86>
cmpl   $0xa,-0x14(%rbp)
je     118d <main+0x5d>
cmpl   $0x0,-0x14(%rbp)
jne    1192 <main+0x62>
jmp    11b6 <main+0x86>
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x1024(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x1024(%rbp)
cltq
mov    %cl,-0x820(%rbp,%rax,1)
jmp    1166 <main+0x36>
movslq -0x1024(%rbp),%rax
movb   $0x0,-0x820(%rbp,%rax,1)
lea    0xe34(%rip),%rdi
lea    0xe49(%rip),%rsi
call   1030 <printf@plt>
movl   $0x0,-0x1024(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     1232 <main+0x102>
cmpl   $0xa,-0x14(%rbp)
je     1209 <main+0xd9>
cmpl   $0x0,-0x14(%rbp)
jne    120e <main+0xde>
jmp    1232 <main+0x102>
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x1024(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x1024(%rbp)
cltq
mov    %cl,-0x1020(%rbp,%rax,1)
jmp    11e2 <main+0xb2>
movslq -0x1024(%rbp),%rax
movb   $0x0,-0x1020(%rbp,%rax,1)
lea    -0x820(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
call   1050 <subString@plt>
mov    %rax,-0x1030(%rbp)
cmpq   $0x0,-0x1030(%rbp)
jne    1288 <main+0x158>
lea    0xde7(%rip),%rdi
lea    0xdba(%rip),%rsi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a2 <main+0x172>
mov    -0x1030(%rbp),%rsi
lea    0xdb1(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x1000,%rsp
lea    0xec1(%rip),%rdi
lea    0xebd(%rip),%rsi
call   1030 <printf@plt>
xor    %ebx,%ebx
nopl   (%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
test   %eax,%eax
je     116d <main+0x3d>
cmp    $0xa,%eax
je     116d <main+0x3d>
mov    %al,0x800(%rsp,%rbx,1)
add    $0x1,%rbx
jmp    1150 <main+0x20>
mov    %ebx,%eax
movb   $0x0,0x800(%rsp,%rax,1)
lea    0xe82(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1030 <printf@plt>
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
test   %eax,%eax
je     11a9 <main+0x79>
cmp    $0xa,%eax
je     11a9 <main+0x79>
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
jmp    1190 <main+0x60>
mov    %ebx,%eax
movb   $0x0,(%rsp,%rax,1)
lea    0x800(%rsp),%rdi
mov    %rsp,%rsi
call   1050 <subString@plt>
test   %rax,%rax
je     11d0 <main+0xa0>
lea    0xe7c(%rip),%rdi
mov    %rax,%rsi
jmp    11de <main+0xae>
lea    0xe80(%rip),%rdi
lea    0xe53(%rip),%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1000,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [25 x i8] c"Enter the source string:\00"
@.str.2 = [21 x i8] c"Enter the substring:\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [22 x i8] c"Cannot find substring\00"
@.str.5 = [20 x i8] c"Returned String:%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [2048 x i8]
%8 = alloca [2048 x i8]
%9 = alloca i32
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %9
br label %12
12: ; preds = %29, %2
%13 = call i32 (...) @getchar()
store i32 %13, i32* %6
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %30
15: ; preds = %12
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, 10
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %18, %15
br label %30
22: ; preds = %18
%23 = load i32, i32* %6
%24 = trunc i32 %23 to i8
%25 = load i32, i32* %9
%26 = add nsw i32 %25, 1
store i32 %26, i32* %9
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 %27
store i8 %24, i8* %28
br label %29
29: ; preds = %22
br label %12
30: ; preds = %21, %12
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 %32
store i8 0, i8* %33
%34 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %9
br label %35
35: ; preds = %52, %30
%36 = call i32 (...) @getchar()
store i32 %36, i32* %6
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %53
38: ; preds = %35
%39 = load i32, i32* %6
%40 = icmp eq i32 %39, 10
br i1 %40, label %44, label %41
41: ; preds = %38
%42 = load i32, i32* %6
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %41, %38
br label %53
45: ; preds = %41
%46 = load i32, i32* %6
%47 = trunc i32 %46 to i8
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 1
store i32 %49, i32* %9
%50 = sext i32 %48 to i64
%51 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 %50
store i8 %47, i8* %51
br label %52
52: ; preds = %45
br label %35
53: ; preds = %44, %35
%54 = load i32, i32* %9
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 %55
store i8 0, i8* %56
%57 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%58 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%59 = call i8* @subString(i8* %57, i8* %58)
store i8* %59, i8** %10
%60 = load i8*, i8** %10
%61 = icmp eq i8* %60, null
br i1 %61, label %62, label %64
62: ; preds = %53
%63 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %67
64: ; preds = %53
%65 = load i8*, i8** %10
%66 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %65)
store i32 0, i32* %3
br label %67
67: ; preds = %64, %62
%68 = load i32, i32* %3
ret i32 %68
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [25 x i8] c"Enter the source string:\00"
@.str.2 = [21 x i8] c"Enter the substring:\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [22 x i8] c"Cannot find substring\00"
@.str.5 = [20 x i8] c"Returned String:%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2048 x i8]
%4 = alloca [2048 x i8]
%5 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
br label %8
8: ; preds = %11, %2
%9 = phi i64 [ %13, %11 ], [ 0, %2 ]
%10 = tail call i32 (...) @getchar()
switch i32 %10, label %11 [
i32 0, label %15
i32 10, label %15
]
11: ; preds = %8
%12 = trunc i32 %10 to i8
%13 = add nuw i64 %9, 1
%14 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %9
store i8 %12, i8* %14
br label %8
15: ; preds = %8, %8
%16 = and i64 %9, 4294967295
%17 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %16
store i8 0, i8* %17
%18 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %22, %15
%20 = phi i64 [ %24, %22 ], [ 0, %15 ]
%21 = tail call i32 (...) @getchar()
switch i32 %21, label %22 [
i32 0, label %26
i32 10, label %26
]
22: ; preds = %19
%23 = trunc i32 %21 to i8
%24 = add nuw i64 %20, 1
%25 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %20
store i8 %23, i8* %25
br label %19
26: ; preds = %19, %19
%27 = and i64 %20, 4294967295
%28 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %27
store i8 0, i8* %28
%29 = call i8* @subString(i8* %6, i8* %7)
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
br label %35
33: ; preds = %26
%34 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %29)
br label %35
35: ; preds = %33, %31
ret i32 0
}