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

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char *, void *, int);
int marshall_float(float val, char *buf, unsigned int buflen) {
  if (!buf || sizeof(float) != sizeof(u_int32_t)) {
    errno = EINVAL;
    return -1;
  }
  if (buflen >= sizeof(u_int32_t)) {
    u_int32_t temp, *ptr;
    ptr = (u_int32_t *)&val;
    temp = htonl(*ptr);
    memcpy(buf, (void *)&temp, sizeof(u_int32_t));
    return sizeof(u_int32_t);
  }
  return 0;
}


x86 assembly (clang, -O0):
<marshall_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115d <marshall_float+0x3d>
mov    0x2e92(%rip),%rax
mov    (%rax),%ecx
mov    0x2e91(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11a5 <marshall_float+0x85>
mov    -0x14(%rbp),%eax
cmp    $0x4,%rax
jb     119e <marshall_float+0x7e>
lea    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1030 <htonl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
movl   $0x4,-0x4(%rbp)
jmp    11a5 <marshall_float+0x85>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<marshall_float>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     1158 <marshall_float+0x38>
xor    %ebp,%ebp
cmp    $0x4,%esi
jb     116f <marshall_float+0x4f>
mov    %rdi,%rbx
movd   %xmm0,%edi
call   1030 <htonl@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rsi
mov    $0x4,%ebp
mov    %rbx,%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
jmp    116f <marshall_float+0x4f>
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
mov    0x2e78(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
define i32 @marshall_float(float %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca float
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
store float %0, float* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = load i32, i32* @EINVAL
store i32 %13, i32* @errno
store i32 -1, i32* %4
br label %27
14: ; preds = %3
%15 = load i32, i32* %7
%16 = zext i32 %15 to i64
%17 = icmp uge i64 %16, 4
br i1 %17, label %18, label %26
18: ; preds = %14
%19 = bitcast float* %5 to i32*
store i32* %19, i32** %9
%20 = load i32*, i32** %9
%21 = load i32, i32* %20
%22 = call i32 @htonl(i32 %21)
store i32 %22, i32* %8
%23 = load i8*, i8** %6
%24 = bitcast i32* %8 to i8*
%25 = call i32 @memcpy(i8* %23, i8* %24, i32 4)
store i32 4, i32* %4
br label %27
26: ; preds = %14
store i32 0, i32* %4
br label %27
27: ; preds = %26, %18, %12
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
define i32 @marshall_float(float %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = icmp eq i8* %1, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = load i32, i32* @EINVAL
store i32 %7, i32* @errno
br label %15
8: ; preds = %3
%9 = icmp ugt i32 %2, 3
br i1 %9, label %10, label %15
10: ; preds = %8
%11 = bitcast i32* %4 to i8*
%12 = bitcast float %0 to i32
%13 = tail call i32 @htonl(i32 %12)
store i32 %13, i32* %4
%14 = call i32 @memcpy(i8* %1, i8* %11, i32 4)
br label %15
15: ; preds = %8, %10, %6
%16 = phi i32 [ 4, %10 ], [ -1, %6 ], [ 0, %8 ]
ret i32 %16
}