#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 mathbuf_set(uint8_t buf[], uint8_t size, uint32_t value) {
  uint8_t i;
  for (i = 0; i < size - 4; i++)
    buf[i] = 0;
  buf[size - 1] = value & 0xff;
  buf[size - 2] = (value >> 8) & 0xff;
  buf[size - 3] = (value >> 16) & 0xff;
  buf[size - 4] = (value >> 24) & 0xff;
}


x86 assembly (clang, -O0):
<mathbuf_set>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x4,%ecx
cmp    %ecx,%eax
jge    1143 <mathbuf_set+0x43>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1115 <mathbuf_set+0x15>
mov    -0x10(%rbp),%edx
and    $0xff,%edx
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%edx
sar    $0x8,%edx
and    $0xff,%edx
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%edx
sar    $0x10,%edx
and    $0xff,%edx
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x3,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%edx
sar    $0x18,%edx
and    $0xff,%edx
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x4,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
pop    %rbp
ret

x86 assembly (clang, -O2):
<mathbuf_set>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%r15d
mov    %rdi,%r14
lea    -0x4(%r15),%ebp
cmp    $0x5,%esi
jl     1138 <mathbuf_set+0x28>
mov    %ebp,%edx
shl    $0x2,%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
movzbl %bl,%eax
movslq %r15d,%rcx
mov    %eax,-0x4(%r14,%rcx,4)
movzbl %bh,%eax
mov    %eax,-0x8(%r14,%rcx,4)
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%eax
mov    %eax,-0xc(%r14,%rcx,4)
shr    $0x18,%ebx
movslq %ebp,%rax
mov    %ebx,(%r14,%rax,4)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @mathbuf_set(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %18, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %5
%11 = sub nsw i32 %10, 4
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %21
13: ; preds = %8
%14 = load i32*, i32** %4
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %14, i64 %16
store i32 0, i32* %17
br label %18
18: ; preds = %13
%19 = load i32, i32* %7
%20 = add nsw i32 %19, 1
store i32 %20, i32* %7
br label %8
21: ; preds = %8
%22 = load i32, i32* %6
%23 = and i32 %22, 255
%24 = load i32*, i32** %4
%25 = load i32, i32* %5
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %24, i64 %27
store i32 %23, i32* %28
%29 = load i32, i32* %6
%30 = ashr i32 %29, 8
%31 = and i32 %30, 255
%32 = load i32*, i32** %4
%33 = load i32, i32* %5
%34 = sub nsw i32 %33, 2
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %32, i64 %35
store i32 %31, i32* %36
%37 = load i32, i32* %6
%38 = ashr i32 %37, 16
%39 = and i32 %38, 255
%40 = load i32*, i32** %4
%41 = load i32, i32* %5
%42 = sub nsw i32 %41, 3
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %40, i64 %43
store i32 %39, i32* %44
%45 = load i32, i32* %6
%46 = ashr i32 %45, 24
%47 = and i32 %46, 255
%48 = load i32*, i32** %4
%49 = load i32, i32* %5
%50 = sub nsw i32 %49, 4
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %48, i64 %51
store i32 %47, i32* %52
ret void
}

LLVM IR (-O2):
define void @mathbuf_set(i32* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = add i32 %1, -4
%5 = icmp sgt i32 %1, 4
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = bitcast i32* %0 to i8*
%8 = zext i32 %4 to i64
%9 = shl nuw nsw i64 %8, 2
br label %10
10: ; preds = %6, %3
%11 = and i32 %2, 255
%12 = add nsw i32 %1, -1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %0, i64 %13
store i32 %11, i32* %14
%15 = lshr i32 %2, 8
%16 = and i32 %15, 255
%17 = add nsw i32 %1, -2
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %0, i64 %18
store i32 %16, i32* %19
%20 = lshr i32 %2, 16
%21 = and i32 %20, 255
%22 = add nsw i32 %1, -3
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %0, i64 %23
store i32 %21, i32* %24
%25 = lshr i32 %2, 24
%26 = sext i32 %4 to i64
%27 = getelementptr inbounds i32, i32* %0, i64 %26
store i32 %25, i32* %27
ret void
}