#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ uint8_t;
typedef int uint32_t;
typedef int uint16_t;
struct TYPE_3__ {
  int length;
  int /*<<< orphan*/ *msg;
  int /*<<< orphan*/ type;
  scalar_t__ index;
};
typedef TYPE_1__ ca_msg_t;

/* Variables and functions */
int /*<<< orphan*/ CA_CI;
int /*<<< orphan*/ CA_SEND_MSG;
int /*<<< orphan*/ ci_write_length(int /*<<< orphan*/ **, int);
int /*<<< orphan*/ dump(int /*<<< orphan*/ *, int);
int ioctl(int, int /*<<< orphan*/, TYPE_1__ *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int ci_send_obj(int fd, uint32_t tag, uint8_t *buf, uint16_t len) {
  ca_msg_t msg;
  uint8_t *p = msg.msg;
  *p++ = (tag >> 16) & 0xff;
  *p++ = (tag >> 8) & 0xff;
  *p++ = tag & 0xff;
  ci_write_length(&p, len);
  if (buf)
    memcpy(p, buf, len);
  msg.index = 0;
  msg.type = CA_CI;
  msg.length = p - msg.msg + len;
  dump(msg.msg, msg.length);
  return ioctl(fd, CA_SEND_MSG, &msg);
}


x86 assembly (clang, -O0):
<ci_send_obj>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%ecx
sar    $0x10,%ecx
and    $0xff,%ecx
mov    -0x40(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x40(%rbp)
mov    %ecx,(%rax)
mov    -0x8(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x40(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x40(%rbp)
mov    %ecx,(%rax)
mov    -0x8(%rbp),%ecx
and    $0xff,%ecx
mov    -0x40(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x40(%rbp)
mov    %ecx,(%rax)
mov    -0x14(%rbp),%esi
lea    -0x40(%rbp),%rdi
call   1060 <ci_write_length@plt>
cmpq   $0x0,-0x10(%rbp)
je     11d8 <ci_send_obj+0x98>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <memcpy@plt>
movq   $0x0,-0x20(%rbp)
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
sar    $0x2,%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%esi
call   1040 <dump@plt>
mov    -0x4(%rbp),%edi
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1030 <ioctl@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32*, i32, i64 }
@CA_CI = global i32 0
@CA_SEND_MSG = global i32 0
define i32 @ci_send_obj(i32 %0, i32 %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca %struct.TYPE_3__
%10 = alloca i32*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32 %3, i32* %8
%11 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 1
%12 = load i32*, i32** %11
store i32* %12, i32** %10
%13 = load i32, i32* %6
%14 = ashr i32 %13, 16
%15 = and i32 %14, 255
%16 = load i32*, i32** %10
%17 = getelementptr inbounds i32, i32* %16, i32 1
store i32* %17, i32** %10
store i32 %15, i32* %16
%18 = load i32, i32* %6
%19 = ashr i32 %18, 8
%20 = and i32 %19, 255
%21 = load i32*, i32** %10
%22 = getelementptr inbounds i32, i32* %21, i32 1
store i32* %22, i32** %10
store i32 %20, i32* %21
%23 = load i32, i32* %6
%24 = and i32 %23, 255
%25 = load i32*, i32** %10
%26 = getelementptr inbounds i32, i32* %25, i32 1
store i32* %26, i32** %10
store i32 %24, i32* %25
%27 = load i32, i32* %8
%28 = call i32 @ci_write_length(i32** %10, i32 %27)
%29 = load i32*, i32** %7
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %36
31: ; preds = %4
%32 = load i32*, i32** %10
%33 = load i32*, i32** %7
%34 = load i32, i32* %8
%35 = call i32 @memcpy(i32* %32, i32* %33, i32 %34)
br label %36
36: ; preds = %31, %4
%37 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 3
store i64 0, i64* %37
%38 = load i32, i32* @CA_CI
%39 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 2
store i32 %38, i32* %39
%40 = load i32*, i32** %10
%41 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 1
%42 = load i32*, i32** %41
%43 = ptrtoint i32* %40 to i64
%44 = ptrtoint i32* %42 to i64
%45 = sub i64 %43, %44
%46 = sdiv exact i64 %45, 4
%47 = load i32, i32* %8
%48 = sext i32 %47 to i64
%49 = add nsw i64 %46, %48
%50 = trunc i64 %49 to i32
%51 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 0
store i32 %50, i32* %51
%52 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 1
%53 = load i32*, i32** %52
%54 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 0
%55 = load i32, i32* %54
%56 = call i32 @dump(i32* %53, i32 %55)
%57 = load i32, i32* %5
%58 = load i32, i32* @CA_SEND_MSG
%59 = call i32 @ioctl(i32 %57, i32 %58, %struct.TYPE_3__* %9)
ret i32 %59
}

LLVM IR (-O2):