#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 */
struct lowl_pci_handle {
  int dummy;
};
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
void *lowl_pci_get_data(struct lowl_pci_handle *const, void *const,
                        size_t const, int const, int /*<<< orphan*/ const);
int /*<<< orphan*/ memmove(void *const, void const *const, size_t const);
bool lowl_pci_read_data(struct lowl_pci_handle *const lph, void *const buf,
                        const size_t sz, const int bar, const off_t offset) {
  const void *const p = lowl_pci_get_data(lph, buf, sz, bar, offset);
  if (!p)
    return false;
  if (buf != p)
    memmove(buf, p, sz);
  return true;
}


x86 assembly (clang, -O0):
<lowl_pci_read_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
call   1030 <lowl_pci_get_data@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    116e <lowl_pci_read_data+0x4e>
movl   $0x0,-0x4(%rbp)
jmp    1194 <lowl_pci_read_data+0x74>
mov    -0x18(%rbp),%rax
cmp    -0x30(%rbp),%rax
je     118d <lowl_pci_read_data+0x6d>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memmove@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lowl_pci_read_data>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
call   1030 <lowl_pci_get_data@plt>
test   %rax,%rax
je     114e <lowl_pci_read_data+0x2e>
mov    $0x1,%ebp
cmp    %rbx,%rax
je     1150 <lowl_pci_read_data+0x30>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r14,%rdx
call   1040 <memmove@plt>
jmp    1150 <lowl_pci_read_data+0x30>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.lowl_pci_handle = type { i32 }
define i32 @lowl_pci_read_data(%struct.lowl_pci_handle* %0, i8* %1, i64 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca %struct.lowl_pci_handle*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
store %struct.lowl_pci_handle* %0, %struct.lowl_pci_handle** %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%13 = load %struct.lowl_pci_handle*, %struct.lowl_pci_handle** %7
%14 = load i8*, i8** %8
%15 = load i64, i64* %9
%16 = load i32, i32* %10
%17 = load i32, i32* %11
%18 = call i8* @lowl_pci_get_data(%struct.lowl_pci_handle* %13, i8* %14, i64 %15, i32 %16, i32 %17)
store i8* %18, i8** %12
%19 = load i8*, i8** %12
%20 = icmp ne i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %5
store i32 0, i32* %6
br label %32
22: ; preds = %5
%23 = load i8*, i8** %8
%24 = load i8*, i8** %12
%25 = icmp ne i8* %23, %24
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i8*, i8** %8
%28 = load i8*, i8** %12
%29 = load i64, i64* %9
%30 = call i32 @memmove(i8* %27, i8* %28, i64 %29)
br label %31
31: ; preds = %26, %22
store i32 1, i32* %6
br label %32
32: ; preds = %31, %21
%33 = load i32, i32* %6
ret i32 %33
}

LLVM IR (-O2):
%struct.lowl_pci_handle = type { i32 }
define i32 @lowl_pci_read_data(%struct.lowl_pci_handle* %0, i8* %1, i64 %2, i32 %3, i32 %4) {
%6 = tail call i8* @lowl_pci_get_data(%struct.lowl_pci_handle* %0, i8* %1, i64 %2, i32 %3, i32 %4)
%7 = icmp eq i8* %6, null
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = icmp eq i8* %6, %1
br i1 %9, label %12, label %10
10: ; preds = %8
%11 = tail call i32 @memmove(i8* %1, i8* %6, i64 %2)
br label %12
12: ; preds = %8, %10, %5
%13 = phi i32 [ 0, %5 ], [ 1, %10 ], [ 1, %8 ]
ret i32 %13
}