#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 alea(int);
int /*<<< orphan*/ calloc(int, int);
void *check_ptr(int /*<<< orphan*/);
int code_to_string(int, char *);
int random_code(int);
int /*<<< orphan*/ strndup(char *, int);
char **genrights(int count, int permodif) {
  char buffer[20];
  char **result;
  int i, allow, len;
  result = check_ptr(calloc(sizeof *result, count));
  for (i = 0; i < count; i++) {
    allow = random_code(0);
    len = code_to_string(allow, buffer);
    if (permodif > alea(100)) {
      buffer[len++] = ' ';
      len += code_to_string(random_code(allow), buffer + len);
    }
    result[i] = check_ptr(strndup(buffer, len));
  }
  return result;
}


x86 assembly (clang, -O0):
<genrights>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%esi
mov    $0x8,%edi
call   1070 <calloc@plt>
mov    %eax,%edi
call   1080 <check_ptr@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1231 <genrights+0xd1>
xor    %edi,%edi
call   1050 <random_code@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1030 <code_to_string@plt>
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    $0x64,%edi
call   1040 <alea@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
cmp    %ecx,%eax
jle    1201 <genrights+0xa1>
mov    -0x34(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x34(%rbp)
cltq
movb   $0x20,-0x20(%rbp,%rax,1)
mov    -0x30(%rbp),%edi
call   1050 <random_code@plt>
mov    %eax,%edi
lea    -0x20(%rbp),%rsi
movslq -0x34(%rbp),%rax
add    %rax,%rsi
call   1030 <code_to_string@plt>
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1060 <strndup@plt>
mov    %eax,%edi
call   1080 <check_ptr@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    118d <genrights+0x2d>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genrights>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %esi,0xc(%rsp)
mov    %edi,%ebx
mov    $0x8,%edi
mov    %ebx,%esi
call   1070 <calloc@plt>
mov    %eax,%edi
call   1080 <check_ptr@plt>
mov    %rax,%r13
test   %ebx,%ebx
jle    1224 <genrights+0xc4>
mov    %ebx,%r15d
xor    %r14d,%r14d
lea    0x20(%rsp),%r12
mov    %r15,0x18(%rsp)
mov    %r13,0x10(%rsp)
jmp    11cf <genrights+0x6f>
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %ebx,%esi
call   1060 <strndup@plt>
mov    %eax,%edi
call   1080 <check_ptr@plt>
mov    %rax,0x0(%r13,%r14,8)
add    $0x1,%r14
cmp    %r14,%r15
je     1224 <genrights+0xc4>
xor    %edi,%edi
call   1050 <random_code@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r12,%rsi
call   1030 <code_to_string@plt>
mov    %eax,%ebx
mov    $0x64,%edi
call   1040 <alea@plt>
cmp    0xc(%rsp),%eax
jge    11b0 <genrights+0x50>
movslq %ebx,%r15
movb   $0x20,0x20(%rsp,%r15,1)
mov    %ebp,%edi
call   1050 <random_code@plt>
lea    (%rsp,%r15,1),%rsi
add    $0x21,%rsi
mov    0x10(%rsp),%r13
mov    0x18(%rsp),%r15
mov    %eax,%edi
call   1030 <code_to_string@plt>
add    %eax,%ebx
add    $0x1,%ebx
jmp    11b0 <genrights+0x50>
mov    %r13,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8** @genrights(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [20 x i8]
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%10 = load i32, i32* %3
%11 = call i32 @calloc(i32 8, i32 %10)
%12 = call i8* @check_ptr(i32 %11)
%13 = bitcast i8* %12 to i8**
store i8** %13, i8*** %6
store i32 0, i32* %7
br label %14
14: ; preds = %49, %2
%15 = load i32, i32* %7
%16 = load i32, i32* %3
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %52
18: ; preds = %14
%19 = call i32 @random_code(i32 0)
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%22 = call i32 @code_to_string(i32 %20, i8* %21)
store i32 %22, i32* %9
%23 = load i32, i32* %4
%24 = call i32 @alea(i32 100)
%25 = icmp sgt i32 %23, %24
br i1 %25, label %26, label %40
26: ; preds = %18
%27 = load i32, i32* %9
%28 = add nsw i32 %27, 1
store i32 %28, i32* %9
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 %29
store i8 32, i8* %30
%31 = load i32, i32* %8
%32 = call i32 @random_code(i32 %31)
%33 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = call i32 @code_to_string(i32 %32, i8* %36)
%38 = load i32, i32* %9
%39 = add nsw i32 %38, %37
store i32 %39, i32* %9
br label %40
40: ; preds = %26, %18
%41 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%42 = load i32, i32* %9
%43 = call i32 @strndup(i8* %41, i32 %42)
%44 = call i8* @check_ptr(i32 %43)
%45 = load i8**, i8*** %6
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
store i8* %44, i8** %48
br label %49
49: ; preds = %40
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
store i32 %51, i32* %7
br label %14
52: ; preds = %14
%53 = load i8**, i8*** %6
ret i8** %53
}

LLVM IR (-O2):
define i8** @genrights(i32 %0, i32 %1) {
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @calloc(i32 8, i32 %0)
%6 = tail call i8* @check_ptr(i32 %5)
%7 = bitcast i8* %6 to i8**
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %33
9: ; preds = %2
%10 = zext i32 %0 to i64
br label %11
11: ; preds = %9, %26
%12 = phi i64 [ 0, %9 ], [ %31, %26 ]
%13 = call i32 @random_code(i32 0)
%14 = call i32 @code_to_string(i32 %13, i8* %4)
%15 = call i32 @alea(i32 100)
%16 = icmp slt i32 %15, %1
br i1 %16, label %17, label %26
17: ; preds = %11
%18 = add nsw i32 %14, 1
%19 = sext i32 %14 to i64
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 %19
store i8 32, i8* %20
%21 = call i32 @random_code(i32 %13)
%22 = sext i32 %18 to i64
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 %22
%24 = call i32 @code_to_string(i32 %21, i8* %23)
%25 = add nsw i32 %24, %18
br label %26
26: ; preds = %17, %11
%27 = phi i32 [ %25, %17 ], [ %14, %11 ]
%28 = call i32 @strndup(i8* %4, i32 %27)
%29 = call i8* @check_ptr(i32 %28)
%30 = getelementptr inbounds i8*, i8** %7, i64 %12
store i8* %29, i8** %30
%31 = add nuw nsw i64 %12, 1
%32 = icmp eq i64 %31, %10
br i1 %32, label %33, label %11
33: ; preds = %26, %2
ret i8** %7
}