#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 */
typedef int /*<<< orphan*/ sub_s;
typedef int /*<<< orphan*/ n;

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
char *strnstr(char *, char *, int /*<<< orphan*/);
char *strrchr(char *, char);
int main(int argc, char **argv) {
  char buff[] = "Name:Fangxm Born:1977-04-12 Age:31 Sex:male";
  char sub_s[PATH_MAX], n[PATH_MAX], *p, *eof;
  printf("[input \"sub string\" and \"first of bytes\" to search]\n");
  while (1) {
    printf("Search string: [%s]\n", buff);
    printf("sub string: ");
    if (fgets(sub_s, sizeof(sub_s), stdin) == NULL)
      continue;
    if ((eof = strrchr(sub_s, '\n')) == NULL)
      continue;
    eof[0] = '\0';
    printf("first of bytes: ");
    if (fgets(n, sizeof(n), stdin) == NULL)
      continue;
    p = strnstr(buff, sub_s, atoi(n));
    if (p == NULL)
      printf("failuer.\n\n");
    else
      printf("success:[%s]\n\n", p);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movups 0xeac(%rip),%xmm0
movups %xmm0,-0x24(%rbp)
movaps 0xe95(%rip),%xmm0
movaps %xmm0,-0x30(%rbp)
movaps 0xe7a(%rip),%xmm0
movaps %xmm0,-0x40(%rbp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%ecx
mov    %rcx,-0x88(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x48(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x80(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x50(%rbp)
mov    (%rax),%eax
mov    %rax,-0x78(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x58(%rbp)
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f2 <main+0xa2>
lea    -0x40(%rbp),%rsi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x80(%rbp),%rdi
mov    -0x88(%rbp),%rax
mov    %eax,%esi
mov    0x2dba(%rip),%rax
mov    (%rax),%edx
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    123c <main+0xec>
jmp    11ed <main+0x9d>
mov    -0x80(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x68(%rbp)
cmp    $0x0,%rax
jne    125d <main+0x10d>
jmp    11ed <main+0x9d>
mov    -0x68(%rbp),%rax
movb   $0x0,(%rax)
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x70(%rbp),%rdi
mov    -0x78(%rbp),%rax
mov    %eax,%esi
mov    0x2d5d(%rip),%rax
mov    (%rax),%edx
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    1299 <main+0x149>
jmp    11ed <main+0x9d>
mov    -0x70(%rbp),%rdi
lea    -0x40(%rbp),%rax
mov    %rax,-0x90(%rbp)
call   1070 <atoi@plt>
mov    -0x90(%rbp),%rdi
mov    -0x80(%rbp),%rsi
mov    %eax,%edx
call   1050 <strnstr@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    12e1 <main+0x191>
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12f3 <main+0x1a3>
mov    -0x60(%rbp),%rsi
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ed <main+0x9d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movups 0xea4(%rip),%xmm0
movups %xmm0,-0x44(%rbp)
movaps 0xe8d(%rip),%xmm0
movaps %xmm0,-0x50(%rbp)
movaps 0xe72(%rip),%xmm0
movaps %xmm0,-0x60(%rbp)
mov    0x2e57(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
mov    %r14,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
lea    0xeae(%rip),%rdi
call   1030 <puts@plt>
lea    -0x60(%rbp),%r13
mov    0x2e10(%rip),%r12
jmp    11f0 <main+0x90>
lea    0xe86(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xe35(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe39(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    %r14d,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     11f0 <main+0x90>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     11f0 <main+0x90>
movb   $0x0,(%rax)
lea    0xe0f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r12),%edx
mov    %r15,%rdi
mov    %r14d,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     11f0 <main+0x90>
mov    %r15,%rdi
call   1080 <atoi@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <strnstr@plt>
test   %rax,%rax
jne    11d2 <main+0x72>
lea    0xe23(%rip),%rdi
call   1030 <puts@plt>
jmp    11f0 <main+0x90>

LLVM IR (-O0):
@__const.main.buff = [44 x i8] c"Name:Fangxm Born:1977-04-12 Age:31 Sex:male\00"
@PATH_MAX = global i32 0
@.str = [53 x i8] c"[input \22sub string\22 and \22first of bytes\22 to search]\0A\00"
@.str.1 = [21 x i8] c"Search string: [%s]\0A\00"
@.str.2 = [13 x i8] c"sub string: \00"
@stdin = global i32 0
@.str.3 = [17 x i8] c"first of bytes: \00"
@.str.4 = [11 x i8] c"failuer.\0A\0A\00"
@.str.5 = [15 x i8] c"success:[%s]\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [44 x i8]
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [44 x i8]* %6 to i8*
%13 = load i32, i32* @PATH_MAX
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %7
%16 = alloca i8, i64 %14
store i64 %14, i64* %8
%17 = load i32, i32* @PATH_MAX
%18 = zext i32 %17 to i64
%19 = alloca i8, i64 %18
store i64 %18, i64* %9
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %55, %43, %34, %30, %2
br label %22
22: ; preds = %21
%23 = getelementptr inbounds [44 x i8], [44 x i8]* %6, i64 0, i64 0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%26 = trunc i64 %14 to i32
%27 = load i32, i32* @stdin
%28 = call i32* @fgets(i8* %16, i32 %26, i32 %27)
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %31
30: ; preds = %22
br label %21
31: ; preds = %22
%32 = call i8* @strrchr(i8* %16, i8 signext 10)
store i8* %32, i8** %11
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %35
34: ; preds = %31
br label %21
35: ; preds = %31
%36 = load i8*, i8** %11
%37 = getelementptr inbounds i8, i8* %36, i64 0
store i8 0, i8* %37
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%39 = trunc i64 %18 to i32
%40 = load i32, i32* @stdin
%41 = call i32* @fgets(i8* %19, i32 %39, i32 %40)
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %44
43: ; preds = %35
br label %21
44: ; preds = %35
%45 = getelementptr inbounds [44 x i8], [44 x i8]* %6, i64 0, i64 0
%46 = call i32 @atoi(i8* %19)
%47 = call i8* @strnstr(i8* %45, i8* %16, i32 %46)
store i8* %47, i8** %10
%48 = load i8*, i8** %10
%49 = icmp eq i8* %48, null
br i1 %49, label %50, label %52
50: ; preds = %44
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %55
52: ; preds = %44
%53 = load i8*, i8** %10
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %53)
br label %55
55: ; preds = %52, %50
br label %21
}

LLVM IR (-O2):
@__const.main.buff = [44 x i8] c"Name:Fangxm Born:1977-04-12 Age:31 Sex:male\00"
@PATH_MAX = global i32 0
@.str.1 = [21 x i8] c"Search string: [%s]\0A\00"
@.str.2 = [13 x i8] c"sub string: \00"
@stdin = global i32 0
@.str.3 = [17 x i8] c"first of bytes: \00"
@.str.5 = [15 x i8] c"success:[%s]\0A\0A\00"
@str = [52 x i8] c"[input \22sub string\22 and \22first of bytes\22 to search]\00"
@str.6 = [10 x i8] c"failuer.\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [44 x i8]
%4 = getelementptr inbounds [44 x i8], [44 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = alloca i8, i64 %6
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str, i64 0, i64 0))
br label %10
10: ; preds = %30, %2
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32, i32* @stdin
%14 = call i32* @fgets(i8* %7, i32 %5, i32 %13)
%15 = icmp eq i32* %14, null
br i1 %15, label %30, label %16
16: ; preds = %10
%17 = call i8* @strrchr(i8* %7, i8 signext 10)
%18 = icmp eq i8* %17, null
br i1 %18, label %30, label %19
19: ; preds = %16
store i8 0, i8* %17
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%21 = load i32, i32* @stdin
%22 = call i32* @fgets(i8* %8, i32 %5, i32 %21)
%23 = icmp eq i32* %22, null
br i1 %23, label %30, label %24
24: ; preds = %19
%25 = call i32 @atoi(i8* %8)
%26 = call i8* @strnstr(i8* %4, i8* %7, i32 %25)
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.6, i64 0, i64 0))
br label %30
30: ; preds = %28, %31, %10, %16, %19
br label %10
31: ; preds = %24
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %26)
br label %30
}