#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();
shuffle_pieces(char *s) {
  int i, p1, p2;
  char tmp;
  for (i = 0; i < 100; i++) {
    p1 = rand() % 16;
    p2 = rand() % 16;
    tmp = s[4 * p1];
    s[4 * p1] = s[4 * p2];
    s[4 * p2] = tmp;
  }
}


x86 assembly (clang, -O0):
<shuffle_pieces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    11a5 <shuffle_pieces+0x95>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1d(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1d(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1123 <shuffle_pieces+0x13>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle_pieces>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x64,%ebp
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <rand@plt>
mov    %eax,%ebx
lea    0xf(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
and    $0xfffffff0,%eax
sub    %eax,%ebx
xor    %eax,%eax
call   1030 <rand@plt>
lea    0xf(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffff0,%ecx
sub    %ecx,%eax
movslq %ebx,%rcx
movzbl (%r14,%rcx,4),%edx
cltq
movzbl (%r14,%rax,4),%ebx
mov    %bl,(%r14,%rcx,4)
mov    %dl,(%r14,%rax,4)
add    $0xffffffff,%ebp
jne    1120 <shuffle_pieces+0x10>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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