#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*/ memcpy(void *, char const *, int);
int /*<<< orphan*/ ntohl(int /*<<< orphan*/);
int unmarshall_float(float *val, const char *buf, unsigned int buflen) {
  if (!val || !buf || sizeof(float) != sizeof(u_int32_t)) {
    errno = EINVAL;
    return -1;
  }
  if (buflen >= sizeof(u_int32_t)) {
    u_int32_t temp;
    u_int32_t *ptr = (u_int32_t *)val;
    memcpy((void *)&temp, buf, sizeof(u_int32_t));
    *ptr = ntohl(temp);
    return sizeof(u_int32_t);
  }
  return 0;
}


x86 assembly (clang, -O0):
<unmarshall_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1149 <unmarshall_float+0x29>
cmpq   $0x0,-0x18(%rbp)
jne    1167 <unmarshall_float+0x47>
mov    0x2e88(%rip),%rax
mov    (%rax),%ecx
mov    0x2e87(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <unmarshall_float+0x91>
mov    -0x1c(%rbp),%eax
cmp    $0x4,%rax
jb     11aa <unmarshall_float+0x8a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%edi
call   1040 <ntohl@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x4,-0x4(%rbp)
jmp    11b1 <unmarshall_float+0x91>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unmarshall_float>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     1158 <unmarshall_float+0x38>
test   %rsi,%rsi
je     1158 <unmarshall_float+0x38>
xor    %ebp,%ebp
cmp    $0x4,%edx
jb     116f <unmarshall_float+0x4f>
mov    %rdi,%rbx
lea    0x4(%rsp),%rdi
mov    $0x4,%ebp
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    0x4(%rsp),%edi
call   1040 <ntohl@plt>
mov    %eax,(%rbx)
jmp    116f <unmarshall_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 @unmarshall_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 float*, float** %5
%11 = icmp ne float* %10, null
br i1 %11, label %12, label %15
12: ; preds = %3
%13 = load i8*, i8** %6
%14 = icmp ne i8* %13, null
br i1 %14, label %17, label %15
15: ; preds = %12, %3
%16 = load i32, i32* @EINVAL
store i32 %16, i32* @errno
store i32 -1, i32* %4
br label %31
17: ; preds = %12
%18 = load i32, i32* %7
%19 = zext i32 %18 to i64
%20 = icmp uge i64 %19, 4
br i1 %20, label %21, label %30
21: ; preds = %17
%22 = load float*, float** %5
%23 = bitcast float* %22 to i32*
store i32* %23, i32** %9
%24 = bitcast i32* %8 to i8*
%25 = load i8*, i8** %6
%26 = call i32 @memcpy(i8* %24, i8* %25, i32 4)
%27 = load i32, i32* %8
%28 = call i32 @ntohl(i32 %27)
%29 = load i32*, i32** %9
store i32 %28, i32* %29
store i32 4, i32* %4
br label %31
30: ; preds = %17
store i32 0, i32* %4
br label %31
31: ; preds = %30, %21, %15
%32 = load i32, i32* %4
ret i32 %32
}

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