#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 */
scalar_t__ RAND_MAX;
scalar_t__ rand();
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
void shuffleIntArray(int *ar, int size) {
  int j, k, tmp;
  double dran;
  srand((unsigned int)time(NULL));
  for (j = size - 1; j >= 0; j--) {
    dran = (double)rand() / (double)(RAND_MAX);
    k = (int)(j * dran);
    tmp = ar[j];
    ar[j] = ar[k];
    ar[k] = tmp;
  }
}


x86 assembly (clang, -O0):
<shuffleIntArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     11d4 <shuffleIntArray+0xa4>
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e73(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
cvtsi2sdl -0x10(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1158 <shuffleIntArray+0x28>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffleIntArray>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r15
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
test   %ebp,%ebp
jle    11ab <shuffleIntArray+0x7b>
mov    %ebp,%ebp
mov    0x2e91(%rip),%r14
nopw   0x0(%rax,%rax,1)
lea    -0x1(%rbp),%rbx
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq (%r14),%xmm1
xorps  %xmm2,%xmm2
cvtsi2sd %ebx,%xmm2
divsd  %xmm1,%xmm0
mulsd  %xmm0,%xmm2
cvttsd2si %xmm2,%eax
mov    %ebx,%ecx
mov    (%r15,%rcx,4),%edx
cltq
mov    (%r15,%rax,4),%esi
mov    %esi,(%r15,%rcx,4)
mov    %edx,(%r15,%rax,4)
cmp    $0x1,%rbp
mov    %rbx,%rbp
ja     1160 <shuffleIntArray+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
define void @shuffleIntArray(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
store i32* %0, i32** %3
store i32 %1, i32* %4
%9 = call i64 @time(i32* null)
%10 = trunc i64 %9 to i32
%11 = call i32 @srand(i32 %10)
%12 = load i32, i32* %4
%13 = sub nsw i32 %12, 1
store i32 %13, i32* %5
br label %14
14: ; preds = %47, %2
%15 = load i32, i32* %5
%16 = icmp sge i32 %15, 0
br i1 %16, label %17, label %50
17: ; preds = %14
%18 = call i64 (...) @rand()
%19 = sitofp i64 %18 to double
%20 = load i64, i64* @RAND_MAX
%21 = sitofp i64 %20 to double
%22 = fdiv double %19, %21
store double %22, double* %8
%23 = load i32, i32* %5
%24 = sitofp i32 %23 to double
%25 = load double, double* %8
%26 = fmul double %24, %25
%27 = fptosi double %26 to i32
store i32 %27, i32* %6
%28 = load i32*, i32** %3
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
store i32 %32, i32* %7
%33 = load i32*, i32** %3
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
%38 = load i32*, i32** %3
%39 = load i32, i32* %5
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
store i32 %37, i32* %41
%42 = load i32, i32* %7
%43 = load i32*, i32** %3
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
store i32 %42, i32* %46
br label %47
47: ; preds = %17
%48 = load i32, i32* %5
%49 = add nsw i32 %48, -1
store i32 %49, i32* %5
br label %14
50: ; preds = %14
ret void
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
define void @shuffleIntArray(i32* nocapture %0, i32 %1) {
%3 = tail call i64 @time(i32* null)
%4 = trunc i64 %3 to i32
%5 = tail call i32 @srand(i32 %4)
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %28
7: ; preds = %2
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ %8, %7 ], [ %11, %9 ]
%11 = add nsw i64 %10, -1
%12 = trunc i64 %11 to i32
%13 = tail call i64 (...) @rand()
%14 = sitofp i64 %13 to double
%15 = load i64, i64* @RAND_MAX
%16 = sitofp i64 %15 to double
%17 = fdiv double %14, %16
%18 = sitofp i32 %12 to double
%19 = fmul double %17, %18
%20 = fptosi double %19 to i32
%21 = and i64 %11, 4294967295
%22 = getelementptr inbounds i32, i32* %0, i64 %21
%23 = load i32, i32* %22
%24 = sext i32 %20 to i64
%25 = getelementptr inbounds i32, i32* %0, i64 %24
%26 = load i32, i32* %25
store i32 %26, i32* %22
store i32 %23, i32* %25
%27 = icmp ugt i64 %10, 1
br i1 %27, label %9, label %28
28: ; preds = %9, %2
ret void
}