#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 */
struct ars_packet {
  int dummy;
};

/* Variables and functions */
void *ars_add_data(struct ars_packet *, size_t);
int /*<<< orphan*/ memcpy(void *, void *, size_t);
int ars_split_data(struct ars_packet *pkt, void *packet, size_t size,
                   int *state, int *len) {
  void *newdata;
  if ((newdata = ars_add_data(pkt, size)) == NULL)
    return -3;
  memcpy(newdata, packet, size);
  *len = size;
  *state = 0;
  return -0;
}


x86 assembly (clang, -O0):
<ars_split_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <ars_add_data@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1163 <ars_split_data+0x43>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1191 <ars_split_data+0x71>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ars_split_data>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdx,%rsi
call   1040 <ars_add_data@plt>
test   %rax,%rax
je     115d <ars_split_data+0x3d>
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1030 <memcpy@plt>
mov    %ebx,(%r14)
movl   $0x0,(%r15)
xor    %eax,%eax
jmp    1162 <ars_split_data+0x42>
mov    $0xfffffffd,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.ars_packet = type { i32 }
define i32 @ars_split_data(%struct.ars_packet* %0, i8* %1, i64 %2, i32* nocapture writeonly %3, i32* nocapture writeonly %4) {
%6 = tail call i8* @ars_add_data(%struct.ars_packet* %0, i64 %2)
%7 = icmp eq i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = tail call i32 @memcpy(i8* %6, i8* %1, i64 %2)
%10 = trunc i64 %2 to i32
store i32 %10, i32* %4
store i32 0, i32* %3
br label %11
11: ; preds = %5, %8
%12 = phi i32 [ 0, %8 ], [ -3, %5 ]
ret i32 %12
}