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

/* Variables and functions */
void nios_pkt_8x16_pack(uint8_t *buf, uint8_t target, bool write, uint8_t addr,
                        uint16_t data) {
  buf[0] = ((uint8_t)'B');
  buf[1] = target;
  if (write) {
    buf[2] = (1 << 0);
  } else {
    buf[2] = 0x00;
  }
  buf[3] = 0x00;
  buf[4] = addr;
  buf[5] = data & 0xff;
  buf[5 + 1] = (data >> 8);
  buf[7 + 0] = 0x00;
  buf[7 + 1] = 0x00;
  buf[7 + 2] = 0x00;
  buf[7 + 3] = 0x00;
  buf[7 + 4] = 0x00;
  buf[7 + 5] = 0x00;
  buf[7 + 6] = 0x00;
  buf[7 + 7] = 0x00;
  buf[7 + 8] = 0x00;
}


x86 assembly (clang, -O0):
<nios_pkt_8x16_pack>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movl   $0x42,(%rax)
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
cmpl   $0x0,-0x10(%rbp)
je     1143 <nios_pkt_8x16_pack+0x43>
mov    -0x8(%rbp),%rax
movl   $0x1,0x8(%rax)
jmp    114e <nios_pkt_8x16_pack+0x4e>
mov    -0x8(%rbp),%rax
movl   $0x0,0x8(%rax)
mov    -0x8(%rbp),%rax
movl   $0x0,0xc(%rax)
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x18(%rbp),%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x14(%rax)
mov    -0x18(%rbp),%ecx
sar    $0x8,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    -0x8(%rbp),%rax
movl   $0x0,0x1c(%rax)
mov    -0x8(%rbp),%rax
movl   $0x0,0x20(%rax)
mov    -0x8(%rbp),%rax
movl   $0x0,0x24(%rax)
mov    -0x8(%rbp),%rax
movl   $0x0,0x28(%rax)
mov    -0x8(%rbp),%rax
movl   $0x0,0x2c(%rax)
mov    -0x8(%rbp),%rax
movl   $0x0,0x30(%rax)
mov    -0x8(%rbp),%rax
movl   $0x0,0x34(%rax)
mov    -0x8(%rbp),%rax
movl   $0x0,0x38(%rax)
mov    -0x8(%rbp),%rax
movl   $0x0,0x3c(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<nios_pkt_8x16_pack>:
movl   $0x42,(%rdi)
mov    %esi,0x4(%rdi)
xor    %eax,%eax
test   %edx,%edx
setne  %al
mov    %eax,0x8(%rdi)
movl   $0x0,0xc(%rdi)
mov    %ecx,0x10(%rdi)
movzbl %r8b,%eax
mov    %eax,0x14(%rdi)
sar    $0x8,%r8d
mov    %r8d,0x18(%rdi)
xorps  %xmm0,%xmm0
movups %xmm0,0x1c(%rdi)
movups %xmm0,0x2c(%rdi)
movl   $0x0,0x3c(%rdi)
ret

LLVM IR (-O0):
define void @nios_pkt_8x16_pack(i32* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%11 = load i32*, i32** %6
%12 = getelementptr inbounds i32, i32* %11, i64 0
store i32 66, i32* %12
%13 = load i32, i32* %7
%14 = load i32*, i32** %6
%15 = getelementptr inbounds i32, i32* %14, i64 1
store i32 %13, i32* %15
%16 = load i32, i32* %8
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %5
%19 = load i32*, i32** %6
%20 = getelementptr inbounds i32, i32* %19, i64 2
store i32 1, i32* %20
br label %24
21: ; preds = %5
%22 = load i32*, i32** %6
%23 = getelementptr inbounds i32, i32* %22, i64 2
store i32 0, i32* %23
br label %24
24: ; preds = %21, %18
%25 = load i32*, i32** %6
%26 = getelementptr inbounds i32, i32* %25, i64 3
store i32 0, i32* %26
%27 = load i32, i32* %9
%28 = load i32*, i32** %6
%29 = getelementptr inbounds i32, i32* %28, i64 4
store i32 %27, i32* %29
%30 = load i32, i32* %10
%31 = and i32 %30, 255
%32 = load i32*, i32** %6
%33 = getelementptr inbounds i32, i32* %32, i64 5
store i32 %31, i32* %33
%34 = load i32, i32* %10
%35 = ashr i32 %34, 8
%36 = load i32*, i32** %6
%37 = getelementptr inbounds i32, i32* %36, i64 6
store i32 %35, i32* %37
%38 = load i32*, i32** %6
%39 = getelementptr inbounds i32, i32* %38, i64 7
store i32 0, i32* %39
%40 = load i32*, i32** %6
%41 = getelementptr inbounds i32, i32* %40, i64 8
store i32 0, i32* %41
%42 = load i32*, i32** %6
%43 = getelementptr inbounds i32, i32* %42, i64 9
store i32 0, i32* %43
%44 = load i32*, i32** %6
%45 = getelementptr inbounds i32, i32* %44, i64 10
store i32 0, i32* %45
%46 = load i32*, i32** %6
%47 = getelementptr inbounds i32, i32* %46, i64 11
store i32 0, i32* %47
%48 = load i32*, i32** %6
%49 = getelementptr inbounds i32, i32* %48, i64 12
store i32 0, i32* %49
%50 = load i32*, i32** %6
%51 = getelementptr inbounds i32, i32* %50, i64 13
store i32 0, i32* %51
%52 = load i32*, i32** %6
%53 = getelementptr inbounds i32, i32* %52, i64 14
store i32 0, i32* %53
%54 = load i32*, i32** %6
%55 = getelementptr inbounds i32, i32* %54, i64 15
store i32 0, i32* %55
ret void
}

LLVM IR (-O2):
define void @nios_pkt_8x16_pack(i32* nocapture writeonly %0, i32 %1, i32 %2, i32 %3, i32 %4) {
store i32 66, i32* %0
%6 = getelementptr inbounds i32, i32* %0, i64 1
store i32 %1, i32* %6
%7 = icmp ne i32 %2, 0
%8 = zext i1 %7 to i32
%9 = getelementptr inbounds i32, i32* %0, i64 2
store i32 %8, i32* %9
%10 = getelementptr inbounds i32, i32* %0, i64 3
store i32 0, i32* %10
%11 = getelementptr inbounds i32, i32* %0, i64 4
store i32 %3, i32* %11
%12 = and i32 %4, 255
%13 = getelementptr inbounds i32, i32* %0, i64 5
store i32 %12, i32* %13
%14 = ashr i32 %4, 8
%15 = getelementptr inbounds i32, i32* %0, i64 6
store i32 %14, i32* %15
%16 = getelementptr inbounds i32, i32* %0, i64 7
%17 = bitcast i32* %16 to i8*
ret void
}