#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 /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int strindex(char *, char *);
int main() {
  char string[100];
  char substring[100];
  int result;
  printf("请输入字符串 ==>");
  gets(string);
  printf("请输入要找寻的子字符串 ==>");
  gets(substring);
  result = strindex(string, substring);
  if (result > 0)
    printf("子字符串 %s 位置在 %d \n", substring, result);
  else
    printf("没有找到子字符串 %s\n", substring);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
call   1040 <gets@plt>
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xe0(%rbp),%rdi
call   1040 <gets@plt>
lea    -0x70(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
call   1050 <strindex@plt>
mov    %eax,-0xe4(%rbp)
cmpl   $0x0,-0xe4(%rbp)
jle    11b6 <main+0x86>
lea    -0xe0(%rbp),%rsi
mov    -0xe4(%rbp),%edx
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11cb <main+0x9b>
lea    -0xe0(%rbp),%rsi
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0xd8,%rsp
lea    0xebf(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x70(%rsp),%r14
mov    %r14,%rdi
call   1040 <gets@plt>
lea    0xebb(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <gets@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <strindex@plt>
test   %eax,%eax
jle    1192 <main+0x62>
lea    0xeb9(%rip),%rdi
mov    %rsp,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11a3 <main+0x73>
lea    0xec3(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [23 x i8] c"\E8\AF\B7\E8\BE\93\E5\85\A5\E5\AD\97\E7\AC\A6\E4\B8\B2 ==>\00"
@.str.1 = [38 x i8] c"\E8\AF\B7\E8\BE\93\E5\85\A5\E8\A6\81\E6\89\BE\E5\AF\BB\E7\9A\84\E5\AD\90\E5\AD\97\E7\AC\A6\E4\B8\B2 ==>\00"
@.str.2 = [31 x i8] c"\E5\AD\90\E5\AD\97\E7\AC\A6\E4\B8\B2 %s \E4\BD\8D\E7\BD\AE\E5\9C\A8 %d \0A\00"
@.str.3 = [29 x i8] c"\E6\B2\A1\E6\9C\89\E6\89\BE\E5\88\B0\E5\AD\90\E5\AD\97\E7\AC\A6\E4\B8\B2 %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca [100 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%7 = call i32 @gets(i8* %6)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%10 = call i32 @gets(i8* %9)
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%13 = call i32 @strindex(i8* %11, i8* %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %0
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%18 = load i32, i32* %4
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %17, i32 %18)
br label %23
20: ; preds = %0
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %20, %16
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"\E8\AF\B7\E8\BE\93\E5\85\A5\E5\AD\97\E7\AC\A6\E4\B8\B2 ==>\00"
@.str.1 = [38 x i8] c"\E8\AF\B7\E8\BE\93\E5\85\A5\E8\A6\81\E6\89\BE\E5\AF\BB\E7\9A\84\E5\AD\90\E5\AD\97\E7\AC\A6\E4\B8\B2 ==>\00"
@.str.2 = [31 x i8] c"\E5\AD\90\E5\AD\97\E7\AC\A6\E4\B8\B2 %s \E4\BD\8D\E7\BD\AE\E5\9C\A8 %d \0A\00"
@.str.3 = [29 x i8] c"\E6\B2\A1\E6\9C\89\E6\89\BE\E5\88\B0\E5\AD\90\E5\AD\97\E7\AC\A6\E4\B8\B2 %s\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @gets(i8* %3)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @gets(i8* %4)
%9 = call i32 @strindex(i8* %3, i8* %4)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %4, i32 %9)
br label %15
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %15
15: ; preds = %13, %11
ret i32 0
}