#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 *);
int smi_phy_write(unsigned short, unsigned short, unsigned short);
int smi_port_write(unsigned short, unsigned short, unsigned short);
int do_smi_write(unsigned short phyaddr, unsigned short regnum,
                 unsigned short regvalue) {
  if (phyaddr <= 6) {
    return smi_phy_write(phyaddr, regnum, regvalue);
  } else if (phyaddr < 32) {
    return smi_port_write(phyaddr, regnum, regvalue);
  } else {
    perror("  ERROR: invalid phyaddr\n");
    return -1;
  }
}


x86 assembly (clang, -O0):
<do_smi_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dx,%ax
mov    %si,%cx
mov    %di,%dx
mov    %dx,-0x6(%rbp)
mov    %cx,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
movzwl -0x6(%rbp),%eax
cmp    $0x6,%eax
jg     1179 <do_smi_write+0x49>
mov    -0x6(%rbp),%cx
mov    -0x8(%rbp),%ax
movzwl %cx,%edi
movzwl %ax,%esi
movzwl -0xa(%rbp),%edx
call   1040 <smi_phy_write@plt>
mov    %eax,-0x4(%rbp)
jmp    11b8 <do_smi_write+0x88>
movzwl -0x6(%rbp),%eax
cmp    $0x20,%eax
jge    11a5 <do_smi_write+0x75>
mov    -0x6(%rbp),%cx
mov    -0x8(%rbp),%ax
movzwl %cx,%edi
movzwl %ax,%esi
movzwl -0xa(%rbp),%edx
call   1030 <smi_port_write@plt>
mov    %eax,-0x4(%rbp)
jmp    11b8 <do_smi_write+0x88>
lea    0xe54(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_smi_write>:
cmp    $0x6,%di
ja     1144 <do_smi_write+0x14>
movzwl %di,%edi
movzwl %si,%esi
movzwl %dx,%edx
jmp    1040 <smi_phy_write@plt>
cmp    $0x1f,%di
ja     1158 <do_smi_write+0x28>
movzwl %di,%edi
movzwl %si,%esi
movzwl %dx,%edx
jmp    1030 <smi_port_write@plt>
push   %rax
lea    0xea0(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

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

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