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

/* Variables and functions */
int attoHTTPwrite(int /*<<< orphan*/ *, int);
int vsnprintf(char *, int, char const *, int /*<<< orphan*/);
uint16_t attoHTTPvprintf(const char *format, va_list ap) {
  char buffer[128];
  uint16_t count;
  count = vsnprintf(buffer, sizeof(buffer), format, ap);
  if (count == 128) {
    buffer[128 - 1] = 0;
    count--;
  }
  return attoHTTPwrite((uint8_t *)buffer, count);
}


x86 assembly (clang, -O0):
<attoHTTPvprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    $0x80,%esi
call   1030 <vsnprintf@plt>
mov    %eax,-0x94(%rbp)
cmpl   $0x80,-0x94(%rbp)
jne    1173 <attoHTTPvprintf+0x53>
movb   $0x0,-0x11(%rbp)
mov    -0x94(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x94(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x94(%rbp),%esi
call   1040 <attoHTTPwrite@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<attoHTTPvprintf>:
sub    $0x88,%rsp
mov    %esi,%ecx
mov    %rdi,%rdx
mov    %rsp,%rdi
mov    $0x80,%esi
call   1030 <vsnprintf@plt>
cmp    $0x80,%eax
jne    114a <attoHTTPvprintf+0x2a>
movb   $0x0,0x7f(%rsp)
mov    $0x7f,%eax
mov    %rsp,%rdi
mov    %eax,%esi
call   1040 <attoHTTPwrite@plt>
add    $0x88,%rsp
ret

LLVM IR (-O0):
define i32 @attoHTTPvprintf(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [128 x i8]
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = load i32, i32* %4
%10 = call i32 @vsnprintf(i8* %7, i32 128, i8* %8, i32 %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 128
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 127
store i8 0, i8* %14
%15 = load i32, i32* %6
%16 = add nsw i32 %15, -1
store i32 %16, i32* %6
br label %17
17: ; preds = %13, %2
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%19 = bitcast i8* %18 to i32*
%20 = load i32, i32* %6
%21 = call i32 @attoHTTPwrite(i32* %19, i32 %20)
ret i32 %21
}

LLVM IR (-O2):
define i32 @attoHTTPvprintf(i8* nocapture %0, i32 %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = call i32 @vsnprintf(i8* %4, i32 128, i8* %0, i32 %1)
%6 = icmp eq i32 %5, 128
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 127
store i8 0, i8* %8
br label %9
9: ; preds = %7, %2
%10 = phi i32 [ 127, %7 ], [ %5, %2 ]
%11 = bitcast [128 x i8]* %3 to i32*
%12 = call i32 @attoHTTPwrite(i32* %11, i32 %10)
ret i32 %12
}