#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 uint32_t;
typedef int uint16_t;

/* Variables and functions */
int mach64_ext_readb(int, void *);
uint16_t mach64_ext_readw(uint32_t addr, void *p) {
  uint16_t ret;
  if (!(addr & 0x400)) {
    ;
    ret = 0xffff;
  } else
    switch (addr & 0x3ff) {
    default:
      ret = mach64_ext_readb(addr, p);
      ret |= mach64_ext_readb(addr + 1, p) << 8;
      break;
    }
  if ((addr & 0x3fc) != 0x018)
    ;
  return ret;
}


x86 assembly (clang, -O0):
<mach64_ext_readw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
and    $0x400,%eax
cmp    $0x0,%eax
jne    113c <mach64_ext_readw+0x2c>
movl   $0xffff,-0x14(%rbp)
jmp    1168 <mach64_ext_readw+0x58>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <mach64_ext_readb@plt>
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
add    $0x1,%edi
mov    -0x10(%rbp),%rsi
call   1030 <mach64_ext_readb@plt>
shl    $0x8,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1168 <mach64_ext_readw+0x58>
mov    -0x4(%rbp),%eax
and    $0x3fc,%eax
cmp    $0x18,%eax
je     117e <mach64_ext_readw+0x6e>
jmp    117e <mach64_ext_readw+0x6e>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mach64_ext_readw>:
mov    $0xffff,%eax
test   $0x400,%edi
je     1145 <mach64_ext_readw+0x35>
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
call   1030 <mach64_ext_readb@plt>
mov    %eax,%r14d
add    $0x1,%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <mach64_ext_readb@plt>
shl    $0x8,%eax
or     %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mach64_ext_readw(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i32, i32* %3
%7 = and i32 %6, 1024
%8 = icmp ne i32 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %2
store i32 65535, i32* %5
br label %25
10: ; preds = %2
%11 = load i32, i32* %3
%12 = and i32 %11, 1023
switch i32 %12, label %13 [
]
13: ; preds = %10
%14 = load i32, i32* %3
%15 = load i8*, i8** %4
%16 = call i32 @mach64_ext_readb(i32 %14, i8* %15)
store i32 %16, i32* %5
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
%19 = load i8*, i8** %4
%20 = call i32 @mach64_ext_readb(i32 %18, i8* %19)
%21 = shl i32 %20, 8
%22 = load i32, i32* %5
%23 = or i32 %22, %21
store i32 %23, i32* %5
br label %24
24: ; preds = %13
br label %25
25: ; preds = %24, %9
%26 = load i32, i32* %3
%27 = and i32 %26, 1020
%28 = icmp ne i32 %27, 24
br i1 %28, label %29, label %30
29: ; preds = %25
br label %30
30: ; preds = %29, %25
%31 = load i32, i32* %5
ret i32 %31
}

LLVM IR (-O2):
define i32 @mach64_ext_readw(i32 %0, i8* %1) {
%3 = and i32 %0, 1024
%4 = icmp eq i32 %3, 0
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = tail call i32 @mach64_ext_readb(i32 %0, i8* %1)
%7 = add nsw i32 %0, 1
%8 = tail call i32 @mach64_ext_readb(i32 %7, i8* %1)
%9 = shl i32 %8, 8
%10 = or i32 %9, %6
br label %11
11: ; preds = %2, %5
%12 = phi i32 [ %10, %5 ], [ 65535, %2 ]
ret i32 %12
}