#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 */
scalar_t__ is_bigendian();
void convertDouble(unsigned char *d) {
  unsigned char t;
  int i;
  if (is_bigendian()) {
    for (i = 0; i < 4; i++) {
      t = d[7 - i];
      d[8 - i] = d[i];
      d[i] = t;
    }
  }
}


x86 assembly (clang, -O0):
<convertDouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <is_bigendian@plt>
cmp    $0x0,%rax
je     1191 <convertDouble+0x81>
movl   $0x0,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jge    118c <convertDouble+0x7c>
mov    -0x8(%rbp),%rax
mov    $0x7,%ecx
sub    -0x10(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    $0x8,%ecx
sub    -0x10(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x9(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1134 <convertDouble+0x24>
jmp    1191 <convertDouble+0x81>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convertDouble>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <is_bigendian@plt>
test   %rax,%rax
je     114e <convertDouble+0x3e>
mov    (%rbx),%al
mov    0x1(%rbx),%cl
mov    %al,0x8(%rbx)
movzwl 0x6(%rbx),%eax
rol    $0x8,%ax
mov    %ax,(%rbx)
mov    %cl,0x7(%rbx)
mov    0x2(%rbx),%al
mov    %al,0x6(%rbx)
movzwl 0x4(%rbx),%eax
rol    $0x8,%ax
mov    0x3(%rbx),%cl
mov    %ax,0x2(%rbx)
mov    %cl,0x5(%rbx)
pop    %rbx
ret

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

LLVM IR (-O2):
define void @convertDouble(i8* nocapture %0) {
%2 = tail call i64 (...) @is_bigendian()
%3 = icmp eq i64 %2, 0
br i1 %3, label %21, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 7
%6 = load i8, i8* %5
%7 = load i8, i8* %0
%8 = getelementptr inbounds i8, i8* %0, i64 8
store i8 %7, i8* %8
store i8 %6, i8* %0
%9 = getelementptr inbounds i8, i8* %0, i64 6
%10 = load i8, i8* %9
%11 = getelementptr inbounds i8, i8* %0, i64 1
%12 = load i8, i8* %11
store i8 %12, i8* %5
store i8 %10, i8* %11
%13 = getelementptr inbounds i8, i8* %0, i64 5
%14 = load i8, i8* %13
%15 = getelementptr inbounds i8, i8* %0, i64 2
%16 = load i8, i8* %15
store i8 %16, i8* %9
store i8 %14, i8* %15
%17 = getelementptr inbounds i8, i8* %0, i64 4
%18 = load i8, i8* %17
%19 = getelementptr inbounds i8, i8* %0, i64 3
%20 = load i8, i8* %19
store i8 %20, i8* %13
store i8 %18, i8* %19
br label %21
21: ; preds = %4, %1
ret void
}