#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 */
char *mate(char *, int, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int main(void) {
  char str[] = "sfggregfgghhhhf", pattern[] = "fggh";
  int i, len = strlen(pattern);
  char *p;
  p = mate(str, strlen(str), pattern, len);
  if (p) {
    for (i = 0; i < len; i++) {
      printf("%3c", *(p + i));
    }
  } else {
    printf("no found\r\n");
  }
  printf("\r\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeb5(%rip),%eax
mov    %eax,-0x25(%rbp)
mov    0xeb0(%rip),%al
mov    %al,-0x21(%rbp)
lea    -0x25(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x30(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
lea    -0x25(%rbp),%rdx
mov    -0x30(%rbp),%ecx
call   1050 <mate@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11e5 <main+0xb5>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    11e0 <main+0xb0>
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11ac <main+0x7c>
jmp    11f3 <main+0xc3>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
movaps 0xeaf(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movb   $0x0,0xc(%rsp)
movl   $0x68676766,0x8(%rsp)
68
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1060 <mate@plt>
test   %rax,%rax
je     11ca <main+0x8a>
test   %ebp,%ebp
jle    11d6 <main+0x96>
mov    %rax,%r15
mov    %ebp,%ebp
lea    0xe72(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%r15,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11b0 <main+0x70>
jmp    11d6 <main+0x96>
lea    0xe48(%rip),%rdi
call   1030 <puts@plt>
lea    0xe44(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.str = [16 x i8] c"sfggregfgghhhhf\00"
@__const.main.pattern = [5 x i8] c"fggh\00"
@.str = [4 x i8] c"%3c\00"
@.str.1 = [11 x i8] c"no found\0D\0A\00"
@.str.2 = [3 x i8] c"\0D\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [16 x i8]
%3 = alloca [5 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 0, i32* %1
%7 = bitcast [16 x i8]* %2 to i8*
%8 = bitcast [5 x i8]* %3 to i8*
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %5
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
%14 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%15 = load i32, i32* %5
%16 = call i8* @mate(i8* %11, i32 %13, i8* %14, i32 %15)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %36
19: ; preds = %0
store i32 0, i32* %4
br label %20
20: ; preds = %32, %19
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %35
24: ; preds = %20
%25 = load i8*, i8** %6
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %24
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %20
35: ; preds = %20
br label %38
36: ; preds = %0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %38
38: ; preds = %36, %35
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@__const.main.str = [16 x i8] c"sfggregfgghhhhf\00"
@__const.main.pattern = [5 x i8] c"fggh\00"
@.str = [4 x i8] c"%3c\00"
@str = [10 x i8] c"no found\0D\00"
@str.3 = [2 x i8] c"\0D\00"
define i32 @main() {
%1 = alloca [16 x i8]
%2 = alloca [5 x i8]
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%5 = call i32 @strlen(i8* %4)
%6 = call i32 @strlen(i8* %3)
%7 = call i8* @mate(i8* %3, i32 %6, i8* %4, i32 %5)
%8 = icmp eq i8* %7, null
br i1 %8, label %21, label %9
9: ; preds = %0
%10 = icmp sgt i32 %5, 0
br i1 %10, label %11, label %23
11: ; preds = %9
%12 = zext i32 %5 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %19, %13 ]
%15 = getelementptr inbounds i8, i8* %7, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = add nuw nsw i64 %14, 1
%20 = icmp eq i64 %19, %12
br i1 %20, label %23, label %13
21: ; preds = %0
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %23
23: ; preds = %13, %9, %21
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.3, i64 0, i64 0))
ret i32 0
}