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

/* Variables and functions */
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
void int32_to_byte(unsigned int i, unsigned char *bytes) {
  int size = 4;
  memset(bytes, 0, sizeof(unsigned char) * size);
  bytes[0] = (unsigned char)(0xff & i);
  bytes[1] = (unsigned char)((0xff00 & i) >> 8);
  bytes[2] = (unsigned char)((0xff0000 & i) >> 16);
  bytes[3] = (unsigned char)((0xff000000 & i) >> 24);
}


x86 assembly (clang, -O0):
<int32_to_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x4(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x4(%rbp),%eax
and    $0xff00,%eax
shr    $0x8,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x4(%rbp),%eax
and    $0xff0000,%eax
shr    $0x10,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x4(%rbp),%eax
and    $0xff000000,%eax
shr    $0x18,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x3(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int32_to_byte>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    %ebp,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @int32_to_byte(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 4, i32* %5
%6 = load i8*, i8** %4
%7 = load i32, i32* %5
%8 = sext i32 %7 to i64
%9 = mul i64 1, %8
%10 = trunc i64 %9 to i32
%11 = call i32 @memset(i8* %6, i32 0, i32 %10)
%12 = load i32, i32* %3
%13 = and i32 255, %12
%14 = trunc i32 %13 to i8
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 0
store i8 %14, i8* %16
%17 = load i32, i32* %3
%18 = and i32 65280, %17
%19 = lshr i32 %18, 8
%20 = trunc i32 %19 to i8
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8 %20, i8* %22
%23 = load i32, i32* %3
%24 = and i32 16711680, %23
%25 = lshr i32 %24, 16
%26 = trunc i32 %25 to i8
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i64 2
store i8 %26, i8* %28
%29 = load i32, i32* %3
%30 = and i32 -16777216, %29
%31 = lshr i32 %30, 24
%32 = trunc i32 %31 to i8
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i64 3
store i8 %32, i8* %34
ret void
}

LLVM IR (-O2):
define void @int32_to_byte(i32 %0, i8* %1) {
%3 = tail call i32 @memset(i8* %1, i32 0, i32 4)
%4 = trunc i32 %0 to i8
store i8 %4, i8* %1
%5 = lshr i32 %0, 8
%6 = trunc i32 %5 to i8
%7 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %6, i8* %7
%8 = lshr i32 %0, 16
%9 = trunc i32 %8 to i8
%10 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %9, i8* %10
%11 = lshr i32 %0, 24
%12 = trunc i32 %11 to i8
%13 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %12, i8* %13
ret void
}