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

/* Variables and functions */
int /*<<< orphan*/ iAdd(unsigned char *, unsigned char *, unsigned int,
                        unsigned int);
int /*<<< orphan*/ iMultDigit(unsigned char *, unsigned char, unsigned int,
                              unsigned int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ ucShift(unsigned char *, unsigned int, int);
int /*<<< orphan*/ vAssign(unsigned char *, unsigned char *, unsigned int);
int /*<<< orphan*/ vSetZero(unsigned char *, unsigned int);
int iMult(unsigned char *psA, unsigned char *psB, unsigned char *psC,
          unsigned int uiLen, unsigned int uiBase) {
  int i;
  unsigned char sT[128 * 2];
  if (uiBase < 2 || uiBase > 16)
    return (-1);
  if (uiLen > 128)
    return (-2);
  vSetZero(psA, uiLen * 2);
  for (i = 0; i < (int)uiLen; i++) {
    memset(sT, 0, sizeof(sT));
    vAssign(sT, psB, uiLen);
    ucShift(sT, uiLen * 2, i);
    iMultDigit(sT, psC[i], uiLen * 2, uiBase);
    iAdd(psA, sT, uiLen * 2, uiBase);
  }
  return (0);
}


x86 assembly (clang, -O0):
<iMult>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
cmpl   $0x2,-0x28(%rbp)
jb     1192 <iMult+0x32>
cmpl   $0x10,-0x28(%rbp)
jbe    119e <iMult+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1265 <iMult+0x105>
cmpl   $0x80,-0x24(%rbp)
jbe    11b7 <iMult+0x57>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1265 <iMult+0x105>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
shl    $0x1,%esi
call   1050 <vSetZero@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    125e <iMult+0xfe>
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
lea    -0x130(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1080 <vAssign@plt>
lea    -0x130(%rbp),%rdi
mov    -0x24(%rbp),%esi
shl    $0x1,%esi
mov    -0x2c(%rbp),%edx
call   1030 <ucShift@plt>
lea    -0x130(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x24(%rbp),%edx
shl    $0x1,%edx
mov    -0x28(%rbp),%ecx
movzbl %al,%esi
call   1070 <iMultDigit@plt>
mov    -0x10(%rbp),%rdi
lea    -0x130(%rbp),%rsi
mov    -0x24(%rbp),%edx
shl    $0x1,%edx
mov    -0x28(%rbp),%ecx
call   1060 <iAdd@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11cd <iMult+0x6d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iMult>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %r8d,%ebx
mov    %ecx,%r14d
lea    -0x11(%rbx),%ecx
mov    $0xffffffff,%eax
cmp    $0xfffffff1,%ecx
jb     1228 <iMult+0xc8>
mov    $0xfffffffe,%eax
cmp    $0x80,%r14d
ja     1228 <iMult+0xc8>
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
lea    (%r14,%r14,1),%ebp
mov    %ebp,%esi
call   1050 <vSetZero@plt>
test   %r14d,%r14d
je     1226 <iMult+0xc6>
mov    %r13,0x8(%rsp)
mov    %r14d,%r13d
lea    0x10(%rsp),%r14
mov    %r12,(%rsp)
mov    %r15,%r12
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
mov    %r14,%rdi
mov    (%rsp),%rsi
mov    %r13d,%edx
call   1080 <vAssign@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
call   1030 <ucShift@plt>
movzbl (%r12,%r15,1),%esi
mov    %r14,%rdi
mov    %ebp,%edx
mov    %ebx,%ecx
call   1070 <iMultDigit@plt>
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    %ebx,%ecx
call   1060 <iAdd@plt>
add    $0x1,%r15
cmp    %r15,%r13
jne    11d0 <iMult+0x70>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @iMult(i8* %0, i8* %1, i8* nocapture %2, i32 %3, i32 %4) {
%6 = alloca [256 x i8]
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%8 = add i32 %4, -17
%9 = icmp ult i32 %8, -15
br i1 %9, label %30, label %10
10: ; preds = %5
%11 = icmp ugt i32 %3, 128
br i1 %11, label %30, label %12
12: ; preds = %10
%13 = shl nuw nsw i32 %3, 1
%14 = tail call i32 @vSetZero(i8* %0, i32 %13)
%15 = icmp eq i32 %3, 0
br i1 %15, label %30, label %16
16: ; preds = %12
%17 = zext i32 %3 to i64
br label %18
18: ; preds = %16, %18
%19 = phi i64 [ 0, %16 ], [ %28, %18 ]
%20 = call i32 @memset(i8* %7, i32 0, i32 256)
%21 = call i32 @vAssign(i8* %7, i8* %1, i32 %3)
%22 = trunc i64 %19 to i32
%23 = call i32 @ucShift(i8* %7, i32 %13, i32 %22)
%24 = getelementptr inbounds i8, i8* %2, i64 %19
%25 = load i8, i8* %24
%26 = call i32 @iMultDigit(i8* %7, i8 zeroext %25, i32 %13, i32 %4)
%27 = call i32 @iAdd(i8* %0, i8* %7, i32 %13, i32 %4)
%28 = add nuw nsw i64 %19, 1
%29 = icmp eq i64 %28, %17
br i1 %29, label %30, label %18
30: ; preds = %18, %12, %10, %5
%31 = phi i32 [ -1, %5 ], [ -2, %10 ], [ 0, %12 ], [ 0, %18 ]
ret i32 %31
}