#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 EOF;
int getchar();
int /*<<< orphan*/ printf(char *, ...);
int strindex(char *, char *);
int main(void) {
  int ret = 0;
  int c = 0;
  int i = 0;
  char s[1000 + 1], t[1000 + 1];
  printf("\nGive me the string in which you want to search!\n\t");
  while ((i < 1000) && ((c = getchar()) != EOF) && (c != '\n')) {
    s[i++] = c;
  }
  s[++i] = '\0';
  i = 0;
  printf("\nGive me the string that I should look for!\n\t");
  while ((i < 1000) && ((c = getchar()) != EOF) && (c != '\n')) {
    t[i++] = c;
  }
  t[++i] = '\0';
  i = strindex(s, t);
  if (i > 0)
    printf("The last apeareace of '%s' in '%s' is at location %d", t, s, i);
  else
    printf("The string '%s' doesn't appear in '%s!", t, s);
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x800,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
cmpl   $0x3e8,-0x10(%rbp)
mov    %al,-0x7f1(%rbp)
jge    11aa <main+0x7a>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
mov    0x2e59(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x7f1(%rbp)
je     11aa <main+0x7a>
cmpl   $0xa,-0xc(%rbp)
setne  %al
mov    %al,-0x7f1(%rbp)
mov    -0x7f1(%rbp),%al
test   $0x1,%al
jne    11bd <main+0x8d>
jmp    11db <main+0xab>
mov    -0xc(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x10(%rbp)
cltq
mov    %cl,-0x400(%rbp,%rax,1)
jmp    1165 <main+0x35>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
cltq
movb   $0x0,-0x400(%rbp,%rax,1)
movl   $0x0,-0x10(%rbp)
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
cmpl   $0x3e8,-0x10(%rbp)
mov    %al,-0x7f2(%rbp)
jge    1248 <main+0x118>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
mov    0x2dbb(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x7f2(%rbp)
je     1248 <main+0x118>
cmpl   $0xa,-0xc(%rbp)
setne  %al
mov    %al,-0x7f2(%rbp)
mov    -0x7f2(%rbp),%al
test   $0x1,%al
jne    125b <main+0x12b>
jmp    1279 <main+0x149>
mov    -0xc(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x10(%rbp)
cltq
mov    %cl,-0x7f0(%rbp,%rax,1)
jmp    1203 <main+0xd3>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
cltq
movb   $0x0,-0x7f0(%rbp,%rax,1)
lea    -0x400(%rbp),%rdi
lea    -0x7f0(%rbp),%rsi
call   1050 <strindex@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    12d0 <main+0x1a0>
lea    -0x7f0(%rbp),%rsi
lea    -0x400(%rbp),%rdx
mov    -0x10(%rbp),%ecx
lea    0xd9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ec <main+0x1bc>
lea    -0x7f0(%rbp),%rsi
lea    -0x400(%rbp),%rdx
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x800,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x7e8,%rsp
lea    0xebf(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e99(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     118a <main+0x5a>
cmp    (%r14),%eax
je     118a <main+0x5a>
mov    %al,0x3f0(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0x3e8,%rbx
jne    1160 <main+0x30>
mov    $0x3e8,%ebx
add    $0x1,%ebx
movb   $0x0,0x3f0(%rsp,%rbx,1)
lea    0xe97(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     11d6 <main+0xa6>
cmp    (%r14),%eax
je     11d6 <main+0xa6>
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0x3e8,%rbx
jne    11b0 <main+0x80>
mov    $0x3e8,%ebx
add    $0x1,%ebx
movb   $0x0,(%rsp,%rbx,1)
lea    0x3f0(%rsp),%rdi
mov    %rsp,%rsi
call   1050 <strindex@plt>
test   %eax,%eax
jle    120e <main+0xde>
lea    0xe69(%rip),%rdi
mov    %rsp,%rsi
lea    0x3f0(%rsp),%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1227 <main+0xf7>
lea    0xe81(%rip),%rdi
mov    %rsp,%rsi
lea    0x3f0(%rsp),%rdx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x7e8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [51 x i8] c"\0AGive me the string in which you want to search!\0A\09\00"
@EOF = global i32 0
@.str.1 = [46 x i8] c"\0AGive me the string that I should look for!\0A\09\00"
@.str.2 = [53 x i8] c"The last apeareace of '%s' in '%s' is at location %d\00"
@.str.3 = [39 x i8] c"The string '%s' doesn't appear in '%s!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1001 x i8]
%6 = alloca [1001 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %20, %0
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 1000
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = call i32 (...) @getchar()
store i32 %12, i32* %3
%13 = load i32, i32* @EOF
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* %3
%17 = icmp ne i32 %16, 10
br label %18
18: ; preds = %15, %11, %8
%19 = phi i1 [ false, %11 ], [ false, %8 ], [ %17, %15 ]
br i1 %19, label %20, label %27
20: ; preds = %18
%21 = load i32, i32* %3
%22 = trunc i32 %21 to i8
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 %25
store i8 %22, i8* %26
br label %8
27: ; preds = %18
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 %30
store i8 0, i8* %31
store i32 0, i32* %4
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %45, %27
%34 = load i32, i32* %4
%35 = icmp slt i32 %34, 1000
br i1 %35, label %36, label %43
36: ; preds = %33
%37 = call i32 (...) @getchar()
store i32 %37, i32* %3
%38 = load i32, i32* @EOF
%39 = icmp ne i32 %37, %38
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i32, i32* %3
%42 = icmp ne i32 %41, 10
br label %43
43: ; preds = %40, %36, %33
%44 = phi i1 [ false, %36 ], [ false, %33 ], [ %42, %40 ]
br i1 %44, label %45, label %52
45: ; preds = %43
%46 = load i32, i32* %3
%47 = trunc i32 %46 to i8
%48 = load i32, i32* %4
%49 = add nsw i32 %48, 1
store i32 %49, i32* %4
%50 = sext i32 %48 to i64
%51 = getelementptr inbounds [1001 x i8], [1001 x i8]* %6, i64 0, i64 %50
store i8 %47, i8* %51
br label %33
52: ; preds = %43
%53 = load i32, i32* %4
%54 = add nsw i32 %53, 1
store i32 %54, i32* %4
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [1001 x i8], [1001 x i8]* %6, i64 0, i64 %55
store i8 0, i8* %56
%57 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 0
%58 = getelementptr inbounds [1001 x i8], [1001 x i8]* %6, i64 0, i64 0
%59 = call i32 @strindex(i8* %57, i8* %58)
store i32 %59, i32* %4
%60 = load i32, i32* %4
%61 = icmp sgt i32 %60, 0
br i1 %61, label %62, label %67
62: ; preds = %52
%63 = getelementptr inbounds [1001 x i8], [1001 x i8]* %6, i64 0, i64 0
%64 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 0
%65 = load i32, i32* %4
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i8* %63, i8* %64, i32 %65)
br label %71
67: ; preds = %52
%68 = getelementptr inbounds [1001 x i8], [1001 x i8]* %6, i64 0, i64 0
%69 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 0
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %68, i8* %69)
br label %71
71: ; preds = %67, %62
%72 = load i32, i32* %2
ret i32 %72
}

LLVM IR (-O2):
@.str = [51 x i8] c"\0AGive me the string in which you want to search!\0A\09\00"
@EOF = global i32 0
@.str.1 = [46 x i8] c"\0AGive me the string that I should look for!\0A\09\00"
@.str.2 = [53 x i8] c"The last apeareace of '%s' in '%s' is at location %d\00"
@.str.3 = [39 x i8] c"The string '%s' doesn't appear in '%s!\00"
define i32 @main() {
%1 = alloca [1001 x i8]
%2 = alloca [1001 x i8]
%3 = getelementptr inbounds [1001 x i8], [1001 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [1001 x i8], [1001 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %0, %13
%7 = phi i64 [ 0, %0 ], [ %15, %13 ]
%8 = tail call i32 (...) @getchar()
%9 = load i32, i32* @EOF
%10 = icmp ne i32 %8, %9
%11 = icmp ne i32 %8, 10
%12 = and i1 %11, %10
br i1 %12, label %13, label %18
13: ; preds = %6
%14 = trunc i32 %8 to i8
%15 = add nuw nsw i64 %7, 1
%16 = getelementptr inbounds [1001 x i8], [1001 x i8]* %1, i64 0, i64 %7
store i8 %14, i8* %16
%17 = icmp eq i64 %15, 1000
br i1 %17, label %18, label %6
18: ; preds = %13, %6
%19 = phi i64 [ 1000, %13 ], [ %7, %6 ]
%20 = add nuw i64 %19, 1
%21 = and i64 %20, 4294967295
%22 = getelementptr inbounds [1001 x i8], [1001 x i8]* %1, i64 0, i64 %21
store i8 0, i8* %22
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %18, %31
%25 = phi i64 [ 0, %18 ], [ %33, %31 ]
%26 = tail call i32 (...) @getchar()
%27 = load i32, i32* @EOF
%28 = icmp ne i32 %26, %27
%29 = icmp ne i32 %26, 10
%30 = and i1 %29, %28
br i1 %30, label %31, label %36
31: ; preds = %24
%32 = trunc i32 %26 to i8
%33 = add nuw nsw i64 %25, 1
%34 = getelementptr inbounds [1001 x i8], [1001 x i8]* %2, i64 0, i64 %25
store i8 %32, i8* %34
%35 = icmp eq i64 %33, 1000
br i1 %35, label %36, label %24
36: ; preds = %31, %24
%37 = phi i64 [ 1000, %31 ], [ %25, %24 ]
%38 = add nuw i64 %37, 1
%39 = and i64 %38, 4294967295
%40 = getelementptr inbounds [1001 x i8], [1001 x i8]* %2, i64 0, i64 %39
store i8 0, i8* %40
%41 = call i32 @strindex(i8* %3, i8* %4)
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %36
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i8* %4, i8* %3, i32 %41)
br label %47
45: ; preds = %36
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %4, i8* %3)
br label %47
47: ; preds = %45, %43
ret i32 0
}