#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*/ assert(int);
int /*<<< orphan*/ memmove(unsigned char *, unsigned char const *,
                           unsigned int);
unsigned char redupe_gf_mul(unsigned char const, unsigned char);
void redupe_gf_poly_div(const unsigned char *dividend, unsigned dividend_sz,
                        const unsigned char *divisor, unsigned divisor_sz,
                        unsigned char *quotient, unsigned *quotient_sz,
                        unsigned char *remainder, unsigned *remainder_sz) {
  unsigned char buf[256];
  memmove(buf, dividend, dividend_sz);
  for (unsigned i = 0; i < dividend_sz - divisor_sz + 1; ++i) {
    if (buf[i] == 0) {
      continue;
    }
    for (unsigned j = 1; j < divisor_sz; ++j) {
      if (divisor[j] == 0) {
        continue;
      }
      buf[i + j] ^= redupe_gf_mul(divisor[j], buf[i]);
    }
  }
  unsigned sep = dividend_sz - divisor_sz + 1;
  assert(sep < dividend_sz);
  memmove(quotient, buf, sep);
  *quotient_sz = sep;
  memmove(remainder, buf + sep, dividend_sz - sep);
  *remainder_sz = dividend_sz - sep;
}


x86 assembly (clang, -O0):
<redupe_gf_poly_div>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <memmove@plt>
movl   $0x0,-0x134(%rbp)
mov    -0x134(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jae    1250 <redupe_gf_poly_div+0x120>
mov    -0x134(%rbp),%eax
movzbl -0x130(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
jne    11a9 <redupe_gf_poly_div+0x79>
jmp    123c <redupe_gf_poly_div+0x10c>
movl   $0x1,-0x138(%rbp)
mov    -0x138(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    1237 <redupe_gf_poly_div+0x107>
mov    -0x18(%rbp),%rax
mov    -0x138(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    11de <redupe_gf_poly_div+0xae>
jmp    1223 <redupe_gf_poly_div+0xf3>
mov    -0x18(%rbp),%rax
mov    -0x138(%rbp),%ecx
mov    (%rax,%rcx,1),%cl
mov    -0x134(%rbp),%eax
movzbl %cl,%edi
movzbl -0x130(%rbp,%rax,1),%esi
ff
call   1050 <redupe_gf_mul@plt>
movzbl %al,%edx
mov    -0x134(%rbp),%eax
add    -0x138(%rbp),%eax
mov    %eax,%eax
movzbl -0x130(%rbp,%rax,1),%ecx
ff
xor    %edx,%ecx
mov    %cl,-0x130(%rbp,%rax,1)
mov    -0x138(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x138(%rbp)
jmp    11b3 <redupe_gf_poly_div+0x83>
jmp    123c <redupe_gf_poly_div+0x10c>
mov    -0x134(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x134(%rbp)
jmp    1176 <redupe_gf_poly_div+0x46>
mov    -0xc(%rbp),%eax
sub    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13c(%rbp)
mov    -0x13c(%rbp),%eax
cmp    -0xc(%rbp),%eax
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x28(%rbp),%rdi
lea    -0x130(%rbp),%rsi
mov    -0x13c(%rbp),%edx
call   1040 <memmove@plt>
mov    -0x13c(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    0x10(%rbp),%rdi
lea    -0x130(%rbp),%rsi
mov    -0x13c(%rbp),%eax
add    %rax,%rsi
mov    -0xc(%rbp),%edx
sub    -0x13c(%rbp),%edx
call   1040 <memmove@plt>
mov    -0xc(%rbp),%ecx
sub    -0x13c(%rbp),%ecx
mov    0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<redupe_gf_poly_div>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %r9,%r13
mov    %r8,0x18(%rsp)
mov    %ecx,%ebx
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%rsi
mov    0x168(%rsp),%r12
lea    0x20(%rsp),%rdi
mov    %ebp,%edx
call   1040 <memmove@plt>
mov    %ebp,%eax
sub    %ebx,%eax
inc    %eax
jne    1174 <redupe_gf_poly_div+0x44>
xor    %r14d,%r14d
jmp    11f0 <redupe_gf_poly_div+0xc0>
mov    %r13,0x10(%rsp)
mov    %ebp,0xc(%rsp)
mov    %eax,0x8(%rsp)
mov    %eax,%r14d
mov    %ebx,%r12d
xor    %r13d,%r13d
jmp    1199 <redupe_gf_poly_div+0x69>
nopl   0x0(%rax)
add    $0x1,%r13
cmp    %r14,%r13
je     11db <redupe_gf_poly_div+0xab>
cmpb   $0x0,0x20(%rsp,%r13,1)
je     1190 <redupe_gf_poly_div+0x60>
cmp    $0x2,%ebx
jb     1190 <redupe_gf_poly_div+0x60>
mov    $0x1,%ebp
jmp    11b9 <redupe_gf_poly_div+0x89>
nopl   (%rax)
add    $0x1,%rbp
cmp    %rbp,%r12
je     1190 <redupe_gf_poly_div+0x60>
movzbl (%r15,%rbp,1),%eax
test   %al,%al
je     11b0 <redupe_gf_poly_div+0x80>
movzbl 0x20(%rsp,%r13,1),%esi
movzbl %al,%edi
call   1050 <redupe_gf_mul@plt>
lea    0x0(%r13,%rbp,1),%ecx
xor    %al,0x20(%rsp,%rcx,1)
jmp    11b0 <redupe_gf_poly_div+0x80>
mov    0xc(%rsp),%ebp
mov    0x168(%rsp),%r12
mov    0x10(%rsp),%r13
mov    0x8(%rsp),%eax
xor    %edi,%edi
sub    %eax,%ebp
seta   %dil
mov    %eax,%ebx
call   1030 <assert@plt>
lea    0x20(%rsp),%rsi
mov    0x18(%rsp),%rdi
mov    %ebx,%edx
call   1040 <memmove@plt>
mov    %ebx,0x0(%r13)
lea    (%rsp,%r14,1),%rsi
add    $0x20,%rsi
mov    0x160(%rsp),%rdi
mov    %ebp,%edx
call   1040 <memmove@plt>
mov    %ebp,(%r12)
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @redupe_gf_poly_div(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4, i32* %5, i8* %6, i32* %7) {
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32*
%15 = alloca i8*
%16 = alloca i32*
%17 = alloca [256 x i8]
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store i8* %0, i8** %9
store i32 %1, i32* %10
store i8* %2, i8** %11
store i32 %3, i32* %12
store i8* %4, i8** %13
store i32* %5, i32** %14
store i8* %6, i8** %15
store i32* %7, i32** %16
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 0
%22 = load i8*, i8** %9
%23 = load i32, i32* %10
%24 = call i32 @memmove(i8* %21, i8* %22, i32 %23)
store i32 0, i32* %18
br label %25
25: ; preds = %79, %8
%26 = load i32, i32* %18
%27 = load i32, i32* %10
%28 = load i32, i32* %12
%29 = sub i32 %27, %28
%30 = add i32 %29, 1
%31 = icmp ult i32 %26, %30
br i1 %31, label %32, label %82
32: ; preds = %25
%33 = load i32, i32* %18
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %32
br label %79
40: ; preds = %32
store i32 1, i32* %19
br label %41
41: ; preds = %75, %40
%42 = load i32, i32* %19
%43 = load i32, i32* %12
%44 = icmp ult i32 %42, %43
br i1 %44, label %45, label %78
45: ; preds = %41
%46 = load i8*, i8** %11
%47 = load i32, i32* %19
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %45
br label %75
54: ; preds = %45
%55 = load i8*, i8** %11
%56 = load i32, i32* %19
%57 = zext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
%59 = load i8, i8* %58
%60 = load i32, i32* %18
%61 = zext i32 %60 to i64
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 %61
%63 = load i8, i8* %62
%64 = call zeroext i8 @redupe_gf_mul(i8 zeroext %59, i8 zeroext %63)
%65 = zext i8 %64 to i32
%66 = load i32, i32* %18
%67 = load i32, i32* %19
%68 = add i32 %66, %67
%69 = zext i32 %68 to i64
%70 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 %69
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
%73 = xor i32 %72, %65
%74 = trunc i32 %73 to i8
store i8 %74, i8* %70
br label %75
75: ; preds = %54, %53
%76 = load i32, i32* %19
%77 = add i32 %76, 1
store i32 %77, i32* %19
br label %41
78: ; preds = %41
br label %79
79: ; preds = %78, %39
%80 = load i32, i32* %18
%81 = add i32 %80, 1
store i32 %81, i32* %18
br label %25
82: ; preds = %25
%83 = load i32, i32* %10
%84 = load i32, i32* %12
%85 = sub i32 %83, %84
%86 = add i32 %85, 1
store i32 %86, i32* %20
%87 = load i32, i32* %20
%88 = load i32, i32* %10
%89 = icmp ult i32 %87, %88
%90 = zext i1 %89 to i32
%91 = call i32 @assert(i32 %90)
%92 = load i8*, i8** %13
%93 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 0
%94 = load i32, i32* %20
%95 = call i32 @memmove(i8* %92, i8* %93, i32 %94)
%96 = load i32, i32* %20
%97 = load i32*, i32** %14
store i32 %96, i32* %97
%98 = load i8*, i8** %15
%99 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 0
%100 = load i32, i32* %20
%101 = zext i32 %100 to i64
%102 = getelementptr inbounds i8, i8* %99, i64 %101
%103 = load i32, i32* %10
%104 = load i32, i32* %20
%105 = sub i32 %103, %104
%106 = call i32 @memmove(i8* %98, i8* %102, i32 %105)
%107 = load i32, i32* %10
%108 = load i32, i32* %20
%109 = sub i32 %107, %108
%110 = load i32*, i32** %16
store i32 %109, i32* %110
ret void
}

LLVM IR (-O2):
define void @redupe_gf_poly_div(i8* %0, i32 %1, i8* nocapture %2, i32 %3, i8* %4, i32* nocapture writeonly %5, i8* %6, i32* nocapture writeonly %7) {
%9 = alloca [256 x i8]
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%11 = call i32 @memmove(i8* %10, i8* %0, i32 %1)
%12 = sub i32 %1, %3
%13 = add i32 %12, 1
%14 = icmp eq i32 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %8
%16 = icmp ult i32 %3, 2
%17 = zext i32 %13 to i64
%18 = zext i32 %3 to i64
br label %28
19: ; preds = %50, %8
%20 = phi i64 [ 0, %8 ], [ %17, %50 ]
%21 = icmp ult i32 %13, %1
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = call i32 @memmove(i8* %4, i8* %10, i32 %13)
store i32 %13, i32* %5
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %20
%26 = sub i32 %1, %13
%27 = call i32 @memmove(i8* %6, i8* %25, i32 %26)
store i32 %26, i32* %7
ret void
28: ; preds = %15, %50
%29 = phi i64 [ 0, %15 ], [ %51, %50 ]
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 0
%33 = or i1 %32, %16
br i1 %33, label %50, label %34
34: ; preds = %28, %47
%35 = phi i64 [ %48, %47 ], [ 1, %28 ]
%36 = getelementptr inbounds i8, i8* %2, i64 %35
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 0
br i1 %38, label %47, label %39
39: ; preds = %34
%40 = load i8, i8* %30
%41 = call zeroext i8 @redupe_gf_mul(i8 zeroext %37, i8 zeroext %40)
%42 = add nuw i64 %35, %29
%43 = and i64 %42, 4294967295
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = xor i8 %45, %41
store i8 %46, i8* %44
br label %47
47: ; preds = %34, %39
%48 = add nuw nsw i64 %35, 1
%49 = icmp eq i64 %48, %18
br i1 %49, label %50, label %34
50: ; preds = %47, %28
%51 = add nuw nsw i64 %29, 1
%52 = icmp eq i64 %51, %17
br i1 %52, label %19, label %28
}