#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*/ printf(char *, ...);
int rand();
int randGenerator(int *arr, int len) {
  int i, j, r, rcount;
  for (i = 0; i < len; i++) {
    do {
      rcount = 0;
      r = rand() % (len / 2 + 1) + 1;
      for (j = 0; j < i && rcount < 2; j++) {
        if (arr[j] == r) {
          rcount++;
        }
      }
    } while (rcount >= 2);
    arr[i] = r;
    printf("%d ", r);
  }
  printf("\nDone generating\n");
  return 0;
}


x86 assembly (clang, -O0):
<randGenerator>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1212 <randGenerator+0xf2>
jmp    1147 <randGenerator+0x27>
movl   $0x0,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    $0x1,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%ecx
xor    %eax,%eax
cmp    -0x10(%rbp),%ecx
mov    %al,-0x21(%rbp)
jge    1196 <randGenerator+0x76>
cmpl   $0x2,-0x1c(%rbp)
setl   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11a6 <randGenerator+0x86>
jmp    11d6 <randGenerator+0xb6>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x18(%rbp),%eax
jne    11c3 <randGenerator+0xa3>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c8 <randGenerator+0xa8>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117b <randGenerator+0x5b>
jmp    11db <randGenerator+0xbb>
cmpl   $0x2,-0x1c(%rbp)
jge    1147 <randGenerator+0x27>
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%esi
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <randGenerator+0x16>
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randGenerator>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
jle    11b5 <randGenerator+0x85>
mov    %esi,%r12d
mov    %rdi,%rbx
mov    %esi,%r15d
shr    %r12d
add    $0x1,%r12d
lea    0xead(%rip),%r14
xor    %ebp,%ebp
jmp    1165 <randGenerator+0x35>
nopw   0x0(%rax,%rax,1)
cmp    $0x1,%eax
jbe    119d <randGenerator+0x6d>
xor    %eax,%eax
call   1050 <rand@plt>
cltd
idiv   %r12d
add    $0x1,%edx
test   %rbp,%rbp
je     119d <randGenerator+0x6d>
xor    %eax,%eax
mov    $0x1,%ecx
nop
mov    %eax,%esi
xor    %eax,%eax
cmp    %edx,-0x4(%rbx,%rcx,4)
sete   %al
add    %esi,%eax
cmp    %rbp,%rcx
jae    1160 <randGenerator+0x30>
add    $0x1,%rcx
cmp    $0x2,%eax
jb     1180 <randGenerator+0x50>
jmp    1160 <randGenerator+0x30>
mov    %edx,(%rbx,%rbp,4)
mov    %r14,%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %r15,%rbp
jne    1165 <randGenerator+0x35>
lea    0xe48(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d \00"
@.str.1 = [18 x i8] c"\0ADone generating\0A\00"
define i32 @randGenerator(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %9
9: ; preds = %57, %2
%10 = load i32, i32* %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %60
13: ; preds = %9
br label %14
14: ; preds = %46, %13
store i32 0, i32* %8
%15 = call i32 (...) @rand()
%16 = load i32, i32* %4
%17 = sdiv i32 %16, 2
%18 = add nsw i32 %17, 1
%19 = srem i32 %15, %18
%20 = add nsw i32 %19, 1
store i32 %20, i32* %7
store i32 0, i32* %6
br label %21
21: ; preds = %42, %14
%22 = load i32, i32* %6
%23 = load i32, i32* %5
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32, i32* %8
%27 = icmp slt i32 %26, 2
br label %28
28: ; preds = %25, %21
%29 = phi i1 [ false, %21 ], [ %27, %25 ]
br i1 %29, label %30, label %45
30: ; preds = %28
%31 = load i32*, i32** %3
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = load i32, i32* %34
%36 = load i32, i32* %7
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %41
38: ; preds = %30
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
br label %41
41: ; preds = %38, %30
br label %42
42: ; preds = %41
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
br label %21
45: ; preds = %28
br label %46
46: ; preds = %45
%47 = load i32, i32* %8
%48 = icmp sge i32 %47, 2
br i1 %48, label %14, label %49
49: ; preds = %46
%50 = load i32, i32* %7
%51 = load i32*, i32** %3
%52 = load i32, i32* %5
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
store i32 %50, i32* %54
%55 = load i32, i32* %7
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %49
%58 = load i32, i32* %5
%59 = add nsw i32 %58, 1
store i32 %59, i32* %5
br label %9
60: ; preds = %9
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d \00"
@str = [17 x i8] c"\0ADone generating\00"
define i32 @randGenerator(i32* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %34
4: ; preds = %2
%5 = lshr i32 %1, 1
%6 = add nuw nsw i32 %5, 1
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %4, %29
%9 = phi i64 [ 0, %4 ], [ %32, %29 ]
%10 = icmp eq i64 %9, 0
br label %11
11: ; preds = %8, %27
%12 = tail call i32 (...) @rand()
%13 = srem i32 %12, %6
%14 = add nsw i32 %13, 1
br i1 %10, label %29, label %15
15: ; preds = %11, %15
%16 = phi i64 [ %23, %15 ], [ 0, %11 ]
%17 = phi i32 [ %22, %15 ], [ 0, %11 ]
%18 = getelementptr inbounds i32, i32* %0, i64 %16
%19 = load i32, i32* %18
%20 = icmp eq i32 %19, %14
%21 = zext i1 %20 to i32
%22 = add nuw nsw i32 %17, %21
%23 = add nuw nsw i64 %16, 1
%24 = icmp ult i64 %23, %9
%25 = icmp ult i32 %22, 2
%26 = select i1 %24, i1 %25, i1 false
br i1 %26, label %15, label %27
27: ; preds = %15
%28 = icmp ugt i32 %22, 1
br i1 %28, label %11, label %29
29: ; preds = %11, %27
%30 = getelementptr inbounds i32, i32* %0, i64 %9
store i32 %14, i32* %30
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %14)
%32 = add nuw nsw i64 %9, 1
%33 = icmp eq i64 %32, %7
br i1 %33, label %34, label %8
34: ; preds = %29, %2
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
ret i32 0
}