#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 /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strstr(char *, char *);
int count_perfect_matches_v2(char *upstream_sequence, char *motif, int *pos) {
  char *search_string;
  char current_string[10000];
  int n = 0;
  int motif_length;
  motif_length = strlen(motif);
  strcpy(current_string, upstream_sequence);
  search_string = strstr(current_string, motif);
  while (search_string != NULL) {
    search_string = strstr(current_string, motif);
    if (search_string != NULL) {
      n++;
      pos[n] = strlen(search_string);
      strcpy(current_string, search_string + motif_length);
    }
  }
  return n;
}


x86 assembly (clang, -O0):
<count_perfect_matches_v2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2740,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x2734(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2738(%rbp)
lea    -0x2730(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x2730(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f5 <count_perfect_matches_v2+0xc5>
lea    -0x2730(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f0 <count_perfect_matches_v2+0xc0>
mov    -0x2734(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2734(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x2734(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
lea    -0x2730(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0x2738(%rbp),%rax
add    %rax,%rsi
call   1030 <strcpy@plt>
jmp    1184 <count_perfect_matches_v2+0x54>
mov    -0x2734(%rbp),%eax
add    $0x2740,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_perfect_matches_v2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2718,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r13d
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     11d2 <count_perfect_matches_v2+0xa2>
mov    %rsp,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     11d2 <count_perfect_matches_v2+0xa2>
mov    %rax,%rbx
movslq %r13d,%rbp
xor    %r12d,%r12d
mov    %rsp,%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,0x4(%r14,%r12,4)
add    %rbp,%rbx
mov    %r13,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
mov    %rax,%rbx
add    $0x1,%r12
test   %rax,%rax
jne    11a0 <count_perfect_matches_v2+0x70>
mov    %r12d,%eax
add    $0x2718,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @count_perfect_matches_v2(i8* %0, i8* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca [10000 x i8]
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
store i32 0, i32* %9
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %10
%13 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 0
%14 = load i8*, i8** %4
%15 = call i32 @strcpy(i8* %13, i8* %14)
%16 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 0
%17 = load i8*, i8** %5
%18 = call i8* @strstr(i8* %16, i8* %17)
store i8* %18, i8** %7
br label %19
19: ; preds = %43, %3
%20 = load i8*, i8** %7
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %44
22: ; preds = %19
%23 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 0
%24 = load i8*, i8** %5
%25 = call i8* @strstr(i8* %23, i8* %24)
store i8* %25, i8** %7
%26 = load i8*, i8** %7
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %43
28: ; preds = %22
%29 = load i32, i32* %9
%30 = add nsw i32 %29, 1
store i32 %30, i32* %9
%31 = load i8*, i8** %7
%32 = call i32 @strlen(i8* %31)
%33 = load i32*, i32** %6
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
store i32 %32, i32* %36
%37 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 0
%38 = load i8*, i8** %7
%39 = load i32, i32* %10
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = call i32 @strcpy(i8* %37, i8* %41)
br label %43
43: ; preds = %28, %22
br label %19
44: ; preds = %19
%45 = load i32, i32* %9
ret i32 %45
}

LLVM IR (-O2):
define i32 @count_perfect_matches_v2(i8* %0, i8* %1, i32* nocapture writeonly %2) {
%4 = alloca [10000 x i8]
%5 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @strlen(i8* %1)
%7 = call i32 @strcpy(i8* %5, i8* %0)
%8 = call i8* @strstr(i8* %5, i8* dereferenceable(1) %1)
%9 = icmp eq i8* %8, null
br i1 %9, label %25, label %10
10: ; preds = %3
%11 = sext i32 %6 to i64
%12 = call i8* @strstr(i8* %5, i8* dereferenceable(1) %1)
%13 = icmp eq i8* %12, null
br i1 %13, label %25, label %14
14: ; preds = %10, %14
%15 = phi i8* [ %23, %14 ], [ %12, %10 ]
%16 = phi i32 [ %17, %14 ], [ 0, %10 ]
%17 = add nuw nsw i32 %16, 1
%18 = call i32 @strlen(i8* %15)
%19 = zext i32 %17 to i64
%20 = getelementptr inbounds i32, i32* %2, i64 %19
store i32 %18, i32* %20
%21 = getelementptr inbounds i8, i8* %15, i64 %11
%22 = call i32 @strcpy(i8* %5, i8* %21)
%23 = call i8* @strstr(i8* %5, i8* dereferenceable(1) %1)
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %14
25: ; preds = %14, %10, %3
%26 = phi i32 [ 0, %3 ], [ 0, %10 ], [ %17, %14 ]
ret i32 %26
}