#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 *findSubstring(char *, char **, int, int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  char **cl = (char **)malloc(3 * sizeof(char *));
  cl[0] = "ab";
  cl[1] = "bb";
  cl[2] = "foo";
  char *s = "abaaabbb";
  int r;
  int *rs = findSubstring(s, cl, 2, &r);
  for (int i = 0; i < r; i++)
    printf("%d ", rs[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x18,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
lea    0xea8(%rip),%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
lea    0xea7(%rip),%rcx
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
lea    0xe8e(%rip),%rcx
mov    %rcx,0x10(%rax)
lea    0xe87(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x2,%edx
lea    -0x1c(%rbp),%rcx
call   1030 <findSubstring@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11d6 <main+0xa6>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe4d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a5 <main+0x75>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0x18,%edi
call   1050 <malloc@plt>
lea    0xeb6(%rip),%rcx
mov    %rcx,(%rax)
lea    0xeb9(%rip),%rcx
mov    %rcx,0x8(%rax)
lea    0xea4(%rip),%rcx
mov    %rcx,0x10(%rax)
lea    0xe9d(%rip),%rdi
lea    0xc(%rsp),%rcx
mov    %rax,%rsi
mov    $0x2,%edx
call   1030 <findSubstring@plt>
cmpl   $0x0,0xc(%rsp)
jle    11aa <main+0x7a>
mov    %rax,%r15
xor    %ebx,%ebx
lea    0xe81(%rip),%r14
nop
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1190 <main+0x60>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"ab\00"
@.str.1 = [3 x i8] c"bb\00"
@.str.2 = [4 x i8] c"foo\00"
@.str.3 = [9 x i8] c"abaaabbb\00"
@.str.4 = [4 x i8] c"%d \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i32 0, i32* %1
%7 = call i64 @malloc(i32 24)
%8 = inttoptr i64 %7 to i8**
store i8** %8, i8*** %2
%9 = load i8**, i8*** %2
%10 = getelementptr inbounds i8*, i8** %9, i64 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %10
%11 = load i8**, i8*** %2
%12 = getelementptr inbounds i8*, i8** %11, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %12
%13 = load i8**, i8*** %2
%14 = getelementptr inbounds i8*, i8** %13, i64 2
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %14
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8** %3
%15 = load i8*, i8** %3
%16 = load i8**, i8*** %2
%17 = call i32* @findSubstring(i8* %15, i8** %16, i32 2, i32* %4)
store i32* %17, i32** %5
store i32 0, i32* %6
br label %18
18: ; preds = %29, %0
%19 = load i32, i32* %6
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load i32*, i32** %5
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %26
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %22
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
br label %18
32: ; preds = %18
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"ab\00"
@.str.1 = [3 x i8] c"bb\00"
@.str.2 = [4 x i8] c"foo\00"
@.str.3 = [9 x i8] c"abaaabbb\00"
@.str.4 = [4 x i8] c"%d \00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i64 @malloc(i32 24)
%3 = inttoptr i64 %2 to i8**
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %3
%4 = getelementptr inbounds i8*, i8** %3, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %4
%5 = getelementptr inbounds i8*, i8** %3, i64 2
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %5
%6 = bitcast i32* %1 to i8*
%7 = call i32* @findSubstring(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8** %3, i32 2, i32* %1)
%8 = load i32, i32* %1
%9 = icmp sgt i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %11, %0
ret i32 0
11: ; preds = %0, %11
%12 = phi i64 [ %16, %11 ], [ 0, %0 ]
%13 = getelementptr inbounds i32, i32* %7, i64 %12
%14 = load i32, i32* %13
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %14)
%16 = add nuw nsw i64 %12, 1
%17 = load i32, i32* %1
%18 = sext i32 %17 to i64
%19 = icmp slt i64 %16, %18
br i1 %19, label %11, label %10
}