#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__ random();
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 = ((int)(((unsigned int)random()) % ((unsigned int)(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    1188 <_SCOTCHintPerm+0x78>
mov    $0x0,%al
call   1030 <random@plt>
xor    %edx,%edx
divl   -0x1c(%rbp)
mov    %edx,-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    1147 <_SCOTCHintPerm+0x37>
mov    %esi,%r14d
mov    %rdi,%rbx
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <random@plt>
xor    %edx,%edx
div    %r14d
mov    (%rbx),%eax
mov    (%rbx,%rdx,4),%ecx
mov    %ecx,(%rbx)
mov    %eax,(%rbx,%rdx,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 = %34, %2
%12 = load i32, i32* %6
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %39
14: ; preds = %11
%15 = call i64 (...) @random()
%16 = trunc i64 %15 to i32
%17 = load i32, i32* %6
%18 = urem i32 %16, %17
store i32 %18, i32* %7
%19 = load i32*, i32** %5
%20 = getelementptr inbounds i32, i32* %19, i64 0
%21 = load i32, i32* %20
store i32 %21, i32* %8
%22 = load i32*, i32** %5
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = load i32*, i32** %5
%28 = getelementptr inbounds i32, i32* %27, i64 0
store i32 %26, i32* %28
%29 = load i32, i32* %8
%30 = load i32*, i32** %5
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
store i32 %29, i32* %33
br label %34
34: ; preds = %14
%35 = load i32*, i32** %5
%36 = getelementptr inbounds i32, i32* %35, i32 1
store i32* %36, i32** %5
%37 = load i32, i32* %6
%38 = add nsw i32 %37, -1
store i32 %38, i32* %6
br label %11
39: ; 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 %17
4: ; preds = %2, %4
%5 = phi i32* [ %14, %4 ], [ %0, %2 ]
%6 = phi i32 [ %15, %4 ], [ %1, %2 ]
%7 = tail call i64 (...) @random()
%8 = trunc i64 %7 to i32
%9 = urem i32 %8, %6
%10 = load i32, i32* %5
%11 = zext i32 %9 to i64
%12 = getelementptr inbounds i32, i32* %5, i64 %11
%13 = load i32, i32* %12
store i32 %13, i32* %5
store i32 %10, i32* %12
%14 = getelementptr inbounds i32, i32* %5, i64 1
%15 = add nsw i32 %6, -1
%16 = icmp ugt i32 %6, 1
br i1 %16, label %4, label %17
17: ; preds = %4, %2
ret void
}