#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_v3(char *upstream_sequence, char *motif,
                             unsigned short *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] = (unsigned short)strlen(search_string);
      strcpy(current_string, search_string + motif_length);
    }
  }
  return n;
}


x86 assembly (clang, -O0):
<count_perfect_matches_v3>:
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     11f7 <count_perfect_matches_v3+0xc7>
lea    -0x2730(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f2 <count_perfect_matches_v3+0xc2>
mov    -0x2734(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2734(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %ax,%dx
mov    -0x18(%rbp),%rax
movslq -0x2734(%rbp),%rcx
mov    %dx,(%rax,%rcx,2)
lea    -0x2730(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0x2738(%rbp),%rax
add    %rax,%rsi
call   1030 <strcpy@plt>
jmp    1184 <count_perfect_matches_v3+0x54>
mov    -0x2734(%rbp),%eax
add    $0x2740,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_perfect_matches_v3>:
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     11d3 <count_perfect_matches_v3+0xa3>
mov    %rsp,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     11d3 <count_perfect_matches_v3+0xa3>
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    %ax,0x2(%r14,%r12,2)
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_v3+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_v3(i8* %0, i8* %1, i16* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i16*
%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 i16* %2, i16** %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 = %44, %3
%20 = load i8*, i8** %7
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %45
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 %44
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 = trunc i32 %32 to i16
%34 = load i16*, i16** %6
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i16, i16* %34, i64 %36
store i16 %33, i16* %37
%38 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 0
%39 = load i8*, i8** %7
%40 = load i32, i32* %10
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = call i32 @strcpy(i8* %38, i8* %42)
br label %44
44: ; preds = %28, %22
br label %19
45: ; preds = %19
%46 = load i32, i32* %9
ret i32 %46
}

LLVM IR (-O2):
define i32 @count_perfect_matches_v3(i8* %0, i8* %1, i16* 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 %26, 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 %26, label %14
14: ; preds = %10, %14
%15 = phi i8* [ %24, %14 ], [ %12, %10 ]
%16 = phi i32 [ %17, %14 ], [ 0, %10 ]
%17 = add nuw nsw i32 %16, 1
%18 = call i32 @strlen(i8* %15)
%19 = trunc i32 %18 to i16
%20 = zext i32 %17 to i64
%21 = getelementptr inbounds i16, i16* %2, i64 %20
store i16 %19, i16* %21
%22 = getelementptr inbounds i8, i8* %15, i64 %11
%23 = call i32 @strcpy(i8* %5, i8* %22)
%24 = call i8* @strstr(i8* %5, i8* dereferenceable(1) %1)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %14
26: ; preds = %14, %10, %3
%27 = phi i32 [ 0, %3 ], [ 0, %10 ], [ %17, %14 ]
ret i32 %27
}