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

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ snprintf(char *, int, char *);
int sock_bufferize(const char *buffer, int size, char *tempbuf, int *offset,
                   int totsize, int checkonly, char *errbuf, int errbuflen) {
  if ((*offset + size) > totsize) {
    if (errbuf) {
      snprintf(errbuf, errbuflen,
               "Not enough space in the temporary send buffer.");
      errbuf[errbuflen - 1] = 0;
    }
    return -1;
  };
  if (!checkonly)
    memcpy(tempbuf + (*offset), buffer, size);
  (*offset) += size;
  return 0;
}


x86 assembly (clang, -O0):
<sock_bufferize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    %r9d,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
add    -0x14(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jle    1193 <sock_bufferize+0x73>
cmpq   $0x0,0x10(%rbp)
je     1187 <sock_bufferize+0x67>
mov    0x10(%rbp),%rdi
mov    0x18(%rbp),%esi
lea    0xe8f(%rip),%rdx
call   1030 <snprintf@plt>
mov    0x10(%rbp),%rax
mov    0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <sock_bufferize+0xa9>
cmpl   $0x0,-0x30(%rbp)
jne    11b7 <sock_bufferize+0x97>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
movslq (%rax),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x14(%rbp),%ecx
mov    -0x28(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_bufferize>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %esi,%ebx
movslq (%rcx),%rax
lea    (%rax,%rbx,1),%ecx
cmp    %r8d,%ecx
jle    1163 <sock_bufferize+0x43>
mov    0x20(%rsp),%r14
mov    $0xffffffff,%ebx
test   %r14,%r14
je     1182 <sock_bufferize+0x62>
mov    0x28(%rsp),%ebp
lea    0xeb2(%rip),%rdx
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <snprintf@plt>
movslq %ebp,%rax
movb   $0x0,-0x1(%rax,%r14,1)
jmp    1182 <sock_bufferize+0x62>
test   %r9d,%r9d
jne    117d <sock_bufferize+0x5d>
mov    %rdi,%rsi
add    %rax,%rdx
mov    %rdx,%rdi
mov    %ebx,%edx
call   1040 <memcpy@plt>
add    (%r14),%ebx
mov    %ebx,%ecx
mov    %ecx,(%r14)
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [47 x i8] c"Not enough space in the temporary send buffer.\00"
define i32 @sock_bufferize(i8* %0, i32 %1, i8* %2, i32* %3, i32 %4, i32 %5, i8* %6, i32 %7) {
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i32
store i8* %0, i8** %10
store i32 %1, i32* %11
store i8* %2, i8** %12
store i32* %3, i32** %13
store i32 %4, i32* %14
store i32 %5, i32* %15
store i8* %6, i8** %16
store i32 %7, i32* %17
%18 = load i32*, i32** %13
%19 = load i32, i32* %18
%20 = load i32, i32* %11
%21 = add nsw i32 %19, %20
%22 = load i32, i32* %14
%23 = icmp sgt i32 %21, %22
br i1 %23, label %24, label %37
24: ; preds = %8
%25 = load i8*, i8** %16
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %36
27: ; preds = %24
%28 = load i8*, i8** %16
%29 = load i32, i32* %17
%30 = call i32 @snprintf(i8* %28, i32 %29, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%31 = load i8*, i8** %16
%32 = load i32, i32* %17
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
store i8 0, i8* %35
br label %36
36: ; preds = %27, %24
store i32 -1, i32* %9
br label %54
37: ; preds = %8
%38 = load i32, i32* %15
%39 = icmp ne i32 %38, 0
br i1 %39, label %49, label %40
40: ; preds = %37
%41 = load i8*, i8** %12
%42 = load i32*, i32** %13
%43 = load i32, i32* %42
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %41, i64 %44
%46 = load i8*, i8** %10
%47 = load i32, i32* %11
%48 = call i32 @memcpy(i8* %45, i8* %46, i32 %47)
br label %49
49: ; preds = %40, %37
%50 = load i32, i32* %11
%51 = load i32*, i32** %13
%52 = load i32, i32* %51
%53 = add nsw i32 %52, %50
store i32 %53, i32* %51
store i32 0, i32* %9
br label %54
54: ; preds = %49, %36
%55 = load i32, i32* %9
ret i32 %55
}

LLVM IR (-O2):
@.str = [47 x i8] c"Not enough space in the temporary send buffer.\00"
define i32 @sock_bufferize(i8* %0, i32 %1, i8* %2, i32* nocapture %3, i32 %4, i32 %5, i8* %6, i32 %7) {
%9 = load i32, i32* %3
%10 = add nsw i32 %9, %1
%11 = icmp sgt i32 %10, %4
br i1 %11, label %12, label %19
12: ; preds = %8
%13 = icmp eq i8* %6, null
br i1 %13, label %29, label %14
14: ; preds = %12
%15 = tail call i32 @snprintf(i8* %6, i32 %7, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%16 = add nsw i32 %7, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %6, i64 %17
store i8 0, i8* %18
br label %29
19: ; preds = %8
%20 = icmp eq i32 %5, 0
br i1 %20, label %21, label %27
21: ; preds = %19
%22 = sext i32 %9 to i64
%23 = getelementptr inbounds i8, i8* %2, i64 %22
%24 = tail call i32 @memcpy(i8* %23, i8* %0, i32 %1)
%25 = load i32, i32* %3
%26 = add nsw i32 %25, %1
br label %27
27: ; preds = %21, %19
%28 = phi i32 [ %26, %21 ], [ %10, %19 ]
store i32 %28, i32* %3
br label %29
29: ; preds = %12, %14, %27
%30 = phi i32 [ 0, %27 ], [ -1, %14 ], [ -1, %12 ]
ret i32 %30
}