#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 scalar_t__ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(void *, void *, scalar_t__);
int pack_bytes(void *inbuf, uint32_t insize, void *outbuf, uint32_t *outsize) {
  if ((NULL == inbuf) || (NULL == outbuf) || (NULL == outsize)) {
    return -1;
  }
  if (insize > *outsize) {
    return -1;
  }
  *outsize = insize;
  memcpy(outbuf, inbuf, insize);
  return 0;
}


x86 assembly (clang, -O0):
<pack_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     114c <pack_bytes+0x3c>
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
je     114c <pack_bytes+0x3c>
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    1158 <pack_bytes+0x48>
movl   $0xffffffff,-0x4(%rbp)
jmp    1198 <pack_bytes+0x88>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
cmp    (%rcx),%rax
jle    1175 <pack_bytes+0x65>
movl   $0xffffffff,-0x4(%rbp)
jmp    1198 <pack_bytes+0x88>
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pack_bytes>:
push   %rax
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     1140 <pack_bytes+0x30>
test   %rdx,%rdx
je     1140 <pack_bytes+0x30>
test   %rcx,%rcx
je     1140 <pack_bytes+0x30>
mov    %rsi,%r8
cmp    %rsi,(%rcx)
jl     1140 <pack_bytes+0x30>
mov    %rdi,%rsi
mov    %r8,(%rcx)
mov    %rdx,%rdi
mov    %r8,%rdx
call   1030 <memcpy@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @pack_bytes(i8* %0, i64 %1, i8* %2, i64* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64*
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i64* %3, i64** %9
%10 = load i8*, i8** %6
%11 = icmp eq i8* null, %10
br i1 %11, label %18, label %12
12: ; preds = %4
%13 = load i8*, i8** %8
%14 = icmp eq i8* null, %13
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i64*, i64** %9
%17 = icmp eq i64* null, %16
br i1 %17, label %18, label %19
18: ; preds = %15, %12, %4
store i32 -1, i32* %5
br label %32
19: ; preds = %15
%20 = load i64, i64* %7
%21 = load i64*, i64** %9
%22 = load i64, i64* %21
%23 = icmp sgt i64 %20, %22
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 -1, i32* %5
br label %32
25: ; preds = %19
%26 = load i64, i64* %7
%27 = load i64*, i64** %9
store i64 %26, i64* %27
%28 = load i8*, i8** %8
%29 = load i8*, i8** %6
%30 = load i64, i64* %7
%31 = call i32 @memcpy(i8* %28, i8* %29, i64 %30)
store i32 0, i32* %5
br label %32
32: ; preds = %25, %24, %18
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
define i32 @pack_bytes(i8* %0, i64 %1, i8* %2, i64* %3) {
%5 = icmp eq i8* %0, null
%6 = icmp eq i8* %2, null
%7 = or i1 %5, %6
%8 = icmp eq i64* %3, null
%9 = or i1 %7, %8
br i1 %9, label %15, label %10
10: ; preds = %4
%11 = load i64, i64* %3
%12 = icmp slt i64 %11, %1
br i1 %12, label %15, label %13
13: ; preds = %10
store i64 %1, i64* %3
%14 = tail call i32 @memcpy(i8* %2, i8* %0, i64 %1)
br label %15
15: ; preds = %10, %4, %13
%16 = phi i32 [ 0, %13 ], [ -1, %4 ], [ -1, %10 ]
ret i32 %16
}