#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*/ _longadd(int /*<<< orphan*/, unsigned int *);
int /*<<< orphan*/ _longmul(unsigned int *, unsigned int *);
unsigned _longarraymul(unsigned *uarray, int lg, unsigned factor) {
  unsigned ovfl, carry;
  carry = 0;
  ovfl = 0;
  for (; lg-- > 0;) {
    carry += ovfl;
    ovfl = factor;
    _longmul(uarray, &ovfl);
    _longadd(uarray++, &carry);
  }
  return carry + ovfl;
}


x86 assembly (clang, -O0):
<_longarraymul>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
jle    118f <_longarraymul+0x6f>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <_longmul@plt>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x8(%rbp)
mov    %eax,%edi
lea    -0x18(%rbp),%rsi
call   1030 <_longadd@plt>
jmp    1140 <_longarraymul+0x20>
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_longarraymul>:
test   %esi,%esi
jle    11c7 <_longarraymul+0xa7>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbx
movl   $0x0,0x4(%rsp)
mov    %edx,(%rsp)
mov    %rsp,%rsi
call   1040 <_longmul@plt>
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
call   1030 <_longadd@plt>
cmp    $0x1,%r15d
je     11b1 <_longarraymul+0x91>
add    $0x1,%r15d
lea    0x4(%rbx),%ebp
add    $0x4,%rbx
mov    %rsp,%r12
lea    0x4(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rsp),%eax
add    %eax,0x4(%rsp)
mov    %r14d,(%rsp)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <_longmul@plt>
mov    %ebp,%edi
mov    %r13,%rsi
call   1030 <_longadd@plt>
add    $0xffffffff,%r15d
add    $0x4,%ebp
add    $0x4,%rbx
cmp    $0x2,%r15d
jg     1180 <_longarraymul+0x60>
mov    (%rsp),%eax
add    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @_longarraymul(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %8
store i32 0, i32* %7
br label %9
9: ; preds = %13, %3
%10 = load i32, i32* %5
%11 = add nsw i32 %10, -1
store i32 %11, i32* %5
%12 = icmp sgt i32 %10, 0
br i1 %12, label %13, label %24
13: ; preds = %9
%14 = load i32, i32* %7
%15 = load i32, i32* %8
%16 = add i32 %15, %14
store i32 %16, i32* %8
%17 = load i32, i32* %6
store i32 %17, i32* %7
%18 = load i32*, i32** %4
%19 = call i32 @_longmul(i32* %18, i32* %7)
%20 = load i32*, i32** %4
%21 = getelementptr inbounds i32, i32* %20, i32 1
store i32* %21, i32** %4
%22 = ptrtoint i32* %20 to i32
%23 = call i32 @_longadd(i32 %22, i32* %8)
br label %9
24: ; preds = %9
%25 = load i32, i32* %8
%26 = load i32, i32* %7
%27 = add i32 %25, %26
ret i32 %27
}

LLVM IR (-O2):
define i32 @_longarraymul(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %4 to i8*
%7 = bitcast i32* %5 to i8*
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %32
9: ; preds = %3
store i32 0, i32* %5
store i32 %2, i32* %4
%10 = call i32 @_longmul(i32* %0, i32* %4)
%11 = ptrtoint i32* %0 to i64
%12 = trunc i64 %11 to i32
%13 = call i32 @_longadd(i32 %12, i32* %5)
%14 = icmp eq i32 %1, 1
br i1 %14, label %28, label %15
15: ; preds = %9, %15
%16 = phi i32 [ %19, %15 ], [ %1, %9 ]
%17 = phi i32* [ %18, %15 ], [ %0, %9 ]
%18 = getelementptr inbounds i32, i32* %17, i64 1
%19 = add nsw i32 %16, -1
%20 = load i32, i32* %4
%21 = load i32, i32* %5
%22 = add i32 %21, %20
store i32 %22, i32* %5
store i32 %2, i32* %4
%23 = call i32 @_longmul(i32* %18, i32* %4)
%24 = ptrtoint i32* %18 to i64
%25 = trunc i64 %24 to i32
%26 = call i32 @_longadd(i32 %25, i32* %5)
%27 = icmp sgt i32 %16, 2
br i1 %27, label %15, label %28
28: ; preds = %15, %9
%29 = load i32, i32* %5
%30 = load i32, i32* %4
%31 = add i32 %30, %29
br label %32
32: ; preds = %28, %3
%33 = phi i32 [ %31, %28 ], [ 0, %3 ]
ret i32 %33
}