#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 rand();
char *rechercherElement(char *, int);
char *getrandpatternMatch(char *pattern) {
  char *results[1000], *wordPTR_tmp = NULL, *wordPTR = NULL;
  int count = 0, nb_results = 0;
  do {
    wordPTR_tmp = wordPTR;
    wordPTR = rechercherElement(pattern, count);
    if ((wordPTR) && (wordPTR != wordPTR_tmp)) {
      results[nb_results] = wordPTR;
      nb_results++;
      if (nb_results > 500)
        break;
    }
    count++;
  } while (wordPTR);
  if (nb_results > 0) {
    return results[rand() % nb_results];
  } else {
    return NULL;
  }
}


x86 assembly (clang, -O0):
<getrandpatternMatch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f70,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x1f58(%rbp)
movq   $0x0,-0x1f60(%rbp)
movl   $0x0,-0x1f64(%rbp)
movl   $0x0,-0x1f68(%rbp)
mov    -0x1f60(%rbp),%rax
mov    %rax,-0x1f58(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1f64(%rbp),%esi
call   1030 <rechercherElement@plt>
mov    %rax,-0x1f60(%rbp)
cmpq   $0x0,-0x1f60(%rbp)
je     11de <getrandpatternMatch+0xbe>
mov    -0x1f60(%rbp),%rax
cmp    -0x1f58(%rbp),%rax
je     11de <getrandpatternMatch+0xbe>
mov    -0x1f60(%rbp),%rcx
movslq -0x1f68(%rbp),%rax
mov    %rcx,-0x1f50(%rbp,%rax,8)
ff
mov    -0x1f68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f68(%rbp)
cmpl   $0x1f4,-0x1f68(%rbp)
jle    11d9 <getrandpatternMatch+0xb9>
jmp    11fb <getrandpatternMatch+0xdb>
jmp    11de <getrandpatternMatch+0xbe>
mov    -0x1f64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f64(%rbp)
cmpq   $0x0,-0x1f60(%rbp)
jne    1159 <getrandpatternMatch+0x39>
cmpl   $0x0,-0x1f68(%rbp)
jle    122a <getrandpatternMatch+0x10a>
mov    $0x0,%al
call   1040 <rand@plt>
cltd
idivl  -0x1f68(%rbp)
movslq %edx,%rax
mov    -0x1f50(%rbp,%rax,8),%rax
ff
mov    %rax,-0x8(%rbp)
jmp    1232 <getrandpatternMatch+0x112>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1f70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getrandpatternMatch>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1f48,%rsp
mov    %rdi,%r14
xor    %eax,%eax
xor    %ebp,%ebp
xor    %r15d,%r15d
jmp    1148 <getrandpatternMatch+0x28>
nopl   0x0(%rax)
add    $0x1,%ebp
test   %rax,%rax
je     1174 <getrandpatternMatch+0x54>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <rechercherElement@plt>
test   %rax,%rax
je     1140 <getrandpatternMatch+0x20>
cmp    %rbx,%rax
je     1140 <getrandpatternMatch+0x20>
movslq %r15d,%rcx
mov    %rax,(%rsp,%rcx,8)
lea    0x1(%rcx),%r15d
cmp    $0x1f3,%ecx
jle    1140 <getrandpatternMatch+0x20>
jmp    1179 <getrandpatternMatch+0x59>
test   %r15d,%r15d
jle    118d <getrandpatternMatch+0x6d>
xor    %eax,%eax
call   1040 <rand@plt>
cltd
idiv   %r15d
movslq %edx,%rax
mov    (%rsp,%rax,8),%rax
jmp    118f <getrandpatternMatch+0x6f>
xor    %eax,%eax
add    $0x1f48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @getrandpatternMatch(i8* %0) {
%2 = alloca [1000 x i8*]
%3 = bitcast [1000 x i8*]* %2 to i8*
br label %4
4: ; preds = %17, %1
%5 = phi i8* [ null, %1 ], [ %8, %17 ]
%6 = phi i32 [ 0, %1 ], [ %19, %17 ]
%7 = phi i32 [ 0, %1 ], [ %18, %17 ]
%8 = tail call i8* @rechercherElement(i8* %0, i32 %6)
%9 = icmp eq i8* %8, null
%10 = icmp eq i8* %8, %5
%11 = or i1 %9, %10
br i1 %11, label %17, label %12
12: ; preds = %4
%13 = sext i32 %7 to i64
%14 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %2, i64 0, i64 %13
store i8* %8, i8** %14
%15 = add nsw i32 %7, 1
%16 = icmp sgt i32 %7, 499
br i1 %16, label %22, label %17
17: ; preds = %12, %4
%18 = phi i32 [ %15, %12 ], [ %7, %4 ]
%19 = add nuw nsw i32 %6, 1
br i1 %9, label %20, label %4
20: ; preds = %17
%21 = icmp sgt i32 %18, 0
br i1 %21, label %22, label %29
22: ; preds = %12, %20
%23 = phi i32 [ %18, %20 ], [ %15, %12 ]
%24 = tail call i32 (...) @rand()
%25 = srem i32 %24, %23
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %2, i64 0, i64 %26
%28 = load i8*, i8** %27
br label %29
29: ; preds = %20, %22
%30 = phi i8* [ %28, %22 ], [ null, %20 ]
ret i8* %30
}