#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(float *, void const *, int);
float endian_read_float(const void *ptr, int read_le) {
  float ret;
  char r[4];
  const void *p;
  int i;
  if (1 == read_le) {
    p = ptr;
  } else {
    for (i = 0; i < 4; i++) {
      r[i] = ((char *)ptr)[3 - i];
    }
    p = r;
  }
  memcpy(&ret, p, 4);
  return ret;
}


x86 assembly (clang, -O0):
<endian_read_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x1,%eax
cmp    -0xc(%rbp),%eax
jne    113a <endian_read_float+0x2a>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    117b <endian_read_float+0x6b>
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    1173 <endian_read_float+0x63>
mov    -0x8(%rbp),%rax
mov    $0x3,%ecx
sub    -0x24(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x24(%rbp),%rax
mov    %cl,-0x14(%rbp,%rax,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1141 <endian_read_float+0x31>
lea    -0x14(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    -0x10(%rbp),%rdi
mov    $0x4,%edx
call   1030 <memcpy@plt>
movss  -0x10(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<endian_read_float>:
push   %rax
mov    %rdi,%rax
cmp    $0x1,%esi
je     1139 <endian_read_float+0x29>
mov    0x3(%rax),%cl
mov    %cl,(%rsp)
mov    0x2(%rax),%cl
mov    %cl,0x1(%rsp)
mov    0x1(%rax),%cl
mov    %cl,0x2(%rsp)
mov    (%rax),%al
mov    %rsp,%rcx
mov    %al,0x3(%rsp)
mov    %rcx,%rax
lea    0x4(%rsp),%rdi
mov    %rax,%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
movss  0x4(%rsp),%xmm0
pop    %rax
ret

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

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