#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 */
struct gf {
  int dummy;
};

/* Variables and functions */
unsigned char gf_add(struct gf *, unsigned char, unsigned char);
unsigned char gf_mult(struct gf *, unsigned char, unsigned char);
void p_mul(struct gf *f, unsigned char *dst, int alen, unsigned char *pa,
           int blen, unsigned char *pb) {
  int i, j;
  unsigned char pm;
  for (i = 0; i < alen + blen - 1; i++)
    dst[i] = 0;
  for (i = 0; i < alen; i++) {
    for (j = 0; j < blen; j++) {
      pm = gf_mult(f, pa[i], pb[j]);
      dst[i + j] = gf_add(f, dst[i + j], pm);
    }
  }
}


x86 assembly (clang, -O0):
<p_mul>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    -0x24(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1174 <p_mul+0x54>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1146 <p_mul+0x26>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1213 <p_mul+0xf3>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1200 <p_mul+0xe0>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x30(%rbp),%rax
movslq -0x38(%rbp),%rcx
movzbl %dl,%esi
movzbl (%rax,%rcx,1),%edx
call   1040 <gf_mult@plt>
mov    %al,-0x39(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
movzbl %al,%esi
movzbl -0x39(%rbp),%edx
call   1030 <gf_add@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    -0x38(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    118e <p_mul+0x6e>
jmp    1205 <p_mul+0xe5>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    117b <p_mul+0x5b>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p_mul>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r15d
mov    %rcx,%rbp
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%rbx
lea    (%r12,%r15,1),%eax
add    $0xffffffff,%eax
test   %eax,%eax
jle    1179 <p_mul+0x49>
lea    (%r15,%r12,1),%edx
add    $0xfffffffe,%edx
add    $0x1,%rdx
mov    %r14,%rdi
xor    %esi,%esi
mov    %r14,%r13
mov    %r9,%r14
call   1030 <memset@plt>
mov    %r14,%r9
mov    %r13,%r14
test   %r12d,%r12d
jle    11fd <p_mul+0xcd>
mov    %r12d,%eax
mov    %rax,(%rsp)
mov    %r15d,%eax
xor    %r13d,%r13d
mov    %r15,0x8(%rsp)
mov    %rax,0x10(%rsp)
jmp    11b3 <p_mul+0x83>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r13
add    $0x1,%r14
cmp    (%rsp),%r13
mov    0x8(%rsp),%r15
je     11fd <p_mul+0xcd>
test   %r15d,%r15d
jle    11a0 <p_mul+0x70>
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
movzbl 0x0(%rbp,%r13,1),%esi
movzbl (%r9,%r15,1),%edx
mov    %rbx,%rdi
mov    %r9,%r12
call   1050 <gf_mult@plt>
movzbl (%r14,%r15,1),%esi
movzbl %al,%edx
mov    %rbx,%rdi
call   1040 <gf_add@plt>
mov    %r12,%r9
mov    %al,(%r14,%r15,1)
mov    0x10(%rsp),%rax
add    $0x1,%r15
cmp    %r15,%rax
jne    11c0 <p_mul+0x90>
jmp    11a0 <p_mul+0x70>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.gf = type { i32 }
define void @p_mul(%struct.gf* %0, i8* %1, i32 %2, i8* %3, i32 %4, i8* %5) {
%7 = alloca %struct.gf*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8
store %struct.gf* %0, %struct.gf** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store i8* %5, i8** %12
store i32 0, i32* %13
br label %16
16: ; preds = %28, %6
%17 = load i32, i32* %13
%18 = load i32, i32* %9
%19 = load i32, i32* %11
%20 = add nsw i32 %18, %19
%21 = sub nsw i32 %20, 1
%22 = icmp slt i32 %17, %21
br i1 %22, label %23, label %31
23: ; preds = %16
%24 = load i8*, i8** %8
%25 = load i32, i32* %13
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 0, i8* %27
br label %28
28: ; preds = %23
%29 = load i32, i32* %13
%30 = add nsw i32 %29, 1
store i32 %30, i32* %13
br label %16
31: ; preds = %16
store i32 0, i32* %13
br label %32
32: ; preds = %74, %31
%33 = load i32, i32* %13
%34 = load i32, i32* %9
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %77
36: ; preds = %32
store i32 0, i32* %14
br label %37
37: ; preds = %70, %36
%38 = load i32, i32* %14
%39 = load i32, i32* %11
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %73
41: ; preds = %37
%42 = load %struct.gf*, %struct.gf** %7
%43 = load i8*, i8** %10
%44 = load i32, i32* %13
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8, i8* %46
%48 = load i8*, i8** %12
%49 = load i32, i32* %14
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = load i8, i8* %51
%53 = call zeroext i8 @gf_mult(%struct.gf* %42, i8 zeroext %47, i8 zeroext %52)
store i8 %53, i8* %15
%54 = load %struct.gf*, %struct.gf** %7
%55 = load i8*, i8** %8
%56 = load i32, i32* %13
%57 = load i32, i32* %14
%58 = add nsw i32 %56, %57
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %55, i64 %59
%61 = load i8, i8* %60
%62 = load i8, i8* %15
%63 = call zeroext i8 @gf_add(%struct.gf* %54, i8 zeroext %61, i8 zeroext %62)
%64 = load i8*, i8** %8
%65 = load i32, i32* %13
%66 = load i32, i32* %14
%67 = add nsw i32 %65, %66
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %64, i64 %68
store i8 %63, i8* %69
br label %70
70: ; preds = %41
%71 = load i32, i32* %14
%72 = add nsw i32 %71, 1
store i32 %72, i32* %14
br label %37
73: ; preds = %37
br label %74
74: ; preds = %73
%75 = load i32, i32* %13
%76 = add nsw i32 %75, 1
store i32 %76, i32* %13
br label %32
77: ; preds = %32
ret void
}

LLVM IR (-O2):
%struct.gf = type { i32 }
define void @p_mul(%struct.gf* %0, i8* nocapture %1, i32 %2, i8* nocapture %3, i32 %4, i8* nocapture %5) {
%7 = add i32 %2, -1
%8 = add i32 %7, %4
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = add i32 %4, %2
%12 = add i32 %11, -2
%13 = zext i32 %12 to i64
%14 = add nuw nsw i64 %13, 1
br label %15
15: ; preds = %10, %6
%16 = icmp sgt i32 %2, 0
br i1 %16, label %17, label %40
17: ; preds = %15
%18 = icmp sgt i32 %4, 0
%19 = zext i32 %2 to i64
%20 = zext i32 %4 to i64
br label %21
21: ; preds = %17, %37
%22 = phi i64 [ 0, %17 ], [ %38, %37 ]
br i1 %18, label %23, label %37
23: ; preds = %21
%24 = getelementptr inbounds i8, i8* %3, i64 %22
br label %25
25: ; preds = %23, %25
%26 = phi i64 [ 0, %23 ], [ %35, %25 ]
%27 = load i8, i8* %24
%28 = getelementptr inbounds i8, i8* %5, i64 %26
%29 = load i8, i8* %28
%30 = tail call zeroext i8 @gf_mult(%struct.gf* %0, i8 zeroext %27, i8 zeroext %29)
%31 = add nuw nsw i64 %26, %22
%32 = getelementptr inbounds i8, i8* %1, i64 %31
%33 = load i8, i8* %32
%34 = tail call zeroext i8 @gf_add(%struct.gf* %0, i8 zeroext %33, i8 zeroext %30)
store i8 %34, i8* %32
%35 = add nuw nsw i64 %26, 1
%36 = icmp eq i64 %35, %20
br i1 %36, label %37, label %25
37: ; preds = %25, %21
%38 = add nuw nsw i64 %22, 1
%39 = icmp eq i64 %38, %19
br i1 %39, label %40, label %21
40: ; preds = %37, %15
ret void
}