#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 BigNum {
  int dummy;
};

/* Variables and functions */
int bnSubQ(struct BigNum *, unsigned int);
int bnSubMult(struct BigNum *bn, unsigned x, unsigned y) {
  unsigned long z = (unsigned long)x * y;
  while (z > 65535) {
    if (bnSubQ(bn, 65535) < 0)
      return -1;
    z -= 65535;
  }
  return bnSubQ(bn, (unsigned)z);
}


x86 assembly (clang, -O0):
<bnSubMult>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
imul   %rcx,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0xffff,-0x20(%rbp)
jbe    1174 <bnSubMult+0x64>
mov    -0x10(%rbp),%rdi
mov    $0xffff,%esi
call   1030 <bnSubQ@plt>
cmp    $0x0,%eax
jge    1161 <bnSubMult+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    1186 <bnSubMult+0x76>
mov    -0x20(%rbp),%rax
sub    $0xffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1130 <bnSubMult+0x20>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    %eax,%esi
call   1030 <bnSubQ@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bnSubMult>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %esi,%eax
mov    %edx,%ebx
imul   %rax,%rbx
cmp    $0x10000,%rbx
jb     1151 <bnSubMult+0x41>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0xffff,%esi
call   1030 <bnSubQ@plt>
test   %eax,%eax
js     1162 <bnSubMult+0x52>
add    $0xffffffffffff0001,%rbx
cmp    $0xffff,%rbx
ja     1130 <bnSubMult+0x20>
mov    %r14,%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <bnSubQ@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.BigNum = type { i32 }
define i32 @bnSubMult(%struct.BigNum* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.BigNum*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
store %struct.BigNum* %0, %struct.BigNum** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %6
%10 = zext i32 %9 to i64
%11 = load i32, i32* %7
%12 = zext i32 %11 to i64
%13 = mul i64 %10, %12
store i64 %13, i64* %8
br label %14
14: ; preds = %22, %3
%15 = load i64, i64* %8
%16 = icmp ugt i64 %15, 65535
br i1 %16, label %17, label %25
17: ; preds = %14
%18 = load %struct.BigNum*, %struct.BigNum** %5
%19 = call i32 @bnSubQ(%struct.BigNum* %18, i32 65535)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 -1, i32* %4
br label %30
22: ; preds = %17
%23 = load i64, i64* %8
%24 = sub i64 %23, 65535
store i64 %24, i64* %8
br label %14
25: ; preds = %14
%26 = load %struct.BigNum*, %struct.BigNum** %5
%27 = load i64, i64* %8
%28 = trunc i64 %27 to i32
%29 = call i32 @bnSubQ(%struct.BigNum* %26, i32 %28)
store i32 %29, i32* %4
br label %30
30: ; preds = %25, %21
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
%struct.BigNum = type { i32 }
define i32 @bnSubMult(%struct.BigNum* %0, i32 %1, i32 %2) {
%4 = zext i32 %1 to i64
%5 = zext i32 %2 to i64
%6 = mul nuw i64 %5, %4
%7 = icmp ugt i64 %6, 65535
br i1 %7, label %8, label %15
8: ; preds = %3, %12
%9 = phi i64 [ %13, %12 ], [ %6, %3 ]
%10 = tail call i32 @bnSubQ(%struct.BigNum* %0, i32 65535)
%11 = icmp slt i32 %10, 0
br i1 %11, label %19, label %12
12: ; preds = %8
%13 = add i64 %9, -65535
%14 = icmp ugt i64 %13, 65535
br i1 %14, label %8, label %15
15: ; preds = %12, %3
%16 = phi i64 [ %6, %3 ], [ %13, %12 ]
%17 = trunc i64 %16 to i32
%18 = tail call i32 @bnSubQ(%struct.BigNum* %0, i32 %17)
br label %19
19: ; preds = %8, %15
%20 = phi i32 [ %18, %15 ], [ -1, %8 ]
ret i32 %20
}