#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();
int /*<<< orphan*/ swap_int(int *, int *);
void shuffle(int vec[], const int len) {
  int i, pos1, pos2;
  for (i = 0; i < 2 * len; i++) {
    pos1 = rand() % 4;
    pos2 = rand() % 4;
    swap_int(&vec[pos1], &vec[pos2]);
  }
}


x86 assembly (clang, -O0):
<shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jge    119c <shuffle+0x7c>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <swap_int@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <shuffle+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle>:
push   %rbp
push   %r14
push   %rbx
test   %esi,%esi
jle    1181 <shuffle+0x61>
mov    %rdi,%r14
add    %esi,%esi
cmp    $0x2,%esi
mov    $0x1,%ebp
cmovge %esi,%ebp
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,%ebx
lea    0x3(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
and    $0xfffffffc,%eax
sub    %eax,%ebx
xor    %eax,%eax
call   1040 <rand@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
movslq %ebx,%rcx
lea    (%r14,%rcx,4),%rdi
cltq
lea    (%r14,%rax,4),%rsi
call   1030 <swap_int@plt>
add    $0xffffffff,%ebp
jne    1140 <shuffle+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @shuffle(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %8
8: ; preds = %27, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = mul nsw i32 2, %10
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %30
13: ; preds = %8
%14 = call i32 (...) @rand()
%15 = srem i32 %14, 4
store i32 %15, i32* %6
%16 = call i32 (...) @rand()
%17 = srem i32 %16, 4
store i32 %17, i32* %7
%18 = load i32*, i32** %3
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
%22 = load i32*, i32** %3
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = call i32 @swap_int(i32* %21, i32* %25)
br label %27
27: ; preds = %13
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %8
30: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @shuffle(i32* %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %20
4: ; preds = %2
%5 = shl nuw i32 %1, 1
%6 = call i32 @llvm.smax.i32(i32 %5, i32 1)
br label %7
7: ; preds = %4, %7
%8 = phi i32 [ %18, %7 ], [ 0, %4 ]
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 4
%11 = tail call i32 (...) @rand()
%12 = srem i32 %11, 4
%13 = sext i32 %10 to i64
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = sext i32 %12 to i64
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = tail call i32 @swap_int(i32* %14, i32* %16)
%18 = add nuw nsw i32 %8, 1
%19 = icmp eq i32 %18, %6
br i1 %19, label %20, label %7
20: ; preds = %7, %2
ret void
}