#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 *find_substr_with_gap(char *, char *);
int /*<<< orphan*/ free(char *);
char *get_next_sp(char *, char **);
int /*<<< orphan*/ printf(char *, ...);
char *strlen(char *);
int main(int argc, char *argv[]) {
  char *s = argv[1];
  char *p = argv[2];
  char *sp = NULL;
  printf("INIT: s=%p:\t     |%15s|\n\n", s, s);
  while (*p != '\0') {
    sp = get_next_sp(argv[2], &p);
    s = find_substr_with_gap(s, sp);
    printf("found at: s=%p\n", s - strlen(sp));
    if (sp)
      free(sp);
    if (s == NULL) {
      printf("Not Found\n");
      return 0;
    }
  }
  printf("Found\n");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1236 <main+0xe6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <get_next_sp@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <find_substr_with_gap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rsi
sub    %rax,%rsi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x28(%rbp)
je     120c <main+0xbc>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1231 <main+0xe1>
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    124b <main+0xfb>
jmp    119c <main+0x4c>
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x8(%rsi),%rbp
mov    0x10(%rsi),%r14
mov    %r14,(%rsp)
lea    0xe7f(%rip),%rdi
mov    %rbp,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%r12d
lea    0xe93(%rip),%r15
cmpb   $0x0,(%r14)
je     1222 <main+0xc2>
mov    %rsp,%r12
lea    0xe6b(%rip),%r13
lea    0xe74(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    0x10(%rbx),%rdi
mov    %r12,%rsi
call   1070 <get_next_sp@plt>
mov    %rax,%r14
mov    %rbp,%rdi
mov    %rax,%rsi
call   1080 <find_substr_with_gap@plt>
mov    %rax,%rbp
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %rbp,%rsi
sub    %rax,%rsi
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
test   %r14,%r14
je     1202 <main+0xa2>
mov    %r14,%rdi
call   1030 <free@plt>
test   %rbp,%rbp
je     121f <main+0xbf>
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
jne    11c0 <main+0x60>
lea    0xe17(%rip),%r15
mov    $0x1,%r12d
jmp    1222 <main+0xc2>
xor    %r12d,%r12d
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"INIT: s=%p:\09 |%15s|\0A\0A\00"
@.str.1 = [16 x i8] c"found at: s=%p\0A\00"
@.str.2 = [11 x i8] c"Not Found\0A\00"
@.str.3 = [7 x i8] c"Found\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
store i8* %11, i8** %6
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 2
%14 = load i8*, i8** %13
store i8* %14, i8** %7
store i8* null, i8** %8
%15 = load i8*, i8** %6
%16 = load i8*, i8** %6
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %16)
br label %18
18: ; preds = %48, %2
%19 = load i8*, i8** %7
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %49
23: ; preds = %18
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i8* @get_next_sp(i8* %26, i8** %7)
store i8* %27, i8** %8
%28 = load i8*, i8** %6
%29 = load i8*, i8** %8
%30 = call i8* @find_substr_with_gap(i8* %28, i8* %29)
store i8* %30, i8** %6
%31 = load i8*, i8** %6
%32 = load i8*, i8** %8
%33 = call i8* @strlen(i8* %32)
%34 = ptrtoint i8* %31 to i64
%35 = ptrtoint i8* %33 to i64
%36 = sub i64 %34, %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %36)
%38 = load i8*, i8** %8
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %43
40: ; preds = %23
%41 = load i8*, i8** %8
%42 = call i32 @free(i8* %41)
br label %43
43: ; preds = %40, %23
%44 = load i8*, i8** %6
%45 = icmp eq i8* %44, null
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %51
48: ; preds = %43
br label %18
49: ; preds = %18
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %51
51: ; preds = %49, %46
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@.str = [26 x i8] c"INIT: s=%p:\09 |%15s|\0A\0A\00"
@.str.1 = [16 x i8] c"found at: s=%p\0A\00"
@str = [6 x i8] c"Found\00"
@str.4 = [10 x i8] c"Not Found\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = bitcast i8** %3 to i8*
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
store i8* %8, i8** %3
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %5)
%10 = load i8, i8* %8
%11 = icmp eq i8 %10, 0
br i1 %11, label %31, label %12
12: ; preds = %2, %27
%13 = phi i8* [ %16, %27 ], [ %5, %2 ]
%14 = load i8*, i8** %7
%15 = call i8* @get_next_sp(i8* %14, i8** %3)
%16 = call i8* @find_substr_with_gap(i8* %13, i8* %15)
%17 = call i8* @strlen(i8* %15)
%18 = ptrtoint i8* %16 to i64
%19 = ptrtoint i8* %17 to i64
%20 = sub i64 %18, %19
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %20)
%22 = icmp eq i8* %15, null
br i1 %22, label %25, label %23
23: ; preds = %12
%24 = call i32 @free(i8* %15)
br label %25
25: ; preds = %23, %12
%26 = icmp eq i8* %16, null
br i1 %26, label %31, label %27
27: ; preds = %25
%28 = load i8*, i8** %3
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 0
br i1 %30, label %31, label %12
31: ; preds = %25, %27, %2
%32 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @str.4, i64 0, i64 0), %25 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0), %27 ]
%33 = phi i32 [ 1, %2 ], [ 0, %25 ], [ 1, %27 ]
%34 = call i32 @puts(i8* dereferenceable(1) %32)
ret i32 %33
}