#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 */
typedef int /*<<< orphan*/ randvals;
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ gfshare_fill_rand(unsigned char *, int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int32_t init_sharenrs(unsigned char sharenrs[255], unsigned char *orig,
                      int32_t m, int32_t n) {
  unsigned char randvals[65536], valid[255];
  int32_t i, j, r, remains, orign;
  if (m > n || n >= 0xff) {
    printf("illegal M.%d of N.%d\n", m, n);
    return (-1);
  }
  gfshare_fill_rand(randvals, sizeof(randvals));
  memset(sharenrs, 0, n);
  if (orig == 0 && n == m) {
    for (i = 0; i < 255; i++)
      valid[i] = (i + 1);
    remains = orign = 255;
    for (i = 0; i < n; i++) {
      r = (randvals[i] % remains);
      sharenrs[i] = valid[r];
      printf("%d ", sharenrs[i]);
      valid[r] = valid[--remains];
    }
    printf("FULL SET\n");
  } else {
    remains = n;
    orign = n;
    memcpy(valid, orig, n);
    i = j = 0;
    while (i < m) {
      if (j >= sizeof(randvals)) {
        gfshare_fill_rand(randvals, sizeof(randvals));
        printf("refill j.%d\n", j);
        j = 0;
      }
      r = (randvals[j++] % n);
      if (valid[r] != 0) {
        remains--;
        i++;
        sharenrs[r] = valid[r];
        valid[r] = 0;
      }
    }
  }
  if (remains != (orign - m)) {
    printf("remains algo error??\n");
    return (-1);
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < m; j++) {
      if (i == j)
        continue;
      if (sharenrs[i] != 0 && sharenrs[i] == sharenrs[j]) {
        printf("FATAL: duplicate entry sharenrs[%d] %d vs %d sharenrs[%d]\n", i,
               sharenrs[i], sharenrs[j], j);
        return (-1);
      }
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<init_sharenrs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     1172 <init_sharenrs+0x32>
cmpl   $0xff,-0x20(%rbp)
jl     1192 <init_sharenrs+0x52>
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    152e <init_sharenrs+0x3ee>
lea    -0x10020(%rbp),%rdi
mov    $0x10000,%esi
call   1030 <gfshare_fill_rand@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%edx
xor    %esi,%esi
call   1050 <memset@plt>
cmpq   $0x0,-0x18(%rbp)
jne    12de <init_sharenrs+0x19e>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    12de <init_sharenrs+0x19e>
movl   $0x0,-0x10124(%rbp)
cmpl   $0xff,-0x10124(%rbp)
jge    120f <init_sharenrs+0xcf>
mov    -0x10124(%rbp),%eax
add    $0x1,%eax
mov    %al,%cl
movslq -0x10124(%rbp),%rax
mov    %cl,-0x10120(%rbp,%rax,1)
mov    -0x10124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10124(%rbp)
jmp    11d2 <init_sharenrs+0x92>
movl   $0xff,-0x10134(%rbp)
movl   $0xff,-0x10130(%rbp)
movl   $0x0,-0x10124(%rbp)
mov    -0x10124(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12cb <init_sharenrs+0x18b>
movslq -0x10124(%rbp),%rax
movzbl -0x10020(%rbp,%rax,1),%eax
ff
cltd
idivl  -0x10130(%rbp)
mov    %edx,-0x1012c(%rbp)
movslq -0x1012c(%rbp),%rax
mov    -0x10120(%rbp,%rax,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x10124(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq -0x10124(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xd8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10130(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10130(%rbp)
cltq
mov    -0x10120(%rbp,%rax,1),%cl
movslq -0x1012c(%rbp),%rax
mov    %cl,-0x10120(%rbp,%rax,1)
mov    -0x10124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10124(%rbp)
jmp    122d <init_sharenrs+0xed>
lea    0xd48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    13f8 <init_sharenrs+0x2b8>
mov    -0x20(%rbp),%eax
mov    %eax,-0x10130(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x10134(%rbp)
lea    -0x10120(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1060 <memcpy@plt>
movl   $0x0,-0x10128(%rbp)
movl   $0x0,-0x10124(%rbp)
mov    -0x10124(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    13f3 <init_sharenrs+0x2b3>
movslq -0x10128(%rbp),%rax
cmp    $0x10000,%rax
jb     1368 <init_sharenrs+0x228>
lea    -0x10020(%rbp),%rdi
mov    $0x10000,%esi
call   1030 <gfshare_fill_rand@plt>
mov    -0x10128(%rbp),%esi
lea    0xccd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x10128(%rbp)
mov    -0x10128(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x10128(%rbp)
cltq
movzbl -0x10020(%rbp,%rax,1),%eax
ff
cltd
idivl  -0x20(%rbp)
mov    %edx,-0x1012c(%rbp)
movslq -0x1012c(%rbp),%rax
movzbl -0x10120(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     13ee <init_sharenrs+0x2ae>
mov    -0x10130(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10130(%rbp)
mov    -0x10124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10124(%rbp)
movslq -0x1012c(%rbp),%rax
mov    -0x10120(%rbp,%rax,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x1012c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
movslq -0x1012c(%rbp),%rax
movb   $0x0,-0x10120(%rbp,%rax,1)
jmp    1317 <init_sharenrs+0x1d7>
jmp    13f8 <init_sharenrs+0x2b8>
mov    -0x10130(%rbp),%eax
mov    -0x10134(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
cmp    %ecx,%eax
je     1429 <init_sharenrs+0x2e9>
lea    0xc1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    152e <init_sharenrs+0x3ee>
movl   $0x0,-0x10124(%rbp)
mov    -0x10124(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1527 <init_sharenrs+0x3e7>
movl   $0x0,-0x10128(%rbp)
mov    -0x10128(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    150e <init_sharenrs+0x3ce>
mov    -0x10124(%rbp),%eax
cmp    -0x10128(%rbp),%eax
jne    1472 <init_sharenrs+0x332>
jmp    14fa <init_sharenrs+0x3ba>
mov    -0x10(%rbp),%rax
movslq -0x10124(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     14f5 <init_sharenrs+0x3b5>
mov    -0x10(%rbp),%rax
movslq -0x10124(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    -0x10(%rbp),%rcx
movslq -0x10128(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    14f5 <init_sharenrs+0x3b5>
mov    -0x10124(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x10124(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
mov    -0x10(%rbp),%rax
movslq -0x10128(%rbp),%rcx
movzbl (%rax,%rcx,1),%ecx
mov    -0x10128(%rbp),%r8d
lea    0xb65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    152e <init_sharenrs+0x3ee>
jmp    14fa <init_sharenrs+0x3ba>
mov    -0x10128(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10128(%rbp)
jmp    144c <init_sharenrs+0x30c>
jmp    1513 <init_sharenrs+0x3d3>
mov    -0x10124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10124(%rbp)
jmp    1433 <init_sharenrs+0x2f3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_sharenrs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10118,%rsp
mov    %ecx,%r13d
mov    %edx,%r14d
cmp    %ecx,%edx
jg     132c <init_sharenrs+0x1dc>
cmp    $0xff,%r13d
jge    132c <init_sharenrs+0x1dc>
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0x110(%rsp),%rdi
mov    $0x10000,%esi
call   1040 <gfshare_fill_rand@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r13d,%edx
call   1060 <memset@plt>
test   %rbp,%rbp
jne    134a <init_sharenrs+0x1fa>
cmp    %r14d,%r13d
jne    134a <init_sharenrs+0x1fa>
movaps 0xe46(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe4a(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe4e(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe52(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe56(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe5a(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xe5e(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe62(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xe63(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xe64(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
movaps 0xe65(%rip),%xmm0
movaps %xmm0,0xb0(%rsp)
movaps 0xe66(%rip),%xmm0
movaps %xmm0,0xc0(%rsp)
movaps 0xe67(%rip),%xmm0
movaps %xmm0,0xd0(%rsp)
movaps 0xe68(%rip),%xmm0
movaps %xmm0,0xe0(%rsp)
movaps 0xe69(%rip),%xmm0
movaps %xmm0,0xf0(%rsp)
movabs $0xf8f7f6f5f4f3f2f1,%rax
f6 f7 f8
mov    %rax,0x100(%rsp)
movl   $0xfcfbfaf9,0x108(%rsp)
f9 fa fb fc
movw   $0xfefd,0x10c(%rsp)
movb   $0xff,0x10e(%rsp)
ff
mov    $0xff,%r13d
mov    $0xff,%r12d
test   %r14d,%r14d
jle    131b <init_sharenrs+0x1cb>
mov    %r14d,0xc(%rsp)
mov    %r14d,%r14d
mov    $0xfe,%r12d
xor    %r15d,%r15d
movzbl 0x110(%rsp,%r15,1),%eax
lea    0x1(%r12),%ecx
xor    %edx,%edx
idiv   %ecx
mov    %edx,%ebp
movzbl 0x10(%rsp,%rbp,1),%esi
mov    %sil,(%rbx,%r15,1)
lea    0xe12(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x10(%rsp,%r12,1),%eax
mov    %al,0x10(%rsp,%rbp,1)
add    $0x1,%r15
add    $0xffffffffffffffff,%r12
cmp    %r15,%r14
jne    12d0 <init_sharenrs+0x180>
add    $0x1,%r12d
mov    0xc(%rsp),%r14d
lea    0xe45(%rip),%rdi
call   1030 <puts@plt>
jmp    13d1 <init_sharenrs+0x281>
lea    0xdbd(%rip),%rdi
mov    %r14d,%esi
mov    %r13d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%eax
jmp    1448 <init_sharenrs+0x2f8>
lea    0x10(%rsp),%rdi
mov    %rbp,%rsi
mov    %r13d,%edx
call   1070 <memcpy@plt>
test   %r14d,%r14d
jle    13ce <init_sharenrs+0x27e>
xor    %ebp,%ebp
mov    %r13d,%r12d
xor    %r15d,%r15d
jmp    1378 <init_sharenrs+0x228>
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    %r14d,%r15d
jge    13d1 <init_sharenrs+0x281>
cmp    $0x10000,%ebp
jb     13a4 <init_sharenrs+0x254>
lea    0x110(%rsp),%rdi
mov    $0x10000,%esi
call   1040 <gfshare_fill_rand@plt>
lea    0xd71(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
movzbl 0x110(%rsp,%rax,1),%eax
xor    %edx,%edx
idiv   %r13d
movzbl 0x10(%rsp,%rdx,1),%eax
test   %al,%al
je     1370 <init_sharenrs+0x220>
add    $0xffffffff,%r12d
add    $0x1,%r15d
mov    %al,(%rbx,%rdx,1)
movb   $0x0,0x10(%rsp,%rdx,1)
jmp    1370 <init_sharenrs+0x220>
mov    %r13d,%r12d
sub    %r14d,%r13d
cmp    %r13d,%r12d
jne    1433 <init_sharenrs+0x2e3>
test   %r14d,%r14d
jle    1446 <init_sharenrs+0x2f6>
mov    %r14d,%edx
xor    %esi,%esi
xor    %eax,%eax
jmp    13f9 <init_sharenrs+0x2a9>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rsi
cmp    %rdx,%rsi
je     1448 <init_sharenrs+0x2f8>
xor    %r8d,%r8d
jmp    1409 <init_sharenrs+0x2b9>
xchg   %ax,%ax
add    $0x1,%r8
cmp    %r8,%rdx
je     13f0 <init_sharenrs+0x2a0>
cmp    %r8,%rsi
je     1400 <init_sharenrs+0x2b0>
movzbl (%rbx,%rsi,1),%ecx
test   %ecx,%ecx
je     1400 <init_sharenrs+0x2b0>
cmp    (%rbx,%r8,1),%cl
jne    1400 <init_sharenrs+0x2b0>
lea    0xcf4(%rip),%rdi
mov    %ecx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%eax
jmp    1448 <init_sharenrs+0x2f8>
lea    0xd18(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    1448 <init_sharenrs+0x2f8>
xor    %eax,%eax
add    $0x10118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"illegal M.%d of N.%d\0A\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [10 x i8] c"FULL SET\0A\00"
@.str.3 = [13 x i8] c"refill j.%d\0A\00"
@.str.4 = [22 x i8] c"remains algo error??\0A\00"
@.str.5 = [59 x i8] c"FATAL: duplicate entry sharenrs[%d] %d vs %d sharenrs[%d]\0A\00"
define i32 @init_sharenrs(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [65536 x i8]
%11 = alloca [255 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%17 = load i32, i32* %8
%18 = load i32, i32* %9
%19 = icmp sgt i32 %17, %18
br i1 %19, label %23, label %20
20: ; preds = %4
%21 = load i32, i32* %9
%22 = icmp sge i32 %21, 255
br i1 %22, label %23, label %27
23: ; preds = %20, %4
%24 = load i32, i32* %8
%25 = load i32, i32* %9
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %24, i32 %25)
store i32 -1, i32* %5
br label %217
27: ; preds = %20
%28 = getelementptr inbounds [65536 x i8], [65536 x i8]* %10, i64 0, i64 0
%29 = call i32 @gfshare_fill_rand(i8* %28, i32 65536)
%30 = load i8*, i8** %6
%31 = load i32, i32* %9
%32 = call i32 @memset(i8* %30, i32 0, i32 %31)
%33 = load i8*, i8** %7
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %94
35: ; preds = %27
%36 = load i32, i32* %9
%37 = load i32, i32* %8
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %94
39: ; preds = %35
store i32 0, i32* %12
br label %40
40: ; preds = %50, %39
%41 = load i32, i32* %12
%42 = icmp slt i32 %41, 255
br i1 %42, label %43, label %53
43: ; preds = %40
%44 = load i32, i32* %12
%45 = add nsw i32 %44, 1
%46 = trunc i32 %45 to i8
%47 = load i32, i32* %12
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 %48
store i8 %46, i8* %49
br label %50
50: ; preds = %43
%51 = load i32, i32* %12
%52 = add nsw i32 %51, 1
store i32 %52, i32* %12
br label %40
53: ; preds = %40
store i32 255, i32* %16
store i32 255, i32* %15
store i32 0, i32* %12
br label %54
54: ; preds = %89, %53
%55 = load i32, i32* %12
%56 = load i32, i32* %9
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %92
58: ; preds = %54
%59 = load i32, i32* %12
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [65536 x i8], [65536 x i8]* %10, i64 0, i64 %60
%62 = load i8, i8* %61
%63 = zext i8 %62 to i32
%64 = load i32, i32* %15
%65 = srem i32 %63, %64
store i32 %65, i32* %14
%66 = load i32, i32* %14
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 %67
%69 = load i8, i8* %68
%70 = load i8*, i8** %6
%71 = load i32, i32* %12
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %70, i64 %72
store i8 %69, i8* %73
%74 = load i8*, i8** %6
%75 = load i32, i32* %12
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %74, i64 %76
%78 = load i8, i8* %77
%79 = zext i8 %78 to i32
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %79)
%81 = load i32, i32* %15
%82 = add nsw i32 %81, -1
store i32 %82, i32* %15
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 %83
%85 = load i8, i8* %84
%86 = load i32, i32* %14
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 %87
store i8 %85, i8* %88
br label %89
89: ; preds = %58
%90 = load i32, i32* %12
%91 = add nsw i32 %90, 1
store i32 %91, i32* %12
br label %54
92: ; preds = %54
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %147
94: ; preds = %35, %27
%95 = load i32, i32* %9
store i32 %95, i32* %15
%96 = load i32, i32* %9
store i32 %96, i32* %16
%97 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 0
%98 = load i8*, i8** %7
%99 = load i32, i32* %9
%100 = call i32 @memcpy(i8* %97, i8* %98, i32 %99)
store i32 0, i32* %13
store i32 0, i32* %12
br label %101
101: ; preds = %145, %94
%102 = load i32, i32* %12
%103 = load i32, i32* %8
%104 = icmp slt i32 %102, %103
br i1 %104, label %105, label %146
105: ; preds = %101
%106 = load i32, i32* %13
%107 = sext i32 %106 to i64
%108 = icmp uge i64 %107, 65536
br i1 %108, label %109, label %114
109: ; preds = %105
%110 = getelementptr inbounds [65536 x i8], [65536 x i8]* %10, i64 0, i64 0
%111 = call i32 @gfshare_fill_rand(i8* %110, i32 65536)
%112 = load i32, i32* %13
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %112)
store i32 0, i32* %13
br label %114
114: ; preds = %109, %105
%115 = load i32, i32* %13
%116 = add nsw i32 %115, 1
store i32 %116, i32* %13
%117 = sext i32 %115 to i64
%118 = getelementptr inbounds [65536 x i8], [65536 x i8]* %10, i64 0, i64 %117
%119 = load i8, i8* %118
%120 = zext i8 %119 to i32
%121 = load i32, i32* %9
%122 = srem i32 %120, %121
store i32 %122, i32* %14
%123 = load i32, i32* %14
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 %124
%126 = load i8, i8* %125
%127 = zext i8 %126 to i32
%128 = icmp ne i32 %127, 0
br i1 %128, label %129, label %145
129: ; preds = %114
%130 = load i32, i32* %15
%131 = add nsw i32 %130, -1
store i32 %131, i32* %15
%132 = load i32, i32* %12
%133 = add nsw i32 %132, 1
store i32 %133, i32* %12
%134 = load i32, i32* %14
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 %135
%137 = load i8, i8* %136
%138 = load i8*, i8** %6
%139 = load i32, i32* %14
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds i8, i8* %138, i64 %140
store i8 %137, i8* %141
%142 = load i32, i32* %14
%143 = sext i32 %142 to i64
%144 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 %143
store i8 0, i8* %144
br label %145
145: ; preds = %129, %114
br label %101
146: ; preds = %101
br label %147
147: ; preds = %146, %92
%148 = load i32, i32* %15
%149 = load i32, i32* %16
%150 = load i32, i32* %8
%151 = sub nsw i32 %149, %150
%152 = icmp ne i32 %148, %151
br i1 %152, label %153, label %155
153: ; preds = %147
%154 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %5
br label %217
155: ; preds = %147
store i32 0, i32* %12
br label %156
156: ; preds = %213, %155
%157 = load i32, i32* %12
%158 = load i32, i32* %8
%159 = icmp slt i32 %157, %158
br i1 %159, label %160, label %216
160: ; preds = %156
store i32 0, i32* %13
br label %161
161: ; preds = %209, %160
%162 = load i32, i32* %13
%163 = load i32, i32* %8
%164 = icmp slt i32 %162, %163
br i1 %164, label %165, label %212
165: ; preds = %161
%166 = load i32, i32* %12
%167 = load i32, i32* %13
%168 = icmp eq i32 %166, %167
br i1 %168, label %169, label %170
169: ; preds = %165
br label %209
170: ; preds = %165
%171 = load i8*, i8** %6
%172 = load i32, i32* %12
%173 = sext i32 %172 to i64
%174 = getelementptr inbounds i8, i8* %171, i64 %173
%175 = load i8, i8* %174
%176 = zext i8 %175 to i32
%177 = icmp ne i32 %176, 0
br i1 %177, label %178, label %208
178: ; preds = %170
%179 = load i8*, i8** %6
%180 = load i32, i32* %12
%181 = sext i32 %180 to i64
%182 = getelementptr inbounds i8, i8* %179, i64 %181
%183 = load i8, i8* %182
%184 = zext i8 %183 to i32
%185 = load i8*, i8** %6
%186 = load i32, i32* %13
%187 = sext i32 %186 to i64
%188 = getelementptr inbounds i8, i8* %185, i64 %187
%189 = load i8, i8* %188
%190 = zext i8 %189 to i32
%191 = icmp eq i32 %184, %190
br i1 %191, label %192, label %208
192: ; preds = %178
%193 = load i32, i32* %12
%194 = load i8*, i8** %6
%195 = load i32, i32* %12
%196 = sext i32 %195 to i64
%197 = getelementptr inbounds i8, i8* %194, i64 %196
%198 = load i8, i8* %197
%199 = zext i8 %198 to i32
%200 = load i8*, i8** %6
%201 = load i32, i32* %13
%202 = sext i32 %201 to i64
%203 = getelementptr inbounds i8, i8* %200, i64 %202
%204 = load i8, i8* %203
%205 = zext i8 %204 to i32
%206 = load i32, i32* %13
%207 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.5, i64 0, i64 0), i32 %193, i32 %199, i32 %205, i32 %206)
store i32 -1, i32* %5
br label %217
208: ; preds = %178, %170
br label %209
209: ; preds = %208, %169
%210 = load i32, i32* %13
%211 = add nsw i32 %210, 1
store i32 %211, i32* %13
br label %161
212: ; preds = %161
br label %213
213: ; preds = %212
%214 = load i32, i32* %12
%215 = add nsw i32 %214, 1
store i32 %215, i32* %12
br label %156
216: ; preds = %156
store i32 0, i32* %5
br label %217
217: ; preds = %216, %192, %153, %23
%218 = load i32, i32* %5
ret i32 %218
}

LLVM IR (-O2):
@.str = [22 x i8] c"illegal M.%d of N.%d\0A\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.3 = [13 x i8] c"refill j.%d\0A\00"
@.str.5 = [59 x i8] c"FATAL: duplicate entry sharenrs[%d] %d vs %d sharenrs[%d]\0A\00"
@str = [21 x i8] c"remains algo error??\00"
@str.6 = [9 x i8] c"FULL SET\00"
define i32 @init_sharenrs(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca [65536 x i8]
%6 = alloca [255 x i8]
%7 = getelementptr inbounds [65536 x i8], [65536 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%9 = icmp sgt i32 %2, %3
%10 = icmp sgt i32 %3, 254
%11 = or i1 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %4
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %3)
br label %158
14: ; preds = %4
%15 = call i32 @gfshare_fill_rand(i8* %7, i32 65536)
%16 = call i32 @memset(i8* %0, i32 0, i32 %3)
%17 = icmp eq i8* %1, null
%18 = icmp eq i32 %3, %2
%19 = and i1 %17, %18
br i1 %19, label %20, label %92
20: ; preds = %14
%21 = bitcast [255 x i8]* %6 to <16 x i8>*
store <16 x i8> <i8 1, i8 2, i8 3, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16>, <16 x i8>* %21
%22 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 16
%23 = bitcast i8* %22 to <16 x i8>*
store <16 x i8> <i8 17, i8 18, i8 19, i8 20, i8 21, i8 22, i8 23, i8 24, i8 25, i8 26, i8 27, i8 28, i8 29, i8 30, i8 31, i8 32>, <16 x i8>* %23
%24 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 32
%25 = bitcast i8* %24 to <16 x i8>*
store <16 x i8> <i8 33, i8 34, i8 35, i8 36, i8 37, i8 38, i8 39, i8 40, i8 41, i8 42, i8 43, i8 44, i8 45, i8 46, i8 47, i8 48>, <16 x i8>* %25
%26 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 48
%27 = bitcast i8* %26 to <16 x i8>*
store <16 x i8> <i8 49, i8 50, i8 51, i8 52, i8 53, i8 54, i8 55, i8 56, i8 57, i8 58, i8 59, i8 60, i8 61, i8 62, i8 63, i8 64>, <16 x i8>* %27
%28 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 64
%29 = bitcast i8* %28 to <16 x i8>*
store <16 x i8> <i8 65, i8 66, i8 67, i8 68, i8 69, i8 70, i8 71, i8 72, i8 73, i8 74, i8 75, i8 76, i8 77, i8 78, i8 79, i8 80>, <16 x i8>* %29
%30 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 80
%31 = bitcast i8* %30 to <16 x i8>*
store <16 x i8> <i8 81, i8 82, i8 83, i8 84, i8 85, i8 86, i8 87, i8 88, i8 89, i8 90, i8 91, i8 92, i8 93, i8 94, i8 95, i8 96>, <16 x i8>* %31
%32 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 96
%33 = bitcast i8* %32 to <16 x i8>*
store <16 x i8> <i8 97, i8 98, i8 99, i8 100, i8 101, i8 102, i8 103, i8 104, i8 105, i8 106, i8 107, i8 108, i8 109, i8 110, i8 111, i8 112>, <16 x i8>* %33
%34 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 112
%35 = bitcast i8* %34 to <16 x i8>*
store <16 x i8> <i8 113, i8 114, i8 115, i8 116, i8 117, i8 118, i8 119, i8 120, i8 121, i8 122, i8 123, i8 124, i8 125, i8 126, i8 127, i8 -128>, <16 x i8>* %35
%36 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 128
%37 = bitcast i8* %36 to <16 x i8>*
store <16 x i8> <i8 -127, i8 -126, i8 -125, i8 -124, i8 -123, i8 -122, i8 -121, i8 -120, i8 -119, i8 -118, i8 -117, i8 -116, i8 -115, i8 -114, i8 -113, i8 -112>, <16 x i8>* %37
%38 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 144
%39 = bitcast i8* %38 to <16 x i8>*
store <16 x i8> <i8 -111, i8 -110, i8 -109, i8 -108, i8 -107, i8 -106, i8 -105, i8 -104, i8 -103, i8 -102, i8 -101, i8 -100, i8 -99, i8 -98, i8 -97, i8 -96>, <16 x i8>* %39
%40 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 160
%41 = bitcast i8* %40 to <16 x i8>*
store <16 x i8> <i8 -95, i8 -94, i8 -93, i8 -92, i8 -91, i8 -90, i8 -89, i8 -88, i8 -87, i8 -86, i8 -85, i8 -84, i8 -83, i8 -82, i8 -81, i8 -80>, <16 x i8>* %41
%42 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 176
%43 = bitcast i8* %42 to <16 x i8>*
store <16 x i8> <i8 -79, i8 -78, i8 -77, i8 -76, i8 -75, i8 -74, i8 -73, i8 -72, i8 -71, i8 -70, i8 -69, i8 -68, i8 -67, i8 -66, i8 -65, i8 -64>, <16 x i8>* %43
%44 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 192
%45 = bitcast i8* %44 to <16 x i8>*
store <16 x i8> <i8 -63, i8 -62, i8 -61, i8 -60, i8 -59, i8 -58, i8 -57, i8 -56, i8 -55, i8 -54, i8 -53, i8 -52, i8 -51, i8 -50, i8 -49, i8 -48>, <16 x i8>* %45
%46 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 208
%47 = bitcast i8* %46 to <16 x i8>*
store <16 x i8> <i8 -47, i8 -46, i8 -45, i8 -44, i8 -43, i8 -42, i8 -41, i8 -40, i8 -39, i8 -38, i8 -37, i8 -36, i8 -35, i8 -34, i8 -33, i8 -32>, <16 x i8>* %47
%48 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 224
%49 = bitcast i8* %48 to <16 x i8>*
store <16 x i8> <i8 -31, i8 -30, i8 -29, i8 -28, i8 -27, i8 -26, i8 -25, i8 -24, i8 -23, i8 -22, i8 -21, i8 -20, i8 -19, i8 -18, i8 -17, i8 -16>, <16 x i8>* %49
%50 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 240
store i8 -15, i8* %50
%51 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 241
store i8 -14, i8* %51
%52 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 242
store i8 -13, i8* %52
%53 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 243
store i8 -12, i8* %53
%54 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 244
store i8 -11, i8* %54
%55 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 245
store i8 -10, i8* %55
%56 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 246
store i8 -9, i8* %56
%57 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 247
store i8 -8, i8* %57
%58 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 248
store i8 -7, i8* %58
%59 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 249
store i8 -6, i8* %59
%60 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 250
store i8 -5, i8* %60
%61 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 251
store i8 -4, i8* %61
%62 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 252
store i8 -3, i8* %62
%63 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 253
store i8 -2, i8* %63
%64 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 254
store i8 -1, i8* %64
%65 = icmp sgt i32 %2, 0
br i1 %65, label %66, label %89
66: ; preds = %20
%67 = zext i32 %2 to i64
br label %68
68: ; preds = %66, %68
%69 = phi i64 [ 0, %66 ], [ %85, %68 ]
%70 = phi i64 [ 255, %66 ], [ %82, %68 ]
%71 = getelementptr inbounds [65536 x i8], [65536 x i8]* %5, i64 0, i64 %69
%72 = load i8, i8* %71
%73 = zext i8 %72 to i32
%74 = trunc i64 %70 to i32
%75 = srem i32 %73, %74
%76 = zext i32 %75 to i64
%77 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 %76
%78 = load i8, i8* %77
%79 = getelementptr inbounds i8, i8* %0, i64 %69
store i8 %78, i8* %79
%80 = zext i8 %78 to i32
%81 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %80)
%82 = add nsw i64 %70, -1
%83 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 %82
%84 = load i8, i8* %83
store i8 %84, i8* %77
%85 = add nuw nsw i64 %69, 1
%86 = icmp eq i64 %85, %67
br i1 %86, label %87, label %68
87: ; preds = %68
%88 = trunc i64 %82 to i32
br label %89
89: ; preds = %87, %20
%90 = phi i32 [ 255, %20 ], [ %88, %87 ]
%91 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.6, i64 0, i64 0))
br label %123
92: ; preds = %14
%93 = call i32 @memcpy(i8* %8, i8* %1, i32 %3)
%94 = icmp sgt i32 %2, 0
br i1 %94, label %95, label %123
95: ; preds = %92, %119
%96 = phi i32 [ %121, %119 ], [ %3, %92 ]
%97 = phi i32 [ %105, %119 ], [ 0, %92 ]
%98 = phi i32 [ %120, %119 ], [ 0, %92 ]
%99 = icmp ugt i32 %97, 65535
br i1 %99, label %100, label %103
100: ; preds = %95
%101 = call i32 @gfshare_fill_rand(i8* %7, i32 65536)
%102 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %97)
br label %103
103: ; preds = %100, %95
%104 = phi i32 [ 0, %100 ], [ %97, %95 ]
%105 = add nuw nsw i32 %104, 1
%106 = zext i32 %104 to i64
%107 = getelementptr inbounds [65536 x i8], [65536 x i8]* %5, i64 0, i64 %106
%108 = load i8, i8* %107
%109 = zext i8 %108 to i32
%110 = srem i32 %109, %3
%111 = zext i32 %110 to i64
%112 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 %111
%113 = load i8, i8* %112
%114 = icmp eq i8 %113, 0
br i1 %114, label %119, label %115
115: ; preds = %103
%116 = add nsw i32 %96, -1
%117 = add nsw i32 %98, 1
%118 = getelementptr inbounds i8, i8* %0, i64 %111
store i8 %113, i8* %118
store i8 0, i8* %112
br label %119
119: ; preds = %115, %103
%120 = phi i32 [ %117, %115 ], [ %98, %103 ]
%121 = phi i32 [ %116, %115 ], [ %96, %103 ]
%122 = icmp slt i32 %120, %2
br i1 %122, label %95, label %123
123: ; preds = %119, %92, %89
%124 = phi i32 [ %90, %89 ], [ %3, %92 ], [ %121, %119 ]
%125 = phi i32 [ 255, %89 ], [ %3, %92 ], [ %3, %119 ]
%126 = sub nsw i32 %125, %2
%127 = icmp eq i32 %124, %126
br i1 %127, label %128, label %132
128: ; preds = %123
%129 = icmp sgt i32 %2, 0
br i1 %129, label %130, label %158
130: ; preds = %128
%131 = zext i32 %2 to i64
br label %134
132: ; preds = %123
%133 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %158
134: ; preds = %155, %130
%135 = phi i64 [ 0, %130 ], [ %156, %155 ]
%136 = getelementptr inbounds i8, i8* %0, i64 %135
br label %137
137: ; preds = %134, %152
%138 = phi i64 [ 0, %134 ], [ %153, %152 ]
%139 = icmp eq i64 %135, %138
br i1 %139, label %152, label %140
140: ; preds = %137
%141 = load i8, i8* %136
%142 = icmp eq i8 %141, 0
br i1 %142, label %152, label %143
143: ; preds = %140
%144 = getelementptr inbounds i8, i8* %0, i64 %138
%145 = load i8, i8* %144
%146 = icmp eq i8 %141, %145
br i1 %146, label %147, label %152
147: ; preds = %143
%148 = trunc i64 %135 to i32
%149 = trunc i64 %138 to i32
%150 = zext i8 %141 to i32
%151 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.5, i64 0, i64 0), i32 %148, i32 %150, i32 %150, i32 %149)
br label %158
152: ; preds = %140, %143, %137
%153 = add nuw nsw i64 %138, 1
%154 = icmp eq i64 %153, %131
br i1 %154, label %155, label %137
155: ; preds = %152
%156 = add nuw nsw i64 %135, 1
%157 = icmp eq i64 %156, %131
br i1 %157, label %158, label %134
158: ; preds = %155, %128, %147, %132, %12
%159 = phi i32 [ -1, %12 ], [ -1, %132 ], [ -1, %147 ], [ 0, %128 ], [ 0, %155 ]
ret i32 %159
}