#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 u_int8_t;
typedef int u_int32_t;
typedef int /*<<< orphan*/ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ write(int, int *, int);
ssize_t be_write32(int fd, u_int32_t word) {
  u_int8_t buf[4];
  buf[3] = word & 0xff;
  buf[2] = (word & 0xff00) >> 8;
  buf[1] = (word & 0xff0000) >> 16;
  buf[0] = (word & 0xff000000) >> 24;
  return write(fd, buf, 4);
}


x86 assembly (clang, -O0):
<be_write32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
and    $0xff0000,%eax
sar    $0x10,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
and    $0xff000000,%eax
shr    $0x18,%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<be_write32>:
sub    $0x18,%rsp
mov    %esi,%eax
movzbl %al,%ecx
mov    %ecx,0xc(%rsp)
movzbl %ah,%ecx
mov    %ecx,0x8(%rsp)
mov    %esi,%ecx
shr    $0x10,%ecx
movzbl %cl,%ecx
mov    %ecx,0x4(%rsp)
shr    $0x18,%eax
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
define i32 @be_write32(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [4 x i32]
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = and i32 %6, 255
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 3
store i32 %7, i32* %8
%9 = load i32, i32* %4
%10 = and i32 %9, 65280
%11 = ashr i32 %10, 8
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 2
store i32 %11, i32* %12
%13 = load i32, i32* %4
%14 = and i32 %13, 16711680
%15 = ashr i32 %14, 16
%16 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 1
store i32 %15, i32* %16
%17 = load i32, i32* %4
%18 = and i32 %17, -16777216
%19 = lshr i32 %18, 24
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
store i32 %19, i32* %20
%21 = load i32, i32* %3
%22 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
%23 = call i32 @write(i32 %21, i32* %22, i32 4)
ret i32 %23
}

LLVM IR (-O2):
define i32 @be_write32(i32 %0, i32 %1) {
%3 = alloca [4 x i32]
%4 = bitcast [4 x i32]* %3 to i8*
%5 = and i32 %1, 255
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
store i32 %5, i32* %6
%7 = lshr i32 %1, 8
%8 = and i32 %7, 255
%9 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
store i32 %8, i32* %9
%10 = lshr i32 %1, 16
%11 = and i32 %10, 255
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
store i32 %11, i32* %12
%13 = lshr i32 %1, 24
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
store i32 %13, i32* %14
%15 = call i32 @write(i32 %0, i32* %14, i32 4)
ret i32 %15
}