#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*/ perror(char *);
unsigned short smi_phy_read(unsigned short, unsigned short);
unsigned short smi_port_read(unsigned short, unsigned short);
unsigned short do_smi_read(unsigned short phyaddr, unsigned short regnum) {
  if (phyaddr <= 6) {
    return smi_phy_read(phyaddr, regnum);
  } else if (phyaddr < 32) {
    return smi_port_read(phyaddr, regnum);
  } else {
    perror("  ERROR: invalid phyaddr\n");
    return 0xffff;
  }
}


x86 assembly (clang, -O0):
<do_smi_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %si,%ax
mov    %di,%cx
mov    %cx,-0x4(%rbp)
mov    %ax,-0x6(%rbp)
movzwl -0x4(%rbp),%eax
cmp    $0x6,%eax
jg     116c <do_smi_read+0x3c>
mov    -0x4(%rbp),%ax
movzwl %ax,%edi
movzwl -0x6(%rbp),%esi
call   1040 <smi_phy_read@plt>
mov    %ax,-0x2(%rbp)
jmp    11a4 <do_smi_read+0x74>
movzwl -0x4(%rbp),%eax
cmp    $0x20,%eax
jge    1192 <do_smi_read+0x62>
mov    -0x4(%rbp),%ax
movzwl %ax,%edi
movzwl -0x6(%rbp),%esi
call   1030 <smi_port_read@plt>
mov    %ax,-0x2(%rbp)
jmp    11a4 <do_smi_read+0x74>
lea    0xe67(%rip),%rdi
call   1050 <perror@plt>
movw   $0xffff,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_smi_read>:
cmp    $0x6,%di
ja     1141 <do_smi_read+0x11>
movzwl %di,%edi
movzwl %si,%esi
jmp    1040 <smi_phy_read@plt>
cmp    $0x1f,%di
ja     1152 <do_smi_read+0x22>
movzwl %di,%edi
movzwl %si,%esi
jmp    1030 <smi_port_read@plt>
push   %rax
lea    0xea6(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffff,%ax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [26 x i8] c" ERROR: invalid phyaddr\0A\00"
define zeroext i16 @do_smi_read(i16 zeroext %0, i16 zeroext %1) {
%3 = alloca i16
%4 = alloca i16
%5 = alloca i16
store i16 %0, i16* %4
store i16 %1, i16* %5
%6 = load i16, i16* %4
%7 = zext i16 %6 to i32
%8 = icmp sle i32 %7, 6
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i16, i16* %4
%11 = load i16, i16* %5
%12 = call zeroext i16 @smi_phy_read(i16 zeroext %10, i16 zeroext %11)
store i16 %12, i16* %3
br label %23
13: ; preds = %2
%14 = load i16, i16* %4
%15 = zext i16 %14 to i32
%16 = icmp slt i32 %15, 32
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i16, i16* %4
%19 = load i16, i16* %5
%20 = call zeroext i16 @smi_port_read(i16 zeroext %18, i16 zeroext %19)
store i16 %20, i16* %3
br label %23
21: ; preds = %13
%22 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i16 -1, i16* %3
br label %23
23: ; preds = %21, %17, %9
%24 = load i16, i16* %3
ret i16 %24
}

LLVM IR (-O2):
@.str = [26 x i8] c" ERROR: invalid phyaddr\0A\00"
define zeroext i16 @do_smi_read(i16 zeroext %0, i16 zeroext %1) {
%3 = icmp ult i16 %0, 7
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call zeroext i16 @smi_phy_read(i16 zeroext %0, i16 zeroext %1)
br label %12
6: ; preds = %2
%7 = icmp ult i16 %0, 32
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = tail call zeroext i16 @smi_port_read(i16 zeroext %0, i16 zeroext %1)
br label %12
10: ; preds = %6
%11 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %8, %4
%13 = phi i16 [ %5, %4 ], [ %9, %8 ], [ -1, %10 ]
ret i16 %13
}