#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*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ _gf256v_add(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                               unsigned int);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ gf256v_rand(int /*<<< orphan*/ *, unsigned int);
int /*<<< orphan*/ gf256v_set_zero(int /*<<< orphan*/ *, unsigned int);
scalar_t__ gf2mat_gauss_elim(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                             unsigned int);
int /*<<< orphan*/ gf2v_set_ele(int /*<<< orphan*/ *, unsigned int, int);
scalar_t__ malloc(unsigned int);
unsigned gf2mat_rand_inv(uint8_t *a, uint8_t *b, unsigned H) {
  unsigned n_vec_byte = (H + 7) / 8;
  uint8_t *aa = (uint8_t *)malloc(n_vec_byte * H);
  unsigned k;
  for (k = 0; k < 100; k++) {
    gf256v_set_zero(b, n_vec_byte * H);
    for (unsigned i = 0; i < H; i++) {
      gf256v_rand(a + i * n_vec_byte, n_vec_byte);
      gf2v_set_ele(b + n_vec_byte * i, i, 1);
    }
    gf256v_set_zero(aa, n_vec_byte * H);
    _gf256v_add(aa, a, n_vec_byte * H);
    if (gf2mat_gauss_elim(aa, b, H))
      break;
  }
  free(aa);
  return (100 != k);
}


