#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_v2c(char *upstream_sequence, char *motif,
                              char *motifc, 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);
    }
  }
  strcpy(current_string, upstream_sequence);
  search_string = strstr(current_string, motifc);
  while (search_string != NULL) {
    search_string = strstr(current_string, motifc);
    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_v2c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2750,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x2744(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2748(%rbp)
lea    -0x2740(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x2740(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11f9 <count_perfect_matches_v2c+0xc9>
lea    -0x2740(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11f4 <count_perfect_matches_v2c+0xc4>
mov    -0x2744(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2744(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rax
movslq -0x2744(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
lea    -0x2740(%rbp),%rdi
mov    -0x28(%rbp),%rsi
movslq -0x2748(%rbp),%rax
add    %rax,%rsi
call   1030 <strcpy@plt>
jmp    1188 <count_perfect_matches_v2c+0x58>
lea    -0x2740(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x2740(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     128e <count_perfect_matches_v2c+0x15e>
lea    -0x2740(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1289 <count_perfect_matches_v2c+0x159>
mov    -0x2744(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2744(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rax
movslq -0x2744(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
lea    -0x2740(%rbp),%rdi
mov    -0x28(%rbp),%rsi
movslq -0x2748(%rbp),%rax
add    %rax,%rsi
call   1030 <strcpy@plt>
jmp    121d <count_perfect_matches_v2c+0xed>
mov    -0x2744(%rbp),%eax
add    $0x2750,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_perfect_matches_v2c>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2728,%rsp
mov    %rcx,%r15
mov    %rdx,0x8(%rsp)
mov    %rsi,%r13
mov    %rdi,%r12
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <strstr@plt>
xor    %ebx,%ebx
movslq %ebp,%r14
test   %rax,%rax
je     11d6 <count_perfect_matches_v2c+0xa6>
lea    0x10(%rsp),%rdi
mov    %r13,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     11d6 <count_perfect_matches_v2c+0xa6>
mov    %rax,%rbp
mov    %r12,(%rsp)
xor    %ebx,%ebx
lea    0x10(%rsp),%r12
xchg   %ax,%ax
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %eax,0x4(%r15,%rbx,4)
add    %r14,%rbp
mov    %r12,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <strstr@plt>
mov    %rax,%rbp
add    $0x1,%rbx
test   %rax,%rax
jne    11a0 <count_perfect_matches_v2c+0x70>
mov    (%rsp),%r12
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
mov    0x8(%rsp),%r13
mov    %r13,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     1250 <count_perfect_matches_v2c+0x120>
lea    0x10(%rsp),%rdi
mov    %r13,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     1250 <count_perfect_matches_v2c+0x120>
mov    %rax,%rbp
lea    0x10(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebx
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %eax,(%r15,%rbx,4)
add    %r14,%rbp
mov    %r12,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <strstr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1220 <count_perfect_matches_v2c+0xf0>
mov    %ebx,%eax
add    $0x2728,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @count_perfect_matches_v2c(i8* %0, i8* %1, i8* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca [10000 x i8]
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32* %3, i32** %8
store i32 0, i32* %11
%13 = load i8*, i8** %6
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %12
%15 = getelementptr inbounds [10000 x i8], [10000 x i8]* %10, i64 0, i64 0
%16 = load i8*, i8** %5
%17 = call i32 @strcpy(i8* %15, i8* %16)
%18 = getelementptr inbounds [10000 x i8], [10000 x i8]* %10, i64 0, i64 0
%19 = load i8*, i8** %6
%20 = call i8* @strstr(i8* %18, i8* %19)
store i8* %20, i8** %9
br label %21
21: ; preds = %45, %4
%22 = load i8*, i8** %9
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %46
24: ; preds = %21
%25 = getelementptr inbounds [10000 x i8], [10000 x i8]* %10, i64 0, i64 0
%26 = load i8*, i8** %6
%27 = call i8* @strstr(i8* %25, i8* %26)
store i8* %27, i8** %9
%28 = load i8*, i8** %9
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %45
30: ; preds = %24
%31 = load i32, i32* %11
%32 = add nsw i32 %31, 1
store i32 %32, i32* %11
%33 = load i8*, i8** %9
%34 = call i32 @strlen(i8* %33)
%35 = load i32*, i32** %8
%36 = load i32, i32* %11
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
store i32 %34, i32* %38
%39 = getelementptr inbounds [10000 x i8], [10000 x i8]* %10, i64 0, i64 0
%40 = load i8*, i8** %9
%41 = load i32, i32* %12
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = call i32 @strcpy(i8* %39, i8* %43)
br label %45
45: ; preds = %30, %24
br label %21
46: ; preds = %21
%47 = getelementptr inbounds [10000 x i8], [10000 x i8]* %10, i64 0, i64 0
%48 = load i8*, i8** %5
%49 = call i32 @strcpy(i8* %47, i8* %48)
%50 = getelementptr inbounds [10000 x i8], [10000 x i8]* %10, i64 0, i64 0
%51 = load i8*, i8** %7
%52 = call i8* @strstr(i8* %50, i8* %51)
store i8* %52, i8** %9
br label %53
53: ; preds = %77, %46
%54 = load i8*, i8** %9
%55 = icmp ne i8* %54, null
br i1 %55, label %56, label %78
56: ; preds = %53
%57 = getelementptr inbounds [10000 x i8], [10000 x i8]* %10, i64 0, i64 0
%58 = load i8*, i8** %7
%59 = call i8* @strstr(i8* %57, i8* %58)
store i8* %59, i8** %9
%60 = load i8*, i8** %9
%61 = icmp ne i8* %60, null
br i1 %61, label %62, label %77
62: ; preds = %56
%63 = load i32, i32* %11
%64 = add nsw i32 %63, 1
store i32 %64, i32* %11
%65 = load i8*, i8** %9
%66 = call i32 @strlen(i8* %65)
%67 = load i32*, i32** %8
%68 = load i32, i32* %11
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i32, i32* %67, i64 %69
store i32 %66, i32* %70
%71 = getelementptr inbounds [10000 x i8], [10000 x i8]* %10, i64 0, i64 0
%72 = load i8*, i8** %9
%73 = load i32, i32* %12
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %72, i64 %74
%76 = call i32 @strcpy(i8* %71, i8* %75)
br label %77
77: ; preds = %62, %56
br label %53
78: ; preds = %53
%79 = load i32, i32* %11
ret i32 %79
}

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