#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*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ *HadTu_hdr(void const *);
scalar_t__ HadTu_isSwapped(void const *);
uint32_t HadTu_hdrValue(const void *my, unsigned idx) {
  uint32_t *hdr = HadTu_hdr(my);
  if (HadTu_isSwapped(my)) {
    uint32_t tmp0;
    uint32_t tmp1;
    tmp0 = hdr[idx];
    ((char *)&tmp1)[0] = ((char *)&tmp0)[3];
    ((char *)&tmp1)[1] = ((char *)&tmp0)[2];
    ((char *)&tmp1)[2] = ((char *)&tmp0)[1];
    ((char *)&tmp1)[3] = ((char *)&tmp0)[0];
    return tmp1;
  } else {
    return hdr[idx];
  }
}


x86 assembly (clang, -O0):
<HadTu_hdrValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <HadTu_hdr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <HadTu_isSwapped@plt>
cmp    $0x0,%rax
je     117f <HadTu_hdrValue+0x5f>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x24(%rbp)
mov    -0x21(%rbp),%al
mov    %al,-0x28(%rbp)
mov    -0x22(%rbp),%al
mov    %al,-0x27(%rbp)
mov    -0x23(%rbp),%al
mov    %al,-0x26(%rbp)
mov    -0x24(%rbp),%al
mov    %al,-0x25(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118c <HadTu_hdrValue+0x6c>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HadTu_hdrValue>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
call   1030 <HadTu_hdr@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <HadTu_isSwapped@plt>
test   %rax,%rax
mov    %r14d,%eax
mov    0x0(%rbp,%rax,4),%ecx
mov    %ecx,%eax
bswap  %eax
cmove  %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @HadTu_hdrValue(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i8*, i8** %4
%10 = call i32* @HadTu_hdr(i8* %9)
store i32* %10, i32** %6
%11 = load i8*, i8** %4
%12 = call i64 @HadTu_isSwapped(i8* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %41
14: ; preds = %2
%15 = load i32*, i32** %6
%16 = load i32, i32* %5
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
store i32 %19, i32* %7
%20 = bitcast i32* %7 to i8*
%21 = getelementptr inbounds i8, i8* %20, i64 3
%22 = load i8, i8* %21
%23 = bitcast i32* %8 to i8*
%24 = getelementptr inbounds i8, i8* %23, i64 0
store i8 %22, i8* %24
%25 = bitcast i32* %7 to i8*
%26 = getelementptr inbounds i8, i8* %25, i64 2
%27 = load i8, i8* %26
%28 = bitcast i32* %8 to i8*
%29 = getelementptr inbounds i8, i8* %28, i64 1
store i8 %27, i8* %29
%30 = bitcast i32* %7 to i8*
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = load i8, i8* %31
%33 = bitcast i32* %8 to i8*
%34 = getelementptr inbounds i8, i8* %33, i64 2
store i8 %32, i8* %34
%35 = bitcast i32* %7 to i8*
%36 = getelementptr inbounds i8, i8* %35, i64 0
%37 = load i8, i8* %36
%38 = bitcast i32* %8 to i8*
%39 = getelementptr inbounds i8, i8* %38, i64 3
store i8 %37, i8* %39
%40 = load i32, i32* %8
store i32 %40, i32* %3
br label %47
41: ; preds = %2
%42 = load i32*, i32** %6
%43 = load i32, i32* %5
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
%46 = load i32, i32* %45
store i32 %46, i32* %3
br label %47
47: ; preds = %41, %14
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
define i32 @HadTu_hdrValue(i8* %0, i32 %1) {
%3 = tail call i32* @HadTu_hdr(i8* %0)
%4 = tail call i64 @HadTu_isSwapped(i8* %0)
%5 = icmp eq i64 %4, 0
%6 = zext i32 %1 to i64
%7 = getelementptr inbounds i32, i32* %3, i64 %6
%8 = load i32, i32* %7
%9 = tail call i32 @llvm.bswap.i32(i32 %8)
%10 = select i1 %5, i32 %8, i32 %9
ret i32 %10
}