#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*/ uint8_t;
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
scalar_t__ _attoHTTPWriteC(int /*<<< orphan*/);
uint32_t attoHTTPwrite(const uint8_t *buffer, uint32_t len) {
  uint32_t ret = 0;
  uint8_t c;
  while (len-- > 0) {
    c = *buffer++;
    ret += _attoHTTPWriteC(c);
  }
  return ret;
}


x86 assembly (clang, -O0):
<attoHTTPwrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
jle    1168 <attoHTTPwrite+0x58>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <_attoHTTPWriteC@plt>
mov    %rax,%rcx
movslq -0x10(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
jmp    1126 <attoHTTPwrite+0x16>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<attoHTTPwrite>:
push   %rbp
push   %r14
push   %rbx
test   %esi,%esi
jle    1148 <attoHTTPwrite+0x38>
mov    %esi,%ebp
mov    %rdi,%rbx
add    $0x1,%ebp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rbx),%edi
add    $0x4,%rbx
call   1030 <_attoHTTPWriteC@plt>
add    %eax,%r14d
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     1130 <attoHTTPwrite+0x20>
jmp    114b <attoHTTPwrite+0x3b>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @attoHTTPwrite(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 0, i32* %5
br label %7
7: ; preds = %11, %2
%8 = load i32, i32* %4
%9 = add nsw i32 %8, -1
store i32 %9, i32* %4
%10 = icmp sgt i32 %8, 0
br i1 %10, label %11, label %21
11: ; preds = %7
%12 = load i32*, i32** %3
%13 = getelementptr inbounds i32, i32* %12, i32 1
store i32* %13, i32** %3
%14 = load i32, i32* %12
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = call i64 @_attoHTTPWriteC(i32 %15)
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = add nsw i64 %18, %16
%20 = trunc i64 %19 to i32
store i32 %20, i32* %5
br label %7
21: ; preds = %7
%22 = load i32, i32* %5
ret i32 %22
}

LLVM IR (-O2):
define i32 @attoHTTPwrite(i32* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %15
4: ; preds = %2, %4
%5 = phi i32* [ %9, %4 ], [ %0, %2 ]
%6 = phi i32 [ %13, %4 ], [ 0, %2 ]
%7 = phi i32 [ %8, %4 ], [ %1, %2 ]
%8 = add nsw i32 %7, -1
%9 = getelementptr inbounds i32, i32* %5, i64 1
%10 = load i32, i32* %5
%11 = tail call i64 @_attoHTTPWriteC(i32 %10)
%12 = trunc i64 %11 to i32
%13 = add i32 %6, %12
%14 = icmp ugt i32 %7, 1
br i1 %14, label %4, label %15
15: ; preds = %4, %2
%16 = phi i32 [ 0, %2 ], [ %13, %4 ]
ret i32 %16
}