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

/* Variables and functions */
scalar_t__ get_uint32le(unsigned char *);
int /*<<< orphan*/ put_uint32le(unsigned char *, int /*<<< orphan*/);
void telechips_encode_sum(unsigned char *buf, int length) {
  uint32_t sum;
  int i;
  put_uint32le(buf + 0x10, 0);
  sum = 0;
  for (i = 0; i < length; i += 4) {
    sum += get_uint32le(buf + i);
  }
  sum = -sum;
  put_uint32le(buf + 0x10, sum);
}


x86 assembly (clang, -O0):
<telechips_encode_sum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x10,%rdi
xor    %esi,%esi
call   1030 <put_uint32le@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1183 <telechips_encode_sum+0x63>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
call   1040 <get_uint32le@plt>
mov    %rax,%rcx
movslq -0x10(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x14(%rbp)
jmp    114c <telechips_encode_sum+0x2c>
xor    %eax,%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x10,%rdi
mov    -0x10(%rbp),%esi
call   1030 <put_uint32le@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<telechips_encode_sum>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %rdi,%r12
lea    0x10(%rdi),%r14
xor    %ebp,%ebp
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <put_uint32le@plt>
test   %r15d,%r15d
jle    1164 <telechips_encode_sum+0x44>
xor    %ebx,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
lea    (%r12,%rbx,1),%rdi
call   1040 <get_uint32le@plt>
add    %eax,%ebp
add    $0x4,%rbx
cmp    %r15d,%ebx
jl     1150 <telechips_encode_sum+0x30>
neg    %ebp
mov    %r14,%rdi
mov    %ebp,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <put_uint32le@plt>

LLVM IR (-O0):
define void @telechips_encode_sum(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i64 16
%9 = call i32 @put_uint32le(i8* %8, i32 0)
store i32 0, i32* %5
store i32 0, i32* %6
br label %10
10: ; preds = %24, %2
%11 = load i32, i32* %6
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %27
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = call i64 @get_uint32le(i8* %18)
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = add nsw i64 %21, %19
%23 = trunc i64 %22 to i32
store i32 %23, i32* %5
br label %24
24: ; preds = %14
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 4
store i32 %26, i32* %6
br label %10
27: ; preds = %10
%28 = load i32, i32* %5
%29 = sub nsw i32 0, %28
store i32 %29, i32* %5
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i64 16
%32 = load i32, i32* %5
%33 = call i32 @put_uint32le(i8* %31, i32 %32)
ret void
}

LLVM IR (-O2):
define void @telechips_encode_sum(i8* %0, i32 %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 16
%4 = tail call i32 @put_uint32le(i8* %3, i32 0)
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %16
6: ; preds = %2, %6
%7 = phi i64 [ %13, %6 ], [ 0, %2 ]
%8 = phi i32 [ %12, %6 ], [ 0, %2 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %7
%10 = tail call i64 @get_uint32le(i8* %9)
%11 = trunc i64 %10 to i32
%12 = add i32 %8, %11
%13 = add nuw i64 %7, 4
%14 = trunc i64 %13 to i32
%15 = icmp slt i32 %14, %1
br i1 %15, label %6, label %16
16: ; preds = %6, %2
%17 = phi i32 [ 0, %2 ], [ %12, %6 ]
%18 = sub nsw i32 0, %17
%19 = tail call i32 @put_uint32le(i8* %3, i32 %18)
ret void
}