#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*/ pcap_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)
      pcap_snprintf(errbuf, errbuflen,
                    "Not enough space in the temporary send buffer.");
    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    1182 <sock_bufferize+0x62>
cmpq   $0x0,0x10(%rbp)
je     1176 <sock_bufferize+0x56>
mov    0x10(%rbp),%rdi
mov    0x18(%rbp),%esi
lea    0xe8f(%rip),%rdx
call   1040 <pcap_snprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b8 <sock_bufferize+0x98>
cmpl   $0x0,-0x30(%rbp)
jne    11a6 <sock_bufferize+0x86>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
movslq (%rax),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <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   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %esi,%ebx
movslq (%rcx),%rax
lea    (%rax,%rbx,1),%ecx
cmp    %r8d,%ecx
jle    1155 <sock_bufferize+0x35>
mov    0x20(%rsp),%rdi
mov    $0xffffffff,%ebx
test   %rdi,%rdi
je     1174 <sock_bufferize+0x54>
mov    0x28(%rsp),%esi
lea    0xeb2(%rip),%rdx
call   1040 <pcap_snprintf@plt>
jmp    1174 <sock_bufferize+0x54>
test   %r9d,%r9d
jne    116f <sock_bufferize+0x4f>
mov    %rdi,%rsi
add    %rax,%rdx
mov    %rdx,%rdi
mov    %ebx,%edx
call   1030 <memcpy@plt>
add    (%r14),%ebx
mov    %ebx,%ecx
mov    %ecx,(%r14)
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
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 %32
24: ; preds = %8
%25 = load i8*, i8** %16
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i8*, i8** %16
%29 = load i32, i32* %17
%30 = call i32 @pcap_snprintf(i8* %28, i32 %29, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %27, %24
store i32 -1, i32* %9
br label %49
32: ; preds = %8
%33 = load i32, i32* %15
%34 = icmp ne i32 %33, 0
br i1 %34, label %44, label %35
35: ; preds = %32
%36 = load i8*, i8** %12
%37 = load i32*, i32** %13
%38 = load i32, i32* %37
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
%41 = load i8*, i8** %10
%42 = load i32, i32* %11
%43 = call i32 @memcpy(i8* %40, i8* %41, i32 %42)
br label %44
44: ; preds = %35, %32
%45 = load i32, i32* %11
%46 = load i32*, i32** %13
%47 = load i32, i32* %46
%48 = add nsw i32 %47, %45
store i32 %48, i32* %46
store i32 0, i32* %9
br label %49
49: ; preds = %44, %31
%50 = load i32, i32* %9
ret i32 %50
}

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 %16
12: ; preds = %8
%13 = icmp eq i8* %6, null
br i1 %13, label %26, label %14
14: ; preds = %12
%15 = tail call i32 @pcap_snprintf(i8* %6, i32 %7, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
br label %26
16: ; preds = %8
%17 = icmp eq i32 %5, 0
br i1 %17, label %18, label %24
18: ; preds = %16
%19 = sext i32 %9 to i64
%20 = getelementptr inbounds i8, i8* %2, i64 %19
%21 = tail call i32 @memcpy(i8* %20, i8* %0, i32 %1)
%22 = load i32, i32* %3
%23 = add nsw i32 %22, %1
br label %24
24: ; preds = %18, %16
%25 = phi i32 [ %23, %18 ], [ %10, %16 ]
store i32 %25, i32* %3
br label %26
26: ; preds = %12, %14, %24
%27 = phi i32 [ 0, %24 ], [ -1, %14 ], [ -1, %12 ]
ret i32 %27
}