#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*/ uint64_t;
typedef void *uint32_t;
struct ullc {
  int /*<<< orphan*/ ull;
  void **ul;
};

/* Variables and functions */
void *_OSSwapInt32(void *);
uint64_t OSReadSwapInt64(volatile void *base, uintptr_t offset) {
  uint32_t *inp;
  union ullc {
    uint64_t ull;
    uint32_t ul[2];
  } outv;
  inp = (uint32_t *)((uintptr_t)base + offset);
  outv.ul[0] = inp[1];
  outv.ul[1] = inp[0];
  outv.ul[0] = _OSSwapInt32(outv.ul[0]);
  outv.ul[1] = _OSSwapInt32(outv.ul[1]);
  return outv.ull;
}


x86 assembly (clang, -O0):
<OSReadSwapInt64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <_OSSwapInt32@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <_OSSwapInt32@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OSReadSwapInt64>:
push   %r14
push   %rbx
push   %rax
mov    (%rdi,%rsi,1),%r14
mov    0x8(%rdi,%rsi,1),%rdi
call   1030 <_OSSwapInt32@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <_OSSwapInt32@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%union.ullc = type { [2 x i8*] }
define i32 @OSReadSwapInt64(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8**
%6 = alloca %union.ullc
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = load i8*, i8** %3
%8 = ptrtoint i8* %7 to i64
%9 = load i64, i64* %4
%10 = add i64 %8, %9
%11 = inttoptr i64 %10 to i8**
store i8** %11, i8*** %5
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = bitcast %union.ullc* %6 to [2 x i8*]*
%16 = getelementptr inbounds [2 x i8*], [2 x i8*]* %15, i64 0, i64 0
store i8* %14, i8** %16
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = bitcast %union.ullc* %6 to [2 x i8*]*
%21 = getelementptr inbounds [2 x i8*], [2 x i8*]* %20, i64 0, i64 1
store i8* %19, i8** %21
%22 = bitcast %union.ullc* %6 to [2 x i8*]*
%23 = getelementptr inbounds [2 x i8*], [2 x i8*]* %22, i64 0, i64 0
%24 = load i8*, i8** %23
%25 = call i8* @_OSSwapInt32(i8* %24)
%26 = bitcast %union.ullc* %6 to [2 x i8*]*
%27 = getelementptr inbounds [2 x i8*], [2 x i8*]* %26, i64 0, i64 0
store i8* %25, i8** %27
%28 = bitcast %union.ullc* %6 to [2 x i8*]*
%29 = getelementptr inbounds [2 x i8*], [2 x i8*]* %28, i64 0, i64 1
%30 = load i8*, i8** %29
%31 = call i8* @_OSSwapInt32(i8* %30)
%32 = bitcast %union.ullc* %6 to [2 x i8*]*
%33 = getelementptr inbounds [2 x i8*], [2 x i8*]* %32, i64 0, i64 1
store i8* %31, i8** %33
%34 = bitcast %union.ullc* %6 to i32*
%35 = load i32, i32* %34
ret i32 %35
}

LLVM IR (-O2):
define i32 @OSReadSwapInt64(i8* %0, i64 %1) {
%3 = ptrtoint i8* %0 to i64
%4 = add i64 %3, %1
%5 = inttoptr i64 %4 to i8**
%6 = getelementptr inbounds i8*, i8** %5, i64 1
%7 = load i8*, i8** %6
%8 = load i8*, i8** %5
%9 = tail call i8* @_OSSwapInt32(i8* %7)
%10 = tail call i8* @_OSSwapInt32(i8* %8)
%11 = ptrtoint i8* %9 to i64
%12 = trunc i64 %11 to i32
ret i32 %12
}