#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;
typedef int uint32_t;
typedef int uint16_t;

/* Variables and functions */
void mpi_sub(uint16_t *dest, const uint16_t *src) {
  uint32_t c = 1;
  uint8_t count = 128;
  do {
    c += 65535 + *dest - *src;
    *dest = c & 0xFFFF;
    src++;
    dest++;
    c >>= 16;
    c &= 1;
  } while (--count);
}


x86 assembly (clang, -O0):
<mpi_sub>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x80,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
add    $0xffff,%eax
mov    -0x10(%rbp),%rcx
sub    (%rcx),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%ecx
and    $0xffff,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
sar    $0x10,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jne    111a <mpi_sub+0x1a>
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpi_sub>:
mov    $0x1,%eax
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
add    (%rdi,%rcx,4),%eax
sub    (%rsi,%rcx,4),%eax
add    $0xffff,%eax
movzwl %ax,%edx
mov    %edx,(%rdi,%rcx,4)
shr    $0x10,%eax
and    $0x1,%eax
add    0x4(%rdi,%rcx,4),%eax
sub    0x4(%rsi,%rcx,4),%eax
add    $0xffff,%eax
movzwl %ax,%edx
mov    %edx,0x4(%rdi,%rcx,4)
shr    $0x10,%eax
and    $0x1,%eax
add    $0x2,%rcx
cmp    $0x80,%ecx
jne    1110 <mpi_sub+0x10>
ret

LLVM IR (-O0):
define void @mpi_sub(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
store i32 1, i32* %5
store i32 128, i32* %6
br label %7
7: ; preds = %27, %2
%8 = load i32*, i32** %3
%9 = load i32, i32* %8
%10 = add nsw i32 65535, %9
%11 = load i32*, i32** %4
%12 = load i32, i32* %11
%13 = sub nsw i32 %10, %12
%14 = load i32, i32* %5
%15 = add nsw i32 %14, %13
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = and i32 %16, 65535
%18 = load i32*, i32** %3
store i32 %17, i32* %18
%19 = load i32*, i32** %4
%20 = getelementptr inbounds i32, i32* %19, i32 1
store i32* %20, i32** %4
%21 = load i32*, i32** %3
%22 = getelementptr inbounds i32, i32* %21, i32 1
store i32* %22, i32** %3
%23 = load i32, i32* %5
%24 = ashr i32 %23, 16
store i32 %24, i32* %5
%25 = load i32, i32* %5
%26 = and i32 %25, 1
store i32 %26, i32* %5
br label %27
27: ; preds = %7
%28 = load i32, i32* %6
%29 = add nsw i32 %28, -1
store i32 %29, i32* %6
%30 = icmp ne i32 %29, 0
br i1 %30, label %7, label %31
31: ; preds = %27
ret void
}

LLVM IR (-O2):
define void @mpi_sub(i32* nocapture %0, i32* nocapture %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i32* [ %0, %2 ], [ %25, %3 ]
%5 = phi i32* [ %1, %2 ], [ %24, %3 ]
%6 = phi i32 [ 1, %2 ], [ %27, %3 ]
%7 = phi i32 [ 128, %2 ], [ %28, %3 ]
%8 = load i32, i32* %4
%9 = load i32, i32* %5
%10 = add nuw nsw i32 %6, 65535
%11 = add i32 %10, %8
%12 = sub i32 %11, %9
%13 = and i32 %12, 65535
store i32 %13, i32* %4
%14 = getelementptr inbounds i32, i32* %5, i64 1
%15 = getelementptr inbounds i32, i32* %4, i64 1
%16 = lshr i32 %12, 16
%17 = and i32 %16, 1
%18 = load i32, i32* %15
%19 = load i32, i32* %14
%20 = add nuw nsw i32 %17, 65535
%21 = add i32 %20, %18
%22 = sub i32 %21, %19
%23 = and i32 %22, 65535
store i32 %23, i32* %15
%24 = getelementptr inbounds i32, i32* %5, i64 2
%25 = getelementptr inbounds i32, i32* %4, i64 2
%26 = lshr i32 %22, 16
%27 = and i32 %26, 1
%28 = add nsw i32 %7, -2
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %3
30: ; preds = %3
ret void
}