#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*/ is_little_endian();
void endconv(void *data) {
  char tmp[4];
  tmp[0] = ((char *)data)[0];
  tmp[1] = ((char *)data)[1];
  tmp[2] = ((char *)data)[2];
  tmp[3] = ((char *)data)[3];
  if (!is_little_endian()) {
    ((char *)data)[0] = tmp[3];
    ((char *)data)[1] = tmp[2];
    ((char *)data)[2] = tmp[1];
    ((char *)data)[3] = tmp[0];
  }
}


x86 assembly (clang, -O0):
<endconv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0xb(%rbp)
mov    -0x8(%rbp),%rax
mov    0x2(%rax),%al
mov    %al,-0xa(%rbp)
mov    -0x8(%rbp),%rax
mov    0x3(%rax),%al
mov    %al,-0x9(%rbp)
mov    $0x0,%al
call   1030 <is_little_endian@plt>
cmp    $0x0,%eax
jne    117a <endconv+0x6a>
mov    -0x9(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0xa(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0xb(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0xc(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x3(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<endconv>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%bpl
mov    0x1(%rdi),%r14b
mov    0x2(%rdi),%r15b
mov    0x3(%rdi),%r12b
xor    %eax,%eax
call   1030 <is_little_endian@plt>
test   %eax,%eax
jne    1144 <endconv+0x34>
mov    %r12b,(%rbx)
mov    %r15b,0x1(%rbx)
mov    %r14b,0x2(%rbx)
mov    %bpl,0x3(%rbx)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @endconv(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = getelementptr inbounds i8, i8* %0, i64 1
%4 = load i8, i8* %3
%5 = getelementptr inbounds i8, i8* %0, i64 2
%6 = load i8, i8* %5
%7 = getelementptr inbounds i8, i8* %0, i64 3
%8 = load i8, i8* %7
%9 = tail call i32 (...) @is_little_endian()
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i8 %8, i8* %0
store i8 %6, i8* %3
store i8 %4, i8* %5
store i8 %2, i8* %7
br label %12
12: ; preds = %11, %1
ret void
}