#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*/ memcpy(void *, float *, int);
void endian_write_float(void *ptr, float f, int write_le) {
  char *r = (char *)(void *)&f;
  int i;
  char *optr = (char *)ptr;
  if (1 == write_le) {
    memcpy(ptr, &f, 4);
  } else {
    for (i = 0; i < 4; i++) {
      *optr++ = r[3 - i];
    }
  }
}


x86 assembly (clang, -O0):
<endian_write_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
lea    -0xc(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x1,%eax
cmp    -0x10(%rbp),%eax
jne    1159 <endian_write_float+0x49>
mov    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
jmp    11a0 <endian_write_float+0x90>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    119b <endian_write_float+0x8b>
mov    -0x18(%rbp),%rax
mov    $0x3,%ecx
sub    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1160 <endian_write_float+0x50>
jmp    11a0 <endian_write_float+0x90>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<endian_write_float>:
push   %rax
movd   %xmm0,0x4(%rsp)
cmp    $0x1,%esi
jne    112d <endian_write_float+0x1d>
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
pop    %rax
ret
movd   %xmm0,%eax
bswap  %eax
mov    %eax,(%rdi)
pop    %rax
ret

LLVM IR (-O0):
define void @endian_write_float(i8* %0, float %1, i32 %2) {
%4 = alloca i8*
%5 = alloca float
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %4
store float %1, float* %5
store i32 %2, i32* %6
%10 = bitcast float* %5 to i8*
store i8* %10, i8** %7
%11 = load i8*, i8** %4
store i8* %11, i8** %9
%12 = load i32, i32* %6
%13 = icmp eq i32 1, %12
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i8*, i8** %4
%16 = call i32 @memcpy(i8* %15, float* %5, i32 4)
br label %34
17: ; preds = %3
store i32 0, i32* %8
br label %18
18: ; preds = %30, %17
%19 = load i32, i32* %8
%20 = icmp slt i32 %19, 4
br i1 %20, label %21, label %33
21: ; preds = %18
%22 = load i8*, i8** %7
%23 = load i32, i32* %8
%24 = sub nsw i32 3, %23
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
%27 = load i8, i8* %26
%28 = load i8*, i8** %9
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %9
store i8 %27, i8* %28
br label %30
30: ; preds = %21
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %18
33: ; preds = %18
br label %34
34: ; preds = %33, %14
ret void
}

LLVM IR (-O2):
define void @endian_write_float(i8* %0, float %1, i32 %2) {
%4 = alloca float
store float %1, float* %4
%5 = icmp eq i32 %2, 1
%6 = bitcast float %1 to i32
br i1 %5, label %18, label %7
7: ; preds = %3
%8 = trunc i32 %6 to i8
%9 = lshr i32 %6, 8
%10 = trunc i32 %9 to i8
%11 = lshr i32 %6, 16
%12 = trunc i32 %11 to i8
%13 = lshr i32 %6, 24
%14 = trunc i32 %13 to i8
%15 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %14, i8* %0
%16 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %12, i8* %15
%17 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %10, i8* %16
store i8 %8, i8* %17
br label %20
18: ; preds = %3
%19 = call i32 @memcpy(i8* %0, float* %4, i32 4)
br label %20
20: ; preds = %7, %18
ret void
}