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

/* Variables and functions */
void nios_pkt_8x32_pack(uint8_t *buf, uint8_t target, bool write, uint8_t addr,
                        uint32_t data) {
  buf[0] = ((uint8_t)'C');
  buf[1] = target;
  if (write) {
    buf[2] = (1 << 0);
  } else {
    buf[2] = 0x00;
  }
  buf[3] = 0x00;
  buf[4] = addr;
  buf[5 + 0] = data & 0xff;
  buf[5 + 1] = (data >> 8);
  buf[5 + 2] = (data >> 16);
  buf[5 + 3] = (data >> 24);
  buf[9 + 0] = 0x00;
  buf[9 + 1] = 0x00;
  buf[9 + 2] = 0x00;
  buf[9 + 3] = 0x00;
  buf[9 + 4] = 0x00;
  buf[9 + 5] = 0x00;
  buf[9 + 6] = 0x00;
}


x86 assembly (clang, -O0):
<nios_pkt_8x32_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   $0x43,(%rax)
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
cmpl   $0x0,-0x10(%rbp)
je     1143 <nios_pkt_8x32_pack+0x43>
mov    -0x8(%rbp),%rax
movl   $0x1,0x8(%rax)
jmp    114e <nios_pkt_8x32_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    -0x18(%rbp),%ecx
sar    $0x10,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x1c(%rax)
mov    -0x18(%rbp),%ecx
sar    $0x18,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,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_8x32_pack>:
movl   $0x43,(%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)
mov    %r8d,%eax
sar    $0x8,%eax
mov    %eax,0x18(%rdi)
mov    %r8d,%eax
sar    $0x10,%eax
mov    %eax,0x1c(%rdi)
sar    $0x18,%r8d
mov    %r8d,0x20(%rdi)
xorps  %xmm0,%xmm0
movups %xmm0,0x24(%rdi)
movups %xmm0,0x30(%rdi)
ret

LLVM IR (-O0):
define void @nios_pkt_8x32_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 67, 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* %10
%39 = ashr i32 %38, 16
%40 = load i32*, i32** %6
%41 = getelementptr inbounds i32, i32* %40, i64 7
store i32 %39, i32* %41
%42 = load i32, i32* %10
%43 = ashr i32 %42, 24
%44 = load i32*, i32** %6
%45 = getelementptr inbounds i32, i32* %44, i64 8
store i32 %43, i32* %45
%46 = load i32*, i32** %6
%47 = getelementptr inbounds i32, i32* %46, i64 9
store i32 0, i32* %47
%48 = load i32*, i32** %6
%49 = getelementptr inbounds i32, i32* %48, i64 10
store i32 0, i32* %49
%50 = load i32*, i32** %6
%51 = getelementptr inbounds i32, i32* %50, i64 11
store i32 0, i32* %51
%52 = load i32*, i32** %6
%53 = getelementptr inbounds i32, i32* %52, i64 12
store i32 0, i32* %53
%54 = load i32*, i32** %6
%55 = getelementptr inbounds i32, i32* %54, i64 13
store i32 0, i32* %55
%56 = load i32*, i32** %6
%57 = getelementptr inbounds i32, i32* %56, i64 14
store i32 0, i32* %57
%58 = load i32*, i32** %6
%59 = getelementptr inbounds i32, i32* %58, i64 15
store i32 0, i32* %59
ret void
}

LLVM IR (-O2):
define void @nios_pkt_8x32_pack(i32* nocapture writeonly %0, i32 %1, i32 %2, i32 %3, i32 %4) {
store i32 67, 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 = ashr i32 %4, 16
%17 = getelementptr inbounds i32, i32* %0, i64 7
store i32 %16, i32* %17
%18 = ashr i32 %4, 24
%19 = getelementptr inbounds i32, i32* %0, i64 8
store i32 %18, i32* %19
%20 = getelementptr inbounds i32, i32* %0, i64 9
%21 = bitcast i32* %20 to i8*
ret void
}