#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 /*<<< orphan*/ WriteSLUErrorMessage(char *);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ printf(char *, char *, int, int);
int /*<<< orphan*/ sprintf_s(char *, int, char *, char *);
int /*<<< orphan*/ superlu_abort_and_exit(char *);
int /*<<< orphan*/ superlu_free(int *);
int check_perm(char *what, int n, int *perm) {
  register int i;
  int *marker;
  marker = (int *)calloc(n, sizeof(int));
  for (i = 0; i < n; ++i) {
    if (marker[perm[i]] == 1 || perm[i] >= n) {
      printf("%s: Not a valid PERM[%d] = %d\n", what, i, perm[i]);
      {
        char msg[256];
        sprintf_s(msg, 256, "Error: %s", "check_perm");
        WriteSLUErrorMessage(msg);
        superlu_abort_and_exit(msg);
      };
    } else {
      marker[perm[i]] = 1;
    }
  }
  superlu_free(marker);
  return 0;
}


x86 assembly (clang, -O0):
<check_perm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    124c <check_perm+0xec>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
cmpl   $0x1,(%rax,%rcx,4)
je     11c8 <check_perm+0x68>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0xc(%rbp),%eax
jl     1222 <check_perm+0xc2>
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xe1f(%rip),%rdi
call   1050 <printf@plt>
lea    -0x130(%rbp),%rdi
mov    $0x100,%esi
lea    0xe26(%rip),%rdx
lea    0xe29(%rip),%rcx
call   1030 <sprintf_s@plt>
lea    -0x130(%rbp),%rdi
call   1060 <WriteSLUErrorMessage@plt>
lea    -0x130(%rbp),%rdi
call   1040 <superlu_abort_and_exit@plt>
jmp    1239 <check_perm+0xd9>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
movl   $0x1,(%rax,%rcx,4)
jmp    123e <check_perm+0xde>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118e <check_perm+0x2e>
mov    -0x28(%rbp),%rdi
call   1080 <superlu_free@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_perm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rdx,%r15
mov    %esi,%ebx
mov    %rdi,%r14
mov    %esi,%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
mov    %rax,%r12
test   %ebx,%ebx
jle    1202 <check_perm+0xa2>
mov    %ebx,%r13d
xor    %ebx,%ebx
mov    %rsp,%rbp
jmp    11e5 <check_perm+0x85>
cs nopw 0x0(%rax,%rax,1)
lea    0xe59(%rip),%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <printf@plt>
mov    %rbp,%rdi
mov    $0x100,%esi
lea    0xe5f(%rip),%rdx
lea    0xe62(%rip),%rcx
call   1030 <sprintf_s@plt>
mov    %rbp,%rdi
call   1060 <WriteSLUErrorMessage@plt>
mov    %rbp,%rdi
call   1040 <superlu_abort_and_exit@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
je     1202 <check_perm+0xa2>
mov    (%r15,%rbx,4),%ecx
movslq %ecx,%rax
cmpl   $0x1,(%r12,%rax,4)
je     11a0 <check_perm+0x40>
cmp    %r13d,%ecx
jge    11a0 <check_perm+0x40>
movl   $0x1,(%r12,%rax,4)
jmp    11dc <check_perm+0x7c>
mov    %r12,%rdi
call   1080 <superlu_free@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"%s: Not a valid PERM[%d] = %d\0A\00"
@.str.1 = [10 x i8] c"Error: %s\00"
@.str.2 = [11 x i8] c"check_perm\00"
define i32 @check_perm(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca [256 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%10 = load i32, i32* %5
%11 = call i64 @calloc(i32 %10, i32 4)
%12 = inttoptr i64 %11 to i32*
store i32* %12, i32** %8
store i32 0, i32* %7
br label %13
13: ; preds = %61, %3
%14 = load i32, i32* %7
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %64
17: ; preds = %13
%18 = load i32*, i32** %8
%19 = load i32*, i32** %6
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32, i32* %22
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %18, i64 %24
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 1
br i1 %27, label %36, label %28
28: ; preds = %17
%29 = load i32*, i32** %6
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = load i32, i32* %5
%35 = icmp sge i32 %33, %34
br i1 %35, label %36, label %51
36: ; preds = %28, %17
%37 = load i8*, i8** %4
%38 = load i32, i32* %7
%39 = load i32*, i32** %6
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
%43 = load i32, i32* %42
%44 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %37, i32 %38, i32 %43)
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%46 = call i32 @sprintf_s(i8* %45, i32 256, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%48 = call i32 @WriteSLUErrorMessage(i8* %47)
%49 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%50 = call i32 @superlu_abort_and_exit(i8* %49)
br label %60
51: ; preds = %28
%52 = load i32*, i32** %8
%53 = load i32*, i32** %6
%54 = load i32, i32* %7
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %53, i64 %55
%57 = load i32, i32* %56
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %52, i64 %58
store i32 1, i32* %59
br label %60
60: ; preds = %51, %36
br label %61
61: ; preds = %60
%62 = load i32, i32* %7
%63 = add nsw i32 %62, 1
store i32 %63, i32* %7
br label %13
64: ; preds = %13
%65 = load i32*, i32** %8
%66 = call i32 @superlu_free(i32* %65)
ret i32 0
}

LLVM IR (-O2):
@.str = [31 x i8] c"%s: Not a valid PERM[%d] = %d\0A\00"
@.str.1 = [10 x i8] c"Error: %s\00"
@.str.2 = [11 x i8] c"check_perm\00"
define i32 @check_perm(i8* %0, i32 %1, i32* nocapture %2) {
%4 = alloca [256 x i8]
%5 = tail call i64 @calloc(i32 %1, i32 4)
%6 = inttoptr i64 %5 to i32*
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %31
8: ; preds = %3
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%10 = zext i32 %1 to i64
br label %11
11: ; preds = %8, %28
%12 = phi i64 [ 0, %8 ], [ %29, %28 ]
%13 = getelementptr inbounds i32, i32* %2, i64 %12
%14 = load i32, i32* %13
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %6, i64 %15
%17 = load i32, i32* %16
%18 = icmp ne i32 %17, 1
%19 = icmp slt i32 %14, %1
%20 = select i1 %18, i1 %19, i1 false
br i1 %20, label %27, label %21
21: ; preds = %11
%22 = trunc i64 %12 to i32
%23 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %22, i32 %14)
%24 = call i32 @sprintf_s(i8* %9, i32 256, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @WriteSLUErrorMessage(i8* %9)
%26 = call i32 @superlu_abort_and_exit(i8* %9)
br label %28
27: ; preds = %11
store i32 1, i32* %16
br label %28
28: ; preds = %21, %27
%29 = add nuw nsw i64 %12, 1
%30 = icmp eq i64 %29, %10
br i1 %30, label %31, label %11
31: ; preds = %28, %3
%32 = call i32 @superlu_free(i32* %6)
ret i32 0
}