#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 _SCOTCHintRandVal(int);
void _SCOTCHintPerm(int *const permtab, const int permnbr) {
  int *permptr;
  int permrmn;
  for (permptr = permtab, permrmn = permnbr; permrmn > 0;
       permptr++, permrmn--) {
    int permnum;
    int permtmp;
    permnum = _SCOTCHintRandVal(permrmn);
    permtmp = permptr[0];
    permptr[0] = permptr[permnum];
    permptr[permnum] = permtmp;
  }
}


x86 assembly (clang, -O0):
<_SCOTCHintPerm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1184 <_SCOTCHintPerm+0x74>
mov    -0x1c(%rbp),%edi
call   1030 <_SCOTCHintRandVal@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    112d <_SCOTCHintPerm+0x1d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_SCOTCHintPerm>:
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
jle    1145 <_SCOTCHintPerm+0x35>
mov    %esi,%r14d
mov    %rdi,%rbx
xchg   %ax,%ax
mov    %r14d,%edi
call   1030 <_SCOTCHintRandVal@plt>
mov    (%rbx),%ecx
cltq
mov    (%rbx,%rax,4),%edx
mov    %edx,(%rbx)
mov    %ecx,(%rbx,%rax,4)
add    $0x4,%rbx
lea    -0x1(%r14),%eax
cmp    $0x1,%r14d
mov    %eax,%r14d
ja     1120 <_SCOTCHintPerm+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @_SCOTCHintPerm(i32* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %15
4: ; preds = %2, %4
%5 = phi i32* [ %12, %4 ], [ %0, %2 ]
%6 = phi i32 [ %13, %4 ], [ %1, %2 ]
%7 = tail call i32 @_SCOTCHintRandVal(i32 %6)
%8 = load i32, i32* %5
%9 = sext i32 %7 to i64
%10 = getelementptr inbounds i32, i32* %5, i64 %9
%11 = load i32, i32* %10
store i32 %11, i32* %5
store i32 %8, i32* %10
%12 = getelementptr inbounds i32, i32* %5, i64 1
%13 = add nsw i32 %6, -1
%14 = icmp ugt i32 %6, 1
br i1 %14, label %4, label %15
15: ; preds = %4, %2
ret void
}