#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 int /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ swap16(int /*<<< orphan*/ *);
int /*<<< orphan*/ write_register(int /*<<< orphan*/, int /*<<< orphan*/);
int rt_modbus_preset_single_register(uint8_t *buf, int sz) {
  uint16_t address;
  uint16_t value;
  memcpy(&address, buf + 2, 2);
  swap16(&address);
  memcpy(&value, buf + 4, 2);
  swap16(&value);
  write_register(address, value);
  return 8;
}


x86 assembly (clang, -O0):
<rt_modbus_preset_single_register>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
add    $0x8,%rsi
lea    -0x10(%rbp),%rdi
mov    $0x2,%edx
call   1030 <memcpy@plt>
lea    -0x10(%rbp),%rdi
call   1050 <swap16@plt>
mov    -0x8(%rbp),%rsi
add    $0x10,%rsi
lea    -0x14(%rbp),%rdi
mov    $0x2,%edx
call   1030 <memcpy@plt>
lea    -0x14(%rbp),%rdi
call   1050 <swap16@plt>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <write_register@plt>
mov    $0x8,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rt_modbus_preset_single_register>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0x8(%rdi),%rsi
lea    0x4(%rsp),%r14
mov    %r14,%rdi
mov    $0x2,%edx
call   1030 <memcpy@plt>
mov    %r14,%rdi
call   1050 <swap16@plt>
add    $0x10,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1030 <memcpy@plt>
mov    %r14,%rdi
call   1050 <swap16@plt>
mov    0x4(%rsp),%edi
mov    (%rsp),%esi
call   1040 <write_register@plt>
mov    $0x8,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @rt_modbus_preset_single_register(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = load i32*, i32** %3
%8 = getelementptr inbounds i32, i32* %7, i64 2
%9 = call i32 @memcpy(i32* %5, i32* %8, i32 2)
%10 = call i32 @swap16(i32* %5)
%11 = load i32*, i32** %3
%12 = getelementptr inbounds i32, i32* %11, i64 4
%13 = call i32 @memcpy(i32* %6, i32* %12, i32 2)
%14 = call i32 @swap16(i32* %6)
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = call i32 @write_register(i32 %15, i32 %16)
ret i32 8
}

LLVM IR (-O2):
define i32 @rt_modbus_preset_single_register(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = getelementptr inbounds i32, i32* %0, i64 2
%8 = call i32 @memcpy(i32* %3, i32* %7, i32 2)
%9 = call i32 @swap16(i32* %3)
%10 = getelementptr inbounds i32, i32* %0, i64 4
%11 = call i32 @memcpy(i32* %4, i32* %10, i32 2)
%12 = call i32 @swap16(i32* %4)
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = call i32 @write_register(i32 %13, i32 %14)
ret i32 8
}