#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 index_common(char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
void main() {
  char *S, *T;
  char s1[80] = "A STRING SEARCHING EXAMPLE CONSISTING OF SIMPLE TEXT";
  char t1[80] = "STING";
  char s2[80] = "00000000000000000000000000000000000000000000000000001";
  char t2[80] = "00000001";
  int pos;
  S = "lixiang";
  T = "xi";
  printf("Print the string S and T:\n");
  printf("S=%s\nT=%s\n", S, T);
  pos = 1;
  printf("\nFind the position of T in the S from pos %d is %d\n", pos,
         index_common(S, T, pos));
  printf("\nPrint the new string S and T:\n");
  printf("Len=%d, S1=%s\nLen=%d, T1=%s\n", strlen(s1), s1, strlen(t1), t1);
  printf("\nFind the position of T in the S from pos %d is %d\n", pos,
         index_common(S, T, pos));
  printf("\nPrint the new string S and T:\n");
  printf("Len=%d, S=%s\nLen=%d, T=%s\n", strlen(s2), s2, strlen(t2), t2);
  printf("\nFind the position of T in the S from pos %d is %d\n", pos,
         index_common(s2, t2, pos));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
lea    -0x60(%rbp),%rdi
lea    0xe9a(%rip),%rsi
mov    $0x50,%edx
call   1060 <memcpy@plt>
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1050 <memset@plt>
movb   $0x53,-0xb0(%rbp)
movb   $0x54,-0xaf(%rbp)
movb   $0x49,-0xae(%rbp)
movb   $0x4e,-0xad(%rbp)
movb   $0x47,-0xac(%rbp)
lea    -0x100(%rbp),%rdi
lea    0xe9c(%rip),%rsi
mov    $0x50,%edx
call   1060 <memcpy@plt>
lea    -0x150(%rbp),%rdi
lea    0xed4(%rip),%rsi
mov    $0x50,%edx
call   1060 <memcpy@plt>
lea    0xf13(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    0xf10(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xf08(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xf0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x154(%rbp)
mov    -0x154(%rbp),%eax
mov    %eax,-0x178(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x154(%rbp),%edx
call   1070 <index_common@plt>
mov    -0x178(%rbp),%esi
mov    %eax,%edx
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x174(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x170(%rbp)
lea    -0xb0(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x174(%rbp),%esi
mov    -0x170(%rbp),%rdx
mov    %eax,%ecx
lea    -0xb0(%rbp),%r8
lea    0xed5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x154(%rbp),%eax
mov    %eax,-0x168(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x154(%rbp),%edx
call   1070 <index_common@plt>
mov    -0x168(%rbp),%esi
mov    %eax,%edx
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x100(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x164(%rbp)
lea    -0x100(%rbp),%rax
mov    %rax,-0x160(%rbp)
lea    -0x150(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x164(%rbp),%esi
mov    -0x160(%rbp),%rdx
mov    %eax,%ecx
lea    -0x150(%rbp),%r8
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x154(%rbp),%eax
mov    %eax,-0x158(%rbp)
lea    -0x100(%rbp),%rdi
lea    -0x150(%rbp),%rsi
mov    -0x154(%rbp),%edx
call   1070 <index_common@plt>
mov    -0x158(%rbp),%esi
mov    %eax,%edx
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x148,%rsp
movaps 0xee8(%rip),%xmm0
movaps %xmm0,0x130(%rsp)
movaps 0xec9(%rip),%xmm0
movaps %xmm0,0x120(%rsp)
movaps 0xeaa(%rip),%xmm0
movaps %xmm0,0x110(%rsp)
movaps 0xe8b(%rip),%xmm0
movaps %xmm0,0x100(%rsp)
movaps 0xe6c(%rip),%xmm0
movaps %xmm0,0xf0(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x4e495453,(%rsp)
movb   $0x47,0x4(%rsp)
movaps 0xec6(%rip),%xmm0
movaps %xmm0,0xe0(%rsp)
movaps 0xea7(%rip),%xmm0
movaps %xmm0,0xd0(%rsp)
movaps 0xe88(%rip),%xmm0
movaps %xmm0,0xc0(%rsp)
movaps 0xe69(%rip),%xmm0
movaps %xmm0,0xb0(%rsp)
movaps 0xe4a(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
movaps 0xecb(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xeac(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xe8d(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe71(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xe55(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
lea    0xf1b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe98(%rip),%rdi
lea    0xe86(%rip),%r13
lea    0xe87(%rip),%r15
mov    %r13,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1060 <index_common@plt>
lea    0xe71(%rip),%rdi
mov    $0x1,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xee2(%rip),%r12
mov    %r12,%rdi
call   1030 <puts@plt>
lea    0xf0(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0xe64(%rip),%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    %eax,%ecx
mov    %r14,%r8
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1060 <index_common@plt>
lea    0xe08(%rip),%rdi
mov    $0x1,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
lea    0xa0(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0x50(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xe1d(%rip),%rdi
mov    %ebp,%esi
mov    %r14,%rdx
mov    %eax,%ecx
mov    %rbx,%r8
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1060 <index_common@plt>
lea    0xda4(%rip),%rdi
mov    $0x1,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x148,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.s1 = [80 x i8] c"A STRING SEARCHING EXAMPLE CONSISTING OF SIMPLE TEXT\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.main.s2 = [80 x i8] c"00000000000000000000000000000000000000000000000000001\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.main.t2 = [80 x i8] c"00000001\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [8 x i8] c"lixiang\00"
@.str.1 = [3 x i8] c"xi\00"
@.str.2 = [27 x i8] c"Print the string S and T:\0A\00"
@.str.3 = [11 x i8] c"S=%s\0AT=%s\0A\00"
@.str.4 = [52 x i8] c"\0AFind the position of T in the S from pos %d is %d\0A\00"
@.str.5 = [32 x i8] c"\0APrint the new string S and T:\0A\00"
@.str.6 = [29 x i8] c"Len=%d, S1=%s\0ALen=%d, T1=%s\0A\00"
@.str.7 = [27 x i8] c"Len=%d, S=%s\0ALen=%d, T=%s\0A\00"
define void @main() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca [80 x i8]
%4 = alloca [80 x i8]
%5 = alloca [80 x i8]
%6 = alloca [80 x i8]
%7 = alloca i32
%8 = bitcast [80 x i8]* %3 to i8*
%9 = bitcast [80 x i8]* %4 to i8*
%10 = bitcast i8* %9 to [80 x i8]*
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i32 0, i32 0
store i8 83, i8* %11
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i32 0, i32 1
store i8 84, i8* %12
%13 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i32 0, i32 2
store i8 73, i8* %13
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i32 0, i32 3
store i8 78, i8* %14
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i32 0, i32 4
store i8 71, i8* %15
%16 = bitcast [80 x i8]* %5 to i8*
%17 = bitcast [80 x i8]* %6 to i8*
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%19 = load i8*, i8** %1
%20 = load i8*, i8** %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %19, i8* %20)
store i32 1, i32* %7
%22 = load i32, i32* %7
%23 = load i8*, i8** %1
%24 = load i8*, i8** %2
%25 = load i32, i32* %7
%26 = call i32 @index_common(i8* %23, i8* %24, i32 %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i32 %22, i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%29 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%30 = call i32 @strlen(i8* %29)
%31 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%32 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%33 = call i32 @strlen(i8* %32)
%34 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i32 %30, i8* %31, i32 %33, i8* %34)
%36 = load i32, i32* %7
%37 = load i8*, i8** %1
%38 = load i8*, i8** %2
%39 = load i32, i32* %7
%40 = call i32 @index_common(i8* %37, i8* %38, i32 %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i32 %36, i32 %40)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%43 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%44 = call i32 @strlen(i8* %43)
%45 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%46 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%47 = call i32 @strlen(i8* %46)
%48 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %44, i8* %45, i32 %47, i8* %48)
%50 = load i32, i32* %7
%51 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%52 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%53 = load i32, i32* %7
%54 = call i32 @index_common(i8* %51, i8* %52, i32 %53)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i32 %50, i32 %54)
ret void
}

LLVM IR (-O2):
@__const.main.s1 = [80 x i8] c"A STRING SEARCHING EXAMPLE CONSISTING OF SIMPLE TEXT\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.main.s2 = [80 x i8] c"00000000000000000000000000000000000000000000000000001\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.main.t2 = [80 x i8] c"00000001\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [8 x i8] c"lixiang\00"
@.str.1 = [3 x i8] c"xi\00"
@.str.3 = [11 x i8] c"S=%s\0AT=%s\0A\00"
@.str.4 = [52 x i8] c"\0AFind the position of T in the S from pos %d is %d\0A\00"
@.str.6 = [29 x i8] c"Len=%d, S1=%s\0ALen=%d, T1=%s\0A\00"
@.str.7 = [27 x i8] c"Len=%d, S=%s\0ALen=%d, T=%s\0A\00"
@str = [26 x i8] c"Print the string S and T:\00"
@str.9 = [31 x i8] c"\0APrint the new string S and T:\00"
define void @main() {
%1 = alloca [80 x i8]
%2 = alloca [80 x i8]
%3 = alloca [80 x i8]
%4 = alloca [80 x i8]
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
store i8 83, i8* %6
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 1
store i8 84, i8* %7
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 2
store i8 73, i8* %8
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 3
store i8 78, i8* %9
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 4
store i8 71, i8* %10
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @index_common(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 1)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i32 1, i32 %15)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.9, i64 0, i64 0))
%18 = call i32 @strlen(i8* %5)
%19 = call i32 @strlen(i8* %6)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i32 %18, i8* %5, i32 %19, i8* %6)
%21 = call i32 @index_common(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 1)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i32 1, i32 %21)
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.9, i64 0, i64 0))
%24 = call i32 @strlen(i8* %11)
%25 = call i32 @strlen(i8* %12)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %24, i8* %11, i32 %25, i8* %12)
%27 = call i32 @index_common(i8* %11, i8* %12, i32 1)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i32 1, i32 %27)
ret void
}