x86 assembly (clang, -O0):
<gf2mat_rand_inv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x7,%eax
shr    $0x3,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
imul   -0x14(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x64,-0x24(%rbp)
jae    1274 <gf2mat_rand_inv+0x104>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
imul   -0x14(%rbp),%esi
call   1070 <gf256v_set_zero@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    121e <gf2mat_rand_inv+0xae>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,%eax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%esi
call   1090 <gf256v_rand@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%eax
imul   -0x28(%rbp),%eax
mov    %eax,%eax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%esi
mov    $0x1,%edx
call   1050 <gf2v_set_ele@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11c7 <gf2mat_rand_inv+0x57>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
imul   -0x14(%rbp),%esi
call   1070 <gf256v_set_zero@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%edx
imul   -0x14(%rbp),%edx
call   1080 <_gf256v_add@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <gf2mat_gauss_elim@plt>
cmp    $0x0,%rax
je     1261 <gf2mat_rand_inv+0xf1>
jmp    1274 <gf2mat_rand_inv+0x104>
jmp    1266 <gf2mat_rand_inv+0xf6>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a6 <gf2mat_rand_inv+0x36>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0x64,%eax
cmp    -0x24(%rbp),%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gf2mat_rand_inv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%r12
lea    0x7(%r14),%ebp
shr    $0x3,%ebp
mov    %ebp,%r15d
imul   %edx,%r15d
mov    %r15d,%edi
call   1060 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    %r14d,%eax
mov    %rax,0x18(%rsp)
xor    %eax,%eax
mov    %r14,0x20(%rsp)
mov    %r15d,0x4(%rsp)
mov    %r12,0x10(%rsp)
mov    0x18(%rsp),%r13
mov    %eax,(%rsp)
mov    %rbx,%rdi
mov    %r15d,%esi
call   1070 <gf256v_set_zero@plt>
test   %r14d,%r14d
je     1210 <gf2mat_rand_inv+0xa0>
xor    %r12d,%r12d
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    %r12d,%r15d
mov    0x10(%rsp),%rax
lea    (%rax,%r15,4),%rdi
mov    %ebp,%esi
call   1090 <gf256v_rand@plt>
lea    (%rbx,%r15,4),%rdi
mov    %r14d,%esi
mov    $0x1,%edx
call   1050 <gf2v_set_ele@plt>
add    $0x1,%r14
add    %ebp,%r12d
cmp    %r14,%r13
jne    11e0 <gf2mat_rand_inv+0x70>
mov    0x8(%rsp),%r14
mov    %r14,%rdi
mov    0x4(%rsp),%r15d
mov    %r15d,%esi
call   1070 <gf256v_set_zero@plt>
mov    %r14,%rdi
mov    0x10(%rsp),%rsi
mov    %r15d,%edx
call   1080 <_gf256v_add@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    0x20(%rsp),%r14
mov    %r14d,%edx
call   1040 <gf2mat_gauss_elim@plt>
test   %rax,%rax
jne    1263 <gf2mat_rand_inv+0xf3>
mov    (%rsp),%eax
add    $0x1,%eax
cmp    $0x64,%eax
jne    11c0 <gf2mat_rand_inv+0x50>
mov    $0x64,%ebx
jmp    1266 <gf2mat_rand_inv+0xf6>
mov    (%rsp),%ebx
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
cmp    $0x64,%ebx
setne  %al
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @gf2mat_rand_inv(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%11 = load i32, i32* %6
%12 = add i32 %11, 7
%13 = udiv i32 %12, 8
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = load i32, i32* %6
%16 = mul i32 %14, %15
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i32*
store i32* %18, i32** %8
store i32 0, i32* %9
br label %19
19: ; preds = %71, %3
%20 = load i32, i32* %9
%21 = icmp ult i32 %20, 100
br i1 %21, label %22, label %74
22: ; preds = %19
%23 = load i32*, i32** %5
%24 = load i32, i32* %7
%25 = load i32, i32* %6
%26 = mul i32 %24, %25
%27 = call i32 @gf256v_set_zero(i32* %23, i32 %26)
store i32 0, i32* %10
br label %28
28: ; preds = %49, %22
%29 = load i32, i32* %10
%30 = load i32, i32* %6
%31 = icmp ult i32 %29, %30
br i1 %31, label %32, label %52
32: ; preds = %28
%33 = load i32*, i32** %4
%34 = load i32, i32* %10
%35 = load i32, i32* %7
%36 = mul i32 %34, %35
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %33, i64 %37
%39 = load i32, i32* %7
%40 = call i32 @gf256v_rand(i32* %38, i32 %39)
%41 = load i32*, i32** %5
%42 = load i32, i32* %7
%43 = load i32, i32* %10
%44 = mul i32 %42, %43
%45 = zext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %41, i64 %45
%47 = load i32, i32* %10
%48 = call i32 @gf2v_set_ele(i32* %46, i32 %47, i32 1)
br label %49
49: ; preds = %32
%50 = load i32, i32* %10
%51 = add i32 %50, 1
store i32 %51, i32* %10
br label %28
52: ; preds = %28
%53 = load i32*, i32** %8
%54 = load i32, i32* %7
%55 = load i32, i32* %6
%56 = mul i32 %54, %55
%57 = call i32 @gf256v_set_zero(i32* %53, i32 %56)
%58 = load i32*, i32** %8
%59 = load i32*, i32** %4
%60 = load i32, i32* %7
%61 = load i32, i32* %6
%62 = mul i32 %60, %61
%63 = call i32 @_gf256v_add(i32* %58, i32* %59, i32 %62)
%64 = load i32*, i32** %8
%65 = load i32*, i32** %5
%66 = load i32, i32* %6
%67 = call i64 @gf2mat_gauss_elim(i32* %64, i32* %65, i32 %66)
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %52
br label %74
70: ; preds = %52
br label %71
71: ; preds = %70
%72 = load i32, i32* %9
%73 = add i32 %72, 1
store i32 %73, i32* %9
br label %19
74: ; preds = %69, %19
%75 = load i32*, i32** %8
%76 = call i32 @free(i32* %75)
%77 = load i32, i32* %9
%78 = icmp ne i32 100, %77
%79 = zext i1 %78 to i32
ret i32 %79
}

LLVM IR (-O2):
define i32 @gf2mat_rand_inv(i32* %0, i32* %1, i32 %2) {
%4 = add i32 %2, 7
%5 = lshr i32 %4, 3
%6 = mul i32 %5, %2
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i32*
%9 = icmp eq i32 %2, 0
%10 = zext i32 %2 to i64
br label %11
11: ; preds = %3, %30
%12 = phi i32 [ 0, %3 ], [ %31, %30 ]
%13 = tail call i32 @gf256v_set_zero(i32* %1, i32 %6)
br i1 %9, label %14, label %19
14: ; preds = %19, %11
%15 = tail call i32 @gf256v_set_zero(i32* %8, i32 %6)
%16 = tail call i32 @_gf256v_add(i32* %8, i32* %0, i32 %6)
%17 = tail call i64 @gf2mat_gauss_elim(i32* %8, i32* %1, i32 %2)
%18 = icmp eq i64 %17, 0
br i1 %18, label %30, label %33
19: ; preds = %11, %19
%20 = phi i64 [ %28, %19 ], [ 0, %11 ]
%21 = trunc i64 %20 to i32
%22 = mul i32 %5, %21
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %0, i64 %23
%25 = tail call i32 @gf256v_rand(i32* %24, i32 %5)
%26 = getelementptr inbounds i32, i32* %1, i64 %23
%27 = tail call i32 @gf2v_set_ele(i32* %26, i32 %21, i32 1)
%28 = add nuw nsw i64 %20, 1
%29 = icmp eq i64 %28, %10
br i1 %29, label %14, label %19
30: ; preds = %14
%31 = add nuw nsw i32 %12, 1
%32 = icmp eq i32 %31, 100
br i1 %32, label %33, label %11
33: ; preds = %14, %30
%34 = phi i32 [ %12, %14 ], [ 100, %30 ]
%35 = tail call i32 @free(i32* %8)
%36 = icmp ne i32 %34, 100
%37 = zext i1 %36 to i32
ret i32 %37
}