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

/* Variables and functions */
int /*<<< orphan*/ longadd(int *, int, int *, int);
int /*<<< orphan*/ longshl(int *, int, int);
int /*<<< orphan*/ memcpy(int *, int *, int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
void longmult(uint8_t d1[], uint8_t len1, uint8_t d2[], uint8_t len2,
              uint8_t result[], uint8_t work[]) {
  uint8_t i;
  int j;
  uint8_t worklen = len1 + len2;
  memcpy(work + len2, d1, len1);
  memset(work, 0, len2);
  memset(result, 0, worklen);
  for (i = 0; i < (len2 * 8); i++) {
    j = len2 - (i / 8) - 1;
    if (d2[j] & (1 << (i % 8)))
      longadd(result, worklen, work, worklen);
    longshl(work, worklen, 1);
  }
}


x86 assembly (clang, -O0):
<longmult>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0xc(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x3c(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x1c(%rbp),%ecx
shl    $0x3,%ecx
cmp    %ecx,%eax
jge    1238 <longmult+0xf8>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x34(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
sub    %ecx,%eax
sub    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x40(%rbp)
mov    -0x34(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    -0x40(%rbp),%eax
mov    %edx,%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1219 <longmult+0xd9>
mov    -0x28(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    -0x3c(%rbp),%ecx
call   1060 <longadd@plt>
mov    -0x30(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    $0x1,%edx
call   1030 <longshl@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11a5 <longmult+0x65>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<longmult>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%rbx
mov    %r8,(%rsp)
mov    %ecx,%r15d
mov    %rdx,%r12
mov    %esi,%edx
mov    %rdi,%rsi
lea    (%r15,%rdx,1),%ebp
movslq %ecx,%r14
lea    (%r9,%r14,4),%rdi
call   1050 <memcpy@plt>
xor    %r13d,%r13d
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1040 <memset@plt>
mov    (%rsp),%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <memset@plt>
test   %r14d,%r14d
jle    11f9 <longmult+0xb9>
lea    0x0(,%r15,8),%r14d
cmp    $0x2,%r14d
mov    $0x1,%eax
cmovl  %eax,%r14d
jmp    11c8 <longmult+0x88>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
call   1030 <longshl@plt>
add    $0x1,%r13d
cmp    %r13d,%r14d
je     11f9 <longmult+0xb9>
mov    %r13d,%eax
shr    $0x3,%eax
not    %eax
add    %r15d,%eax
cltq
mov    (%r12,%rax,4),%eax
mov    %r13d,%ecx
and    $0x7,%cl
movzbl %cl,%ecx
bt     %ecx,%eax
jae    11b0 <longmult+0x70>
mov    (%rsp),%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1060 <longadd@plt>
jmp    11b0 <longmult+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @longmult(i32* %0, i32 %1, i32* %2, i32 %3, i32* %4, i32* %5) {
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32* %0, i32** %7
store i32 %1, i32* %8
store i32* %2, i32** %9
store i32 %3, i32* %10
store i32* %4, i32** %11
store i32* %5, i32** %12
%16 = load i32, i32* %8
%17 = load i32, i32* %10
%18 = add nsw i32 %16, %17
store i32 %18, i32* %15
%19 = load i32*, i32** %12
%20 = load i32, i32* %10
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32*, i32** %7
%24 = load i32, i32* %8
%25 = call i32 @memcpy(i32* %22, i32* %23, i32 %24)
%26 = load i32*, i32** %12
%27 = load i32, i32* %10
%28 = call i32 @memset(i32* %26, i32 0, i32 %27)
%29 = load i32*, i32** %11
%30 = load i32, i32* %15
%31 = call i32 @memset(i32* %29, i32 0, i32 %30)
store i32 0, i32* %13
br label %32
32: ; preds = %63, %6
%33 = load i32, i32* %13
%34 = load i32, i32* %10
%35 = mul nsw i32 %34, 8
%36 = icmp slt i32 %33, %35
br i1 %36, label %37, label %66
37: ; preds = %32
%38 = load i32, i32* %10
%39 = load i32, i32* %13
%40 = sdiv i32 %39, 8
%41 = sub nsw i32 %38, %40
%42 = sub nsw i32 %41, 1
store i32 %42, i32* %14
%43 = load i32*, i32** %9
%44 = load i32, i32* %14
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
%47 = load i32, i32* %46
%48 = load i32, i32* %13
%49 = srem i32 %48, 8
%50 = shl i32 1, %49
%51 = and i32 %47, %50
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %59
53: ; preds = %37
%54 = load i32*, i32** %11
%55 = load i32, i32* %15
%56 = load i32*, i32** %12
%57 = load i32, i32* %15
%58 = call i32 @longadd(i32* %54, i32 %55, i32* %56, i32 %57)
br label %59
59: ; preds = %53, %37
%60 = load i32*, i32** %12
%61 = load i32, i32* %15
%62 = call i32 @longshl(i32* %60, i32 %61, i32 1)
br label %63
63: ; preds = %59
%64 = load i32, i32* %13
%65 = add nsw i32 %64, 1
store i32 %65, i32* %13
br label %32
66: ; preds = %32
ret void
}

LLVM IR (-O2):
define void @longmult(i32* %0, i32 %1, i32* nocapture %2, i32 %3, i32* %4, i32* %5) {
%7 = add nsw i32 %3, %1
%8 = sext i32 %3 to i64
%9 = getelementptr inbounds i32, i32* %5, i64 %8
%10 = tail call i32 @memcpy(i32* %9, i32* %0, i32 %1)
%11 = tail call i32 @memset(i32* %5, i32 0, i32 %3)
%12 = tail call i32 @memset(i32* %4, i32 0, i32 %7)
%13 = icmp sgt i32 %3, 0
br i1 %13, label %14, label %35
14: ; preds = %6
%15 = shl i32 %3, 3
%16 = call i32 @llvm.smax.i32(i32 %15, i32 1)
br label %17
17: ; preds = %14, %31
%18 = phi i32 [ %33, %31 ], [ 0, %14 ]
%19 = lshr i32 %18, 3
%20 = xor i32 %19, -1
%21 = add i32 %20, %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %2, i64 %22
%24 = load i32, i32* %23
%25 = and i32 %18, 7
%26 = shl nuw nsw i32 1, %25
%27 = and i32 %24, %26
%28 = icmp eq i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %17
%30 = tail call i32 @longadd(i32* %4, i32 %7, i32* %5, i32 %7)
br label %31
31: ; preds = %29, %17
%32 = tail call i32 @longshl(i32* %5, i32 %7, i32 1)
%33 = add nuw nsw i32 %18, 1
%34 = icmp eq i32 %33, %16
br i1 %34, label %35, label %17
35: ; preds = %31, %6
ret void
}