#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 *Sunday(char *, int, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int main(void) {
  char str[] = "sfregfgghhhhf", pattern[] = "fggh";
  int i, len = strlen(pattern);
  char *p;
  p = Sunday(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    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x12(%rbp)
mov    0xeb8(%rip),%eax
mov    %eax,-0xa(%rbp)
mov    0xeb2(%rip),%ax
mov    %ax,-0x6(%rbp)
mov    0xeaa(%rip),%eax
mov    %eax,-0x17(%rbp)
mov    0xea5(%rip),%al
mov    %al,-0x13(%rbp)
lea    -0x17(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
lea    -0x12(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x12(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
lea    -0x17(%rbp),%rdx
mov    -0x20(%rbp),%ecx
call   1050 <Sunday@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11ee <main+0xbe>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11e9 <main+0xb9>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b5 <main+0x85>
jmp    11fc <main+0xcc>
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
movabs $0x66686868686767,%rax
mov    %rax,0xe(%rsp)
movabs $0x6767666765726673,%rax
66 67 67
mov    %rax,0x8(%rsp)
movb   $0x0,0x4(%rsp)
movl   $0x68676766,(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1060 <Sunday@plt>
test   %rax,%rax
je     11da <main+0x9a>
test   %ebp,%ebp
jle    11e6 <main+0xa6>
mov    %rax,%r15
mov    %ebp,%ebp
lea    0xe61(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%r15,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11c0 <main+0x80>
jmp    11e6 <main+0xa6>
lea    0xe36(%rip),%rdi
call   1030 <puts@plt>
lea    0xe32(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.str = [14 x i8] c"sfregfgghhhhf\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 [14 x i8]
%3 = alloca [5 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 0, i32* %1
%7 = bitcast [14 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 [14 x i8], [14 x i8]* %2, i64 0, i64 0
%12 = getelementptr inbounds [14 x i8], [14 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* @Sunday(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 = [14 x i8] c"sfregfgghhhhf\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 [14 x i8]
%2 = alloca [5 x i8]
%3 = getelementptr inbounds [14 x i8], [14 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* @Sunday(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
}