#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();
void mkuniq(int *v, int N) {
  int i, x, already[10000];
  for (i = 0; i < 10000; i++)
    already[i] = 0;
  i = 0;
  while (i < N) {
    x = 1 + rand() % (10000 - 1);
    if (already[x])
      continue;
    v[i++] = x;
    already[x]++;
  }
}


x86 assembly (clang, -O0):
<mkuniq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x2710,-0x10(%rbp)
jge    1153 <mkuniq+0x43>
movslq -0x10(%rbp),%rax
movl   $0x0,-0x9c60(%rbp,%rax,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1129 <mkuniq+0x19>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c4 <mkuniq+0xb4>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x270f,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmpl   $0x0,-0x9c60(%rbp,%rax,4)
je     1192 <mkuniq+0x82>
jmp    115a <mkuniq+0x4a>
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x10(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
movslq -0x14(%rbp),%rax
mov    -0x9c60(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x9c60(%rbp,%rax,4)
jmp    115a <mkuniq+0x4a>
add    $0x9c60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkuniq>:
push   %rbp
push   %r14
push   %rbx
sub    $0x9c40,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x9c40,%edx
xor    %esi,%esi
call   1030 <memset@plt>
test   %ebp,%ebp
jle    119f <mkuniq+0x7f>
mov    %ebp,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand@plt>
movslq %eax,%rcx
imul   $0x68de3af,%rcx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x28,%rdx
add    %esi,%edx
imul   $0x270f,%edx,%edx
sub    %edx,%ecx
movslq %ecx,%rcx
cmpl   $0x0,0x4(%rsp,%rcx,4)
jne    1150 <mkuniq+0x30>
neg    %edx
add    %edx,%eax
add    $0x1,%eax
add    $0x1,%rcx
mov    %eax,(%r14,%rbx,4)
add    $0x1,%rbx
movl   $0x1,(%rsp,%rcx,4)
cmp    %rbp,%rbx
jne    1150 <mkuniq+0x30>
add    $0x9c40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define void @mkuniq(i32* nocapture writeonly %0, i32 %1) {
%3 = alloca [10000 x i32]
%4 = bitcast [10000 x i32]* %3 to i8*
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %23
6: ; preds = %2
%7 = zext i32 %1 to i64
br label %21
8: ; preds = %21, %8
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 9999
%11 = add nsw i32 %10, 1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [10000 x i32], [10000 x i32]* %3, i64 0, i64 %12
%14 = load i32, i32* %13
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %8
16: ; preds = %8
%17 = getelementptr inbounds [10000 x i32], [10000 x i32]* %3, i64 0, i64 %12
%18 = add nuw nsw i64 %22, 1
%19 = getelementptr inbounds i32, i32* %0, i64 %22
store i32 %11, i32* %19
store i32 1, i32* %17
%20 = icmp eq i64 %18, %7
br i1 %20, label %23, label %21
21: ; preds = %6, %16
%22 = phi i64 [ 0, %6 ], [ %18, %16 ]
br label %8
23: ; preds = %16, %2
ret void
}