#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fwrite(unsigned char *, size_t, size_t,
                          int /*<<< orphan*/ *);
void src_int4_write(FILE *fd, int val) {
  unsigned char b[4];
  b[3] = val & 255;
  b[2] = (val = val >> 8) & 255;
  b[1] = (val = val >> 8) & 255;
  b[0] = (val = val >> 8) & 255;
  fwrite(b, (size_t)1, (size_t)4, fd);
}


x86 assembly (clang, -O0):
<src_int4_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %al,-0xd(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0xc(%rbp)
and    $0xff,%eax
mov    %al,-0xe(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0xc(%rbp)
and    $0xff,%eax
mov    %al,-0xf(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0xc(%rbp)
and    $0xff,%eax
mov    %al,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fwrite@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<src_int4_write>:
push   %rax
mov    %rdi,%rcx
bswap  %esi
mov    %esi,0x4(%rsp)
lea    0x4(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fwrite@plt>
pop    %rax
ret

LLVM IR (-O0):
define void @src_int4_write(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [4 x i8]
store i32* %0, i32** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = and i32 %6, 255
%8 = trunc i32 %7 to i8
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 3
store i8 %8, i8* %9
%10 = load i32, i32* %4
%11 = ashr i32 %10, 8
store i32 %11, i32* %4
%12 = and i32 %11, 255
%13 = trunc i32 %12 to i8
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 2
store i8 %13, i8* %14
%15 = load i32, i32* %4
%16 = ashr i32 %15, 8
store i32 %16, i32* %4
%17 = and i32 %16, 255
%18 = trunc i32 %17 to i8
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 1
store i8 %18, i8* %19
%20 = load i32, i32* %4
%21 = ashr i32 %20, 8
store i32 %21, i32* %4
%22 = and i32 %21, 255
%23 = trunc i32 %22 to i8
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
store i8 %23, i8* %24
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%26 = load i32*, i32** %3
%27 = call i32 @fwrite(i8* %25, i64 1, i64 4, i32* %26)
ret void
}

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