#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_32x32_pack(uint8_t *buf, uint8_t target, bool write,
                         uint32_t addr, uint32_t data) {
  buf[0] = ((uint8_t)'K');
  buf[1] = target;
  if (write) {
    buf[2] = (1 << 0);
  } else {
    buf[2] = 0x00;
  }
  buf[3] = 0x00;
  buf[4 + 0] = (addr >> 0);
  buf[4 + 1] = (addr >> 8);
  buf[4 + 2] = (addr >> 16);
  buf[4 + 3] = (addr >> 24);
  buf[8 + 0] = (data >> 0);
  buf[8 + 1] = (data >> 8);
  buf[8 + 2] = (data >> 16);
  buf[8 + 3] = (data >> 24);
  buf[12 + 0] = 0x00;
  buf[12 + 1] = 0x00;
  buf[12 + 2] = 0x00;
  buf[12 + 3] = 0x00;
}


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

LLVM IR (-O0):
define void @nios_pkt_32x32_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 75, 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 = ashr i32 %27, 0
%29 = load i32*, i32** %6
%30 = getelementptr inbounds i32, i32* %29, i64 4
store i32 %28, i32* %30
%31 = load i32, i32* %9
%32 = ashr i32 %31, 8
%33 = load i32*, i32** %6
%34 = getelementptr inbounds i32, i32* %33, i64 5
store i32 %32, i32* %34
%35 = load i32, i32* %9
%36 = ashr i32 %35, 16
%37 = load i32*, i32** %6
%38 = getelementptr inbounds i32, i32* %37, i64 6
store i32 %36, i32* %38
%39 = load i32, i32* %9
%40 = ashr i32 %39, 24
%41 = load i32*, i32** %6
%42 = getelementptr inbounds i32, i32* %41, i64 7
store i32 %40, i32* %42
%43 = load i32, i32* %10
%44 = ashr i32 %43, 0
%45 = load i32*, i32** %6
%46 = getelementptr inbounds i32, i32* %45, i64 8
store i32 %44, i32* %46
%47 = load i32, i32* %10
%48 = ashr i32 %47, 8
%49 = load i32*, i32** %6
%50 = getelementptr inbounds i32, i32* %49, i64 9
store i32 %48, i32* %50
%51 = load i32, i32* %10
%52 = ashr i32 %51, 16
%53 = load i32*, i32** %6
%54 = getelementptr inbounds i32, i32* %53, i64 10
store i32 %52, i32* %54
%55 = load i32, i32* %10
%56 = ashr i32 %55, 24
%57 = load i32*, i32** %6
%58 = getelementptr inbounds i32, i32* %57, i64 11
store i32 %56, i32* %58
%59 = load i32*, i32** %6
%60 = getelementptr inbounds i32, i32* %59, i64 12
store i32 0, i32* %60
%61 = load i32*, i32** %6
%62 = getelementptr inbounds i32, i32* %61, i64 13
store i32 0, i32* %62
%63 = load i32*, i32** %6
%64 = getelementptr inbounds i32, i32* %63, i64 14
store i32 0, i32* %64
%65 = load i32*, i32** %6
%66 = getelementptr inbounds i32, i32* %65, i64 15
store i32 0, i32* %66
ret void
}

LLVM IR (-O2):
define void @nios_pkt_32x32_pack(i32* nocapture writeonly %0, i32 %1, i32 %2, i32 %3, i32 %4) {
store i32 75, 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 = ashr i32 %3, 8
%13 = getelementptr inbounds i32, i32* %0, i64 5
store i32 %12, i32* %13
%14 = ashr i32 %3, 16
%15 = getelementptr inbounds i32, i32* %0, i64 6
store i32 %14, i32* %15
%16 = ashr i32 %3, 24
%17 = getelementptr inbounds i32, i32* %0, i64 7
store i32 %16, i32* %17
%18 = getelementptr inbounds i32, i32* %0, i64 8
store i32 %4, i32* %18
%19 = ashr i32 %4, 8
%20 = getelementptr inbounds i32, i32* %0, i64 9
store i32 %19, i32* %20
%21 = ashr i32 %4, 16
%22 = getelementptr inbounds i32, i32* %0, i64 10
store i32 %21, i32* %22
%23 = ashr i32 %4, 24
%24 = getelementptr inbounds i32, i32* %0, i64 11
store i32 %23, i32* %24
%25 = getelementptr inbounds i32, i32* %0, i64 12
%26 = bitcast i32* %25 to i8*
ret void
}