#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*/ knuth_rand_subset(int *, size_t, size_t);
int /*<<< orphan*/ print_array(int *, size_t);
int /*<<< orphan*/ printf(char *);
int scanf(char *, size_t *, size_t *);
int /*<<< orphan*/ sorted_rand_subset(int *, size_t, size_t);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  srand(time(NULL));
  printf("Enter a number M and a number N to generate a sorted sequence of M "
         "unique random values in the range [0..N]\n");
  printf("Note: N >= M\n");
  printf("> ");
  size_t m, n;
  while (scanf("%zu%zu", &m, &n) == 2) {
    int array[m];
    sorted_rand_subset(array, m, n);
    printf("Suffle method: ");
    print_array(array, m);
    printf("Knuth's Algorithm S: ");
    knuth_rand_subset(array, m, n);
    print_array(array, m);
    printf("> ");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
lea    0xe6a(%rip),%rdi
call   1040 <printf@plt>
lea    0xecb(%rip),%rdi
call   1040 <printf@plt>
lea    0xecd(%rip),%rdi
call   1040 <printf@plt>
lea    0xec4(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1090 <scanf@plt>
cmp    $0x2,%eax
jne    1260 <main+0xf0>
mov    -0x10(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <sorted_rand_subset@plt>
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <print_array@plt>
lea    0xe70(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1070 <knuth_rand_subset@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <print_array@plt>
lea    0xe2c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
jmp    11b3 <main+0x43>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
lea    0xe8a(%rip),%rdi
call   1030 <puts@plt>
lea    0xeea(%rip),%rdi
call   1030 <puts@plt>
lea    0xe42(%rip),%rdi
call   1050 <printf@plt>
lea    0xe39(%rip),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   10a0 <scanf@plt>
cmp    $0x2,%eax
jne    1282 <main+0x102>
lea    0xe1c(%rip),%r13
lea    -0x30(%rbp),%rbx
lea    -0x38(%rbp),%r14
nop
mov    %rsp,%r12
mov    -0x30(%rbp),%rax
mov    %rsp,%r15
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    %r15,%rdi
call   1060 <sorted_rand_subset@plt>
lea    0xde7(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rsi
mov    %r15,%rdi
call   1040 <print_array@plt>
lea    0xddf(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    %r15,%rdi
call   1080 <knuth_rand_subset@plt>
mov    -0x30(%rbp),%rsi
mov    %r15,%rdi
call   1040 <print_array@plt>
lea    0xd9d(%rip),%rdi
call   1050 <printf@plt>
mov    %r12,%rsp
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   10a0 <scanf@plt>
cmp    $0x2,%eax
je     11f0 <main+0x70>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [109 x i8] c"Enter a number M and a number N to generate a sorted sequence of M unique random values in the range [0..N]\0A\00"
@.str.1 = [14 x i8] c"Note: N >= M\0A\00"
@.str.2 = [3 x i8] c"> \00"
@.str.3 = [7 x i8] c"%zu%zu\00"
@.str.4 = [16 x i8] c"Suffle method: \00"
@.str.5 = [22 x i8] c"Knuth's Algorithm S: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
store i32 0, i32* %1
%6 = call i32 @time(i32* null)
%7 = call i32 @srand(i32 %6)
%8 = call i32 @printf(i8* getelementptr inbounds ([109 x i8], [109 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %14, %0
%12 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64* %2, i64* %3)
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %32
14: ; preds = %11
%15 = load i64, i64* %2
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %4
%17 = alloca i32, i64 %15
store i64 %15, i64* %5
%18 = load i64, i64* %2
%19 = load i64, i64* %3
%20 = call i32 @sorted_rand_subset(i32* %17, i64 %18, i64 %19)
%21 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%22 = load i64, i64* %2
%23 = call i32 @print_array(i32* %17, i64 %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%25 = load i64, i64* %2
%26 = load i64, i64* %3
%27 = call i32 @knuth_rand_subset(i32* %17, i64 %25, i64 %26)
%28 = load i64, i64* %2
%29 = call i32 @print_array(i32* %17, i64 %28)
%30 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%31 = load i8*, i8** %4
br label %11
32: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"> \00"
@.str.3 = [7 x i8] c"%zu%zu\00"
@.str.4 = [16 x i8] c"Suffle method: \00"
@.str.5 = [22 x i8] c"Knuth's Algorithm S: \00"
@str = [108 x i8] c"Enter a number M and a number N to generate a sorted sequence of M unique random values in the range [0..N]\00"
@str.6 = [13 x i8] c"Note: N >= M\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([108 x i8], [108 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.6, i64 0, i64 0))
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%8 = bitcast i64* %1 to i8*
%9 = bitcast i64* %2 to i8*
%10 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64* %1, i64* %2)
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %31
12: ; preds = %0, %12
%13 = load i64, i64* %1
%14 = call i8* @llvm.stacksave()
%15 = alloca i32, i64 %13
%16 = load i64, i64* %1
%17 = load i64, i64* %2
%18 = call i32 @sorted_rand_subset(i32* %15, i64 %16, i64 %17)
%19 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%20 = load i64, i64* %1
%21 = call i32 @print_array(i32* %15, i64 %20)
%22 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%23 = load i64, i64* %1
%24 = load i64, i64* %2
%25 = call i32 @knuth_rand_subset(i32* %15, i64 %23, i64 %24)
%26 = load i64, i64* %1
%27 = call i32 @print_array(i32* %15, i64 %26)
%28 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64* %1, i64* %2)
%30 = icmp eq i32 %29, 2
br i1 %30, label %12, label %31
31: ; preds = %12, %0
ret i32 0
}