#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*/ assert(int);
int /*<<< orphan*/ memcpy(long *, long *, size_t);
int /*<<< orphan*/ memmove(long *, long *, size_t);
int random_between(int /*<<< orphan*/, int);
void shuffle(long *A, int count) {
  assert(count >= 0);
  long buffer[count];
  int index = 0;
  int inputs = count;
  while (inputs > 0) {
    int r = random_between(0, inputs);
    buffer[index++] = A[r];
    memmove(&A[r], &A[r + 1], (size_t)(inputs - r - 1) * sizeof(long));
    inputs--;
  }
  memcpy(A, buffer, (size_t)count * sizeof(long));
}


x86 assembly (clang, -O0):
<shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
not    %edi
shr    $0x1f,%edi
call   1040 <assert@plt>
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    1210 <shuffle+0xd0>
mov    -0x28(%rbp),%esi
xor    %edi,%edi
call   1030 <random_between@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,-0x2c(%rbp)
mov    -0x8(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
mov    (%rcx,%rdx,8),%rdx
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x28(%rbp),%eax
sub    -0x2c(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rdx
shl    $0x3,%rdx
call   1060 <memmove@plt>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    1190 <shuffle+0x50>
mov    -0x38(%rbp),%rsi
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rdx
shl    $0x3,%rdx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r12
mov    %esi,%edi
not    %edi
shr    $0x1f,%edi
call   1040 <assert@plt>
mov    %ebx,%r13d
mov    %rsp,%r15
lea    0xf(,%r13,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %ebx,-0x2c(%rbp)
test   %ebx,%ebx
jle    11cb <shuffle+0x8b>
shl    $0x3,%r13
xor    %r14d,%r14d
mov    -0x2c(%rbp),%ebx
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %ebx,%esi
call   1030 <random_between@plt>
cltq
lea    (%r12,%rax,8),%rdi
mov    (%r12,%rax,8),%rcx
mov    %rcx,(%r15,%r14,1)
lea    (%r12,%rax,8),%rsi
add    $0x8,%rsi
not    %eax
add    %ebx,%eax
movslq %eax,%rdx
shl    $0x3,%rdx
call   1060 <memmove@plt>
add    $0xffffffff,%ebx
add    $0x8,%r14
cmp    %r14,%r13
jne    1190 <shuffle+0x50>
movslq -0x2c(%rbp),%rdx
shl    $0x3,%rdx
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <memcpy@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @shuffle(i64* %0, i32 %1) {
%3 = alloca i64*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i64* %0, i64** %3
store i32 %1, i32* %4
%10 = load i32, i32* %4
%11 = icmp sge i32 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i32, i32* %4
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %5
%17 = alloca i64, i64 %15
store i64 %15, i64* %6
store i32 0, i32* %7
%18 = load i32, i32* %4
store i32 %18, i32* %8
br label %19
19: ; preds = %22, %2
%20 = load i32, i32* %8
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %52
22: ; preds = %19
%23 = load i32, i32* %8
%24 = call i32 @random_between(i32 0, i32 %23)
store i32 %24, i32* %9
%25 = load i64*, i64** %3
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i64, i64* %25, i64 %27
%29 = load i64, i64* %28
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
%32 = sext i32 %30 to i64
%33 = getelementptr inbounds i64, i64* %17, i64 %32
store i64 %29, i64* %33
%34 = load i64*, i64** %3
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i64, i64* %34, i64 %36
%38 = load i64*, i64** %3
%39 = load i32, i32* %9
%40 = add nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i64, i64* %38, i64 %41
%43 = load i32, i32* %8
%44 = load i32, i32* %9
%45 = sub nsw i32 %43, %44
%46 = sub nsw i32 %45, 1
%47 = sext i32 %46 to i64
%48 = mul i64 %47, 8
%49 = call i32 @memmove(i64* %37, i64* %42, i64 %48)
%50 = load i32, i32* %8
%51 = add nsw i32 %50, -1
store i32 %51, i32* %8
br label %19
52: ; preds = %19
%53 = load i64*, i64** %3
%54 = load i32, i32* %4
%55 = sext i32 %54 to i64
%56 = mul i64 %55, 8
%57 = call i32 @memcpy(i64* %53, i64* %17, i64 %56)
%58 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
define void @shuffle(i64* %0, i32 %1) {
%3 = xor i32 %1, -1
%4 = lshr i32 %3, 31
%5 = tail call i32 @assert(i32 %4)
%6 = zext i32 %1 to i64
%7 = alloca i64, i64 %6
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %28
9: ; preds = %2, %9
%10 = phi i64 [ %16, %9 ], [ 0, %2 ]
%11 = phi i32 [ %26, %9 ], [ %1, %2 ]
%12 = tail call i32 @random_between(i32 0, i32 %11)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i64, i64* %0, i64 %13
%15 = load i64, i64* %14
%16 = add nuw nsw i64 %10, 1
%17 = getelementptr inbounds i64, i64* %7, i64 %10
store i64 %15, i64* %17
%18 = add nsw i32 %12, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i64, i64* %0, i64 %19
%21 = xor i32 %12, -1
%22 = add i32 %11, %21
%23 = sext i32 %22 to i64
%24 = shl nsw i64 %23, 3
%25 = tail call i32 @memmove(i64* %14, i64* %20, i64 %24)
%26 = add nsw i32 %11, -1
%27 = icmp eq i64 %16, %6
br i1 %27, label %28, label %9
28: ; preds = %9, %2
%29 = sext i32 %1 to i64
%30 = shl nsw i64 %29, 3
%31 = call i32 @memcpy(i64* %0, i64* %7, i64 %30)
ret void
}