#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int uint8_t;
struct ipmi_system_interface_addr {
  scalar_t__ lun;
  int /*<<< orphan*/ channel;
  int /*<<< orphan*/ addr_type;
};
struct TYPE_3__ {
  int netfn;
  int cmd;
  int data_len;
  void *data;
};
struct ipmi_req {
  int addr_len;
  int msgid;
  TYPE_1__ msg;
  void *addr;
};
struct TYPE_4__ {
  int *data;
  int data_len;
};
struct ipmi_recv {
  int addr_len;
  TYPE_2__ msg;
  void *addr;
};
struct ipmi_ipmb_addr {
  int slave_addr;
  int lun;
  scalar_t__ channel;
  int /*<<< orphan*/ addr_type;
};
struct ipmi_addr {
  int dummy;
};
typedef int /*<<< orphan*/ saddr;
typedef int /*<<< orphan*/ raddr;
typedef int /*<<< orphan*/ iaddr;
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
scalar_t__ EMSGSIZE;
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ IPMICTL_RECEIVE_MSG_TRUNC;
int /*<<< orphan*/ IPMICTL_SEND_COMMAND;
int /*<<< orphan*/ IPMI_BMC_CHANNEL;
int /*<<< orphan*/ IPMI_IPMB_ADDR_TYPE;
int /*<<< orphan*/ IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int ioctl(int, int /*<<< orphan*/, void *);
int /*<<< orphan*/ memcpy(void *, int *, int);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int ipmicmd(int sa, int lun, int netfn, int cmd, int datalen, void *data,
            int resplen, int *rlen, void *resp) {
  static int msgid;
  struct ipmi_system_interface_addr saddr;
  struct ipmi_ipmb_addr iaddr;
  struct ipmi_addr raddr;
  struct ipmi_req req;
  struct ipmi_recv rcv;
  fd_set rfd;
  int fd, rc;
  uint8_t tresp[resplen + 1];
  memset(resp, 0, resplen);
  fd = open("/dev/ipmi0", O_RDONLY);
  if (fd < 0)
    return -1;
  if (sa == 0x20) {
    saddr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
    saddr.channel = IPMI_BMC_CHANNEL;
    saddr.lun = 0;
    req.addr = (void *)&saddr;
    req.addr_len = sizeof(saddr);
  } else {
    iaddr.addr_type = IPMI_IPMB_ADDR_TYPE;
    iaddr.channel = 0;
    iaddr.slave_addr = sa;
    iaddr.lun = lun;
    req.addr = (void *)&iaddr;
    req.addr_len = sizeof(iaddr);
  }
  req.msgid = ++msgid;
  req.msg.netfn = netfn;
  req.msg.cmd = cmd;
  req.msg.data_len = datalen;
  req.msg.data = data;
  rc = ioctl(fd, IPMICTL_SEND_COMMAND, (void *)&req);
  if (rc != 0) {
    perror("send");
    goto end;
  }
  FD_ZERO(&rfd);
  FD_SET(fd, &rfd);
  rc = select(fd + 1, &rfd, NULL, NULL, NULL);
  if (rc < 0) {
    perror("select");
    goto end;
  }
  rcv.msg.data = tresp;
  rcv.msg.data_len = resplen + 1;
  rcv.addr = (void *)&raddr;
  rcv.addr_len = sizeof(raddr);
  rc = ioctl(fd, IPMICTL_RECEIVE_MSG_TRUNC, (void *)&rcv);
  if (rc != 0 && errno != EMSGSIZE) {
    perror("recv");
    goto end;
  }
  rc = rcv.msg.data[0];
  if (rc != 0) {
    rc = rcv.msg.data[0];
  } else {
    *rlen = rcv.msg.data_len - 1;
    memcpy(resp, rcv.msg.data + 1, *rlen);
  }
end:
  close(fd);
  return rc;
}


x86 assembly (clang, -O0):
<ipmicmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9,-0x20(%rbp)
mov    0x10(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0xb0(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xc8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0xb8(%rbp)
mov    0x20(%rbp),%rdi
mov    0x10(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
lea    0xdf5(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0xa0(%rbp)
cmpl   $0x0,-0xa0(%rbp)
jge    1239 <ipmicmd+0xa9>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0xbc(%rbp)
jmp    1471 <ipmicmd+0x2e1>
cmpl   $0x20,-0x8(%rbp)
jne    1277 <ipmicmd+0xe7>
mov    0x2d6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
movl   $0x10,-0x78(%rbp)
jmp    12a6 <ipmicmd+0x116>
mov    0x2d4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x44(%rbp)
lea    -0x48(%rbp),%rax
mov    %rax,-0x58(%rbp)
movl   $0x18,-0x78(%rbp)
mov    0x2dc4(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2dbb(%rip)
mov    %eax,-0x74(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0xa0(%rbp),%edi
mov    0x2cc9(%rip),%rax
mov    (%rax),%esi
lea    -0x78(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0x0,-0xa4(%rbp)
je     130e <ipmicmd+0x17e>
lea    0xd07(%rip),%rdi
call   10a0 <perror@plt>
jmp    1453 <ipmicmd+0x2c3>
lea    -0x9c(%rbp),%rdi
call   1070 <FD_ZERO@plt>
mov    -0xa0(%rbp),%edi
lea    -0x9c(%rbp),%rsi
call   10b0 <FD_SET@plt>
mov    -0xa0(%rbp),%edi
add    $0x1,%edi
lea    -0x9c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1080 <select@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0x0,-0xa4(%rbp)
jge    1370 <ipmicmd+0x1e0>
lea    0xcaa(%rip),%rdi
call   10a0 <perror@plt>
jmp    1453 <ipmicmd+0x2c3>
mov    -0xc8(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x80(%rbp)
movl   $0x4,-0x98(%rbp)
mov    -0xa0(%rbp),%edi
mov    0x2c4f(%rip),%rax
mov    (%rax),%esi
lea    -0x98(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0x0,-0xa4(%rbp)
je     13f5 <ipmicmd+0x265>
mov    0x2bdf(%rip),%rax
mov    (%rax),%rax
mov    0x2bfd(%rip),%rcx
cmp    (%rcx),%rax
je     13f5 <ipmicmd+0x265>
lea    0xc2c(%rip),%rdi
call   10a0 <perror@plt>
jmp    1453 <ipmicmd+0x2c3>
mov    -0x90(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xa4(%rbp)
cmpl   $0x0,-0xa4(%rbp)
je     1425 <ipmicmd+0x295>
mov    -0x90(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xa4(%rbp)
jmp    144e <ipmicmd+0x2be>
mov    -0x88(%rbp),%ecx
sub    $0x1,%ecx
mov    0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    0x20(%rbp),%rdi
mov    -0x90(%rbp),%rsi
add    $0x4,%rsi
mov    0x18(%rbp),%rax
mov    (%rax),%edx
call   1060 <memcpy@plt>
jmp    1453 <ipmicmd+0x2c3>
mov    -0xa0(%rbp),%edi
call   1050 <close@plt>
mov    -0xa4(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0xbc(%rbp)
mov    -0xb0(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipmicmd>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %r9,-0x48(%rbp)
mov    %r8d,-0x3c(%rbp)
mov    %ecx,-0x38(%rbp)
mov    %edx,-0x34(%rbp)
mov    %esi,%ebx
mov    %edi,%r12d
mov    %rsp,-0x30(%rbp)
mov    0x20(%rbp),%rdi
mov    0x10(%rbp),%edx
lea    0x1(%rdx),%r13d
mov    %rsp,%r14
lea    0xf(,%r13,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
xor    %esi,%esi
call   1030 <memset@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
lea    0xe0e(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1233 <ipmicmd+0xa3>
mov    %eax,%r15d
cmp    $0x20,%r12d
jne    1241 <ipmicmd+0xb1>
mov    0x2dad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    0x2dc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    $0x10,%eax
jmp    1269 <ipmicmd+0xd9>
mov    $0xffffffff,%ebx
mov    -0x30(%rbp),%r14
jmp    13b1 <ipmicmd+0x221>
mov    0x2d80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
mov    %r12d,-0x60(%rbp)
mov    %ebx,-0x5c(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    $0x18,%eax
mov    -0x48(%rbp),%rcx
mov    -0x3c(%rbp),%edx
mov    -0x38(%rbp),%esi
mov    -0x34(%rbp),%edi
mov    %eax,-0x98(%rbp)
mov    0x2dee(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2de5(%rip)
mov    %eax,-0x94(%rbp)
mov    %edi,-0x90(%rbp)
mov    %esi,-0x8c(%rbp)
mov    %edx,-0x88(%rbp)
mov    %rcx,-0x80(%rbp)
mov    0x2cfa(%rip),%rax
mov    (%rax),%esi
lea    -0x98(%rbp),%rdx
mov    %r15d,%edi
call   1040 <ioctl@plt>
test   %eax,%eax
jne    1383 <ipmicmd+0x1f3>
lea    -0x6c(%rbp),%rbx
mov    %rbx,%rdi
call   1070 <FD_ZERO@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   10b0 <FD_SET@plt>
mov    %r15d,%edi
add    $0x1,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1080 <select@plt>
test   %eax,%eax
js     138e <ipmicmd+0x1fe>
mov    %r14,-0xb0(%rbp)
mov    %r13d,-0xa8(%rbp)
lea    -0x68(%rbp),%rax
mov    %rax,-0xa0(%rbp)
movl   $0x4,-0xb8(%rbp)
mov    0x2cd3(%rip),%rax
mov    (%rax),%esi
lea    -0xb8(%rbp),%rdx
mov    %r15d,%edi
call   1040 <ioctl@plt>
test   %eax,%eax
je     1352 <ipmicmd+0x1c2>
mov    %eax,%ebx
mov    0x2c6d(%rip),%rax
mov    (%rax),%rax
mov    0x2c8b(%rip),%rcx
cmp    (%rcx),%rax
jne    1399 <ipmicmd+0x209>
mov    -0xb0(%rbp),%rsi
mov    (%rsi),%ebx
test   %ebx,%ebx
mov    -0x30(%rbp),%r14
jne    13a9 <ipmicmd+0x219>
mov    0x18(%rbp),%rax
mov    -0xa8(%rbp),%edx
add    $0xffffffff,%edx
mov    %edx,(%rax)
add    $0x4,%rsi
mov    0x20(%rbp),%rdi
call   1060 <memcpy@plt>
xor    %ebx,%ebx
jmp    13a9 <ipmicmd+0x219>
mov    %eax,%ebx
lea    0xc7f(%rip),%rdi
jmp    13a0 <ipmicmd+0x210>
mov    %eax,%ebx
lea    0xc79(%rip),%rdi
jmp    13a0 <ipmicmd+0x210>
lea    0xc77(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x30(%rbp),%r14
mov    %r15d,%edi
call   1050 <close@plt>
mov    %r14,%rsp
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ipmi_system_interface_addr = type { i64, i32, i32 }
%struct.ipmi_ipmb_addr = type { i32, i32, i64, i32 }
%struct.ipmi_addr = type { i32 }
%struct.ipmi_req = type { i32, i32, %struct.TYPE_3__, i8* }
%struct.TYPE_3__ = type { i32, i32, i32, i8* }
%struct.ipmi_recv = type { i32, %struct.TYPE_4__, i8* }
%struct.TYPE_4__ = type { i32*, i32 }
@ipmicmd.msgid = internal global i32 0
@.str = [11 x i8] c"/dev/ipmi0\00"
@O_RDONLY = global i32 0
@IPMI_SYSTEM_INTERFACE_ADDR_TYPE = global i32 0
@IPMI_BMC_CHANNEL = global i32 0
@IPMI_IPMB_ADDR_TYPE = global i32 0
@IPMICTL_SEND_COMMAND = global i32 0
@.str.1 = [5 x i8] c"send\00"
@.str.2 = [7 x i8] c"select\00"
@IPMICTL_RECEIVE_MSG_TRUNC = global i32 0
@errno = global i64 0
@EMSGSIZE = global i64 0
@.str.3 = [5 x i8] c"recv\00"
define i32 @ipmicmd(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i8* %5, i32 %6, i32* %7, i8* %8) {
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i32
%18 = alloca i32*
%19 = alloca i8*
%20 = alloca %struct.ipmi_system_interface_addr
%21 = alloca %struct.ipmi_ipmb_addr
%22 = alloca %struct.ipmi_addr
%23 = alloca %struct.ipmi_req
%24 = alloca %struct.ipmi_recv
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca i8*
%29 = alloca i64
%30 = alloca i32
store i32 %0, i32* %11
store i32 %1, i32* %12
store i32 %2, i32* %13
store i32 %3, i32* %14
store i32 %4, i32* %15
store i8* %5, i8** %16
store i32 %6, i32* %17
store i32* %7, i32** %18
store i8* %8, i8** %19
%31 = load i32, i32* %17
%32 = add nsw i32 %31, 1
%33 = zext i32 %32 to i64
%34 = call i8* @llvm.stacksave()
store i8* %34, i8** %28
%35 = alloca i32, i64 %33
store i64 %33, i64* %29
%36 = load i8*, i8** %19
%37 = load i32, i32* %17
%38 = call i32 @memset(i8* %36, i32 0, i32 %37)
%39 = load i32, i32* @O_RDONLY
%40 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %39)
store i32 %40, i32* %26
%41 = load i32, i32* %26
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %9
store i32 -1, i32* %10
store i32 1, i32* %30
br label %157
44: ; preds = %9
%45 = load i32, i32* %11
%46 = icmp eq i32 %45, 32
br i1 %46, label %47, label %56
47: ; preds = %44
%48 = load i32, i32* @IPMI_SYSTEM_INTERFACE_ADDR_TYPE
%49 = getelementptr inbounds %struct.ipmi_system_interface_addr, %struct.ipmi_system_interface_addr* %20, i32 0, i32 2
store i32 %48, i32* %49
%50 = load i32, i32* @IPMI_BMC_CHANNEL
%51 = getelementptr inbounds %struct.ipmi_system_interface_addr, %struct.ipmi_system_interface_addr* %20, i32 0, i32 1
store i32 %50, i32* %51
%52 = getelementptr inbounds %struct.ipmi_system_interface_addr, %struct.ipmi_system_interface_addr* %20, i32 0, i32 0
store i64 0, i64* %52
%53 = bitcast %struct.ipmi_system_interface_addr* %20 to i8*
%54 = getelementptr inbounds %struct.ipmi_req, %struct.ipmi_req* %23, i32 0, i32 3
store i8* %53, i8** %54
%55 = getelementptr inbounds %struct.ipmi_req, %struct.ipmi_req* %23, i32 0, i32 0
store i32 16, i32* %55
br label %67
56: ; preds = %44
%57 = load i32, i32* @IPMI_IPMB_ADDR_TYPE
%58 = getelementptr inbounds %struct.ipmi_ipmb_addr, %struct.ipmi_ipmb_addr* %21, i32 0, i32 3
store i32 %57, i32* %58
%59 = getelementptr inbounds %struct.ipmi_ipmb_addr, %struct.ipmi_ipmb_addr* %21, i32 0, i32 2
store i64 0, i64* %59
%60 = load i32, i32* %11
%61 = getelementptr inbounds %struct.ipmi_ipmb_addr, %struct.ipmi_ipmb_addr* %21, i32 0, i32 0
store i32 %60, i32* %61
%62 = load i32, i32* %12
%63 = getelementptr inbounds %struct.ipmi_ipmb_addr, %struct.ipmi_ipmb_addr* %21, i32 0, i32 1
store i32 %62, i32* %63
%64 = bitcast %struct.ipmi_ipmb_addr* %21 to i8*
%65 = getelementptr inbounds %struct.ipmi_req, %struct.ipmi_req* %23, i32 0, i32 3
store i8* %64, i8** %65
%66 = getelementptr inbounds %struct.ipmi_req, %struct.ipmi_req* %23, i32 0, i32 0
store i32 24, i32* %66
br label %67
67: ; preds = %56, %47
%68 = load i32, i32* @ipmicmd.msgid
%69 = add nsw i32 %68, 1
store i32 %69, i32* @ipmicmd.msgid
%70 = getelementptr inbounds %struct.ipmi_req, %struct.ipmi_req* %23, i32 0, i32 1
store i32 %69, i32* %70
%71 = load i32, i32* %13
%72 = getelementptr inbounds %struct.ipmi_req, %struct.ipmi_req* %23, i32 0, i32 2
%73 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %72, i32 0, i32 0
store i32 %71, i32* %73
%74 = load i32, i32* %14
%75 = getelementptr inbounds %struct.ipmi_req, %struct.ipmi_req* %23, i32 0, i32 2
%76 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %75, i32 0, i32 1
store i32 %74, i32* %76
%77 = load i32, i32* %15
%78 = getelementptr inbounds %struct.ipmi_req, %struct.ipmi_req* %23, i32 0, i32 2
%79 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %78, i32 0, i32 2
store i32 %77, i32* %79
%80 = load i8*, i8** %16
%81 = getelementptr inbounds %struct.ipmi_req, %struct.ipmi_req* %23, i32 0, i32 2
%82 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %81, i32 0, i32 3
store i8* %80, i8** %82
%83 = load i32, i32* %26
%84 = load i32, i32* @IPMICTL_SEND_COMMAND
%85 = bitcast %struct.ipmi_req* %23 to i8*
%86 = call i32 @ioctl(i32 %83, i32 %84, i8* %85)
store i32 %86, i32* %27
%87 = load i32, i32* %27
%88 = icmp ne i32 %87, 0
br i1 %88, label %89, label %91
89: ; preds = %67
%90 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %153
91: ; preds = %67
%92 = call i32 @FD_ZERO(i32* %25)
%93 = load i32, i32* %26
%94 = call i32 @FD_SET(i32 %93, i32* %25)
%95 = load i32, i32* %26
%96 = add nsw i32 %95, 1
%97 = call i32 @select(i32 %96, i32* %25, i32* null, i32* null, i32* null)
store i32 %97, i32* %27
%98 = load i32, i32* %27
%99 = icmp slt i32 %98, 0
br i1 %99, label %100, label %102
100: ; preds = %91
%101 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %153
102: ; preds = %91
%103 = getelementptr inbounds %struct.ipmi_recv, %struct.ipmi_recv* %24, i32 0, i32 1
%104 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %103, i32 0, i32 0
store i32* %35, i32** %104
%105 = load i32, i32* %17
%106 = add nsw i32 %105, 1
%107 = getelementptr inbounds %struct.ipmi_recv, %struct.ipmi_recv* %24, i32 0, i32 1
%108 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %107, i32 0, i32 1
store i32 %106, i32* %108
%109 = bitcast %struct.ipmi_addr* %22 to i8*
%110 = getelementptr inbounds %struct.ipmi_recv, %struct.ipmi_recv* %24, i32 0, i32 2
store i8* %109, i8** %110
%111 = getelementptr inbounds %struct.ipmi_recv, %struct.ipmi_recv* %24, i32 0, i32 0
store i32 4, i32* %111
%112 = load i32, i32* %26
%113 = load i32, i32* @IPMICTL_RECEIVE_MSG_TRUNC
%114 = bitcast %struct.ipmi_recv* %24 to i8*
%115 = call i32 @ioctl(i32 %112, i32 %113, i8* %114)
store i32 %115, i32* %27
%116 = load i32, i32* %27
%117 = icmp ne i32 %116, 0
br i1 %117, label %118, label %124
118: ; preds = %102
%119 = load i64, i64* @errno
%120 = load i64, i64* @EMSGSIZE
%121 = icmp ne i64 %119, %120
br i1 %121, label %122, label %124
122: ; preds = %118
%123 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %153
124: ; preds = %118, %102
%125 = getelementptr inbounds %struct.ipmi_recv, %struct.ipmi_recv* %24, i32 0, i32 1
%126 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %125, i32 0, i32 0
%127 = load i32*, i32** %126
%128 = getelementptr inbounds i32, i32* %127, i64 0
%129 = load i32, i32* %128
store i32 %129, i32* %27
%130 = load i32, i32* %27
%131 = icmp ne i32 %130, 0
br i1 %131, label %132, label %138
132: ; preds = %124
%133 = getelementptr inbounds %struct.ipmi_recv, %struct.ipmi_recv* %24, i32 0, i32 1
%134 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %133, i32 0, i32 0
%135 = load i32*, i32** %134
%136 = getelementptr inbounds i32, i32* %135, i64 0
%137 = load i32, i32* %136
store i32 %137, i32* %27
br label %152
138: ; preds = %124
%139 = getelementptr inbounds %struct.ipmi_recv, %struct.ipmi_recv* %24, i32 0, i32 1
%140 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %139, i32 0, i32 1
%141 = load i32, i32* %140
%142 = sub nsw i32 %141, 1
%143 = load i32*, i32** %18
store i32 %142, i32* %143
%144 = load i8*, i8** %19
%145 = getelementptr inbounds %struct.ipmi_recv, %struct.ipmi_recv* %24, i32 0, i32 1
%146 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %145, i32 0, i32 0
%147 = load i32*, i32** %146
%148 = getelementptr inbounds i32, i32* %147, i64 1
%149 = load i32*, i32** %18
%150 = load i32, i32* %149
%151 = call i32 @memcpy(i8* %144, i32* %148, i32 %150)
br label %152
152: ; preds = %138, %132
br label %153
153: ; preds = %152, %122, %100, %89
%154 = load i32, i32* %26
%155 = call i32 @close(i32 %154)
%156 = load i32, i32* %27
store i32 %156, i32* %10
store i32 1, i32* %30
br label %157
157: ; preds = %153, %43
%158 = load i8*, i8** %28
%159 = load i32, i32* %10
ret i32 %159
}

LLVM IR (-O2):
%struct.ipmi_system_interface_addr = type { i64, i32, i32 }
%struct.ipmi_ipmb_addr = type { i32, i32, i64, i32 }
%struct.ipmi_addr = type { i32 }
%struct.ipmi_req = type { i32, i32, %struct.TYPE_3__, i8* }
%struct.TYPE_3__ = type { i32, i32, i32, i8* }
%struct.ipmi_recv = type { i32, %struct.TYPE_4__, i8* }
%struct.TYPE_4__ = type { i32*, i32 }
@ipmicmd.msgid = internal unnamed_addr global i32 0
@.str = [11 x i8] c"/dev/ipmi0\00"
@O_RDONLY = global i32 0
@IPMI_SYSTEM_INTERFACE_ADDR_TYPE = global i32 0
@IPMI_BMC_CHANNEL = global i32 0
@IPMI_IPMB_ADDR_TYPE = global i32 0
@IPMICTL_SEND_COMMAND = global i32 0
@.str.1 = [5 x i8] c"send\00"
@.str.2 = [7 x i8] c"select\00"
@IPMICTL_RECEIVE_MSG_TRUNC = global i32 0
@errno = global i64 0
@EMSGSIZE = global i64 0
@.str.3 = [5 x i8] c"recv\00"
define i32 @ipmicmd(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i8* %5, i32 %6, i32* nocapture writeonly %7, i8* %8) {
%10 = alloca %struct.ipmi_system_interface_addr
%11 = alloca %struct.ipmi_ipmb_addr
%12 = alloca %struct.ipmi_addr
%13 = alloca %struct.ipmi_req
%14 = alloca %struct.ipmi_recv
%15 = alloca i32
%16 = bitcast %struct.ipmi_system_interface_addr* %10 to i8*
%17 = bitcast %struct.ipmi_ipmb_addr* %11 to i8*
%18 = bitcast %struct.ipmi_addr* %12 to i8*
%19 = bitcast %struct.ipmi_req* %13 to i8*
%20 = bitcast %struct.ipmi_recv* %14 to i8*
%21 = bitcast i32* %15 to i8*
%22 = add nsw i32 %6, 1
%23 = zext i32 %22 to i64
%24 = tail call i8* @llvm.stacksave()
%25 = alloca i32, i64 %23
%26 = tail call i32 @memset(i8* %8, i32 0, i32 %6)
%27 = load i32, i32* @O_RDONLY
%28 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = icmp slt i32 %28, 0
br i1 %29, label %98, label %30
30: ; preds = %9
%31 = icmp eq i32 %0, 32
br i1 %31, label %32, label %40
32: ; preds = %30
%33 = load i32, i32* @IPMI_SYSTEM_INTERFACE_ADDR_TYPE
%34 = getelementptr inbounds %struct.ipmi_system_interface_addr, %struct.ipmi_system_interface_addr* %10, i64 0, i32 2
store i32 %33, i32* %34
%35 = load i32, i32* @IPMI_BMC_CHANNEL
%36 = getelementptr inbounds %struct.ipmi_system_interface_addr, %struct.ipmi_system_interface_addr* %10, i64 0, i32 1
store i32 %35, i32* %36
%37 = getelementptr inbounds %struct.ipmi_system_interface_addr, %struct.ipmi_system_interface_addr* %10, i64 0, i32 0
store i64 0, i64* %37
%38 = getelementptr inbounds %struct.ipmi_req, %struct.ipmi_req* %13, i64 0, i32 3
%39 = bitcast i8** %38 to %struct.ipmi_system_interface_addr**
store %struct.ipmi_system_interface_addr* %10, %struct.ipmi_system_interface_addr** %39
br label %48
40: ; preds = %30
%41 = load i32, i32* @IPMI_IPMB_ADDR_TYPE
%42 = getelementptr inbounds %struct.ipmi_ipmb_addr, %struct.ipmi_ipmb_addr* %11, i64 0, i32 3
store i32 %41, i32* %42
%43 = getelementptr inbounds %struct.ipmi_ipmb_addr, %struct.ipmi_ipmb_addr* %11, i64 0, i32 2
store i64 0, i64* %43
%44 = getelementptr inbounds %struct.ipmi_ipmb_addr, %struct.ipmi_ipmb_addr* %11, i64 0, i32 0
store i32 %0, i32* %44
%45 = getelementptr inbounds %struct.ipmi_ipmb_addr, %struct.ipmi_ipmb_addr* %11, i64 0, i32 1
store i32 %1, i32* %45
%46 = getelementptr inbounds %struct.ipmi_req, %struct.ipmi_req* %13, i64 0, i32 3
%47 = bitcast i8** %46 to %struct.ipmi_ipmb_addr**
store %struct.ipmi_ipmb_addr* %11, %struct.ipmi_ipmb_addr** %47
br label %48
48: ; preds = %40, %32
%49 = phi i32 [ 16, %32 ], [ 24, %40 ]
%50 = getelementptr inbounds %struct.ipmi_req, %struct.ipmi_req* %13, i64 0, i32 0
store i32 %49, i32* %50
%51 = load i32, i32* @ipmicmd.msgid
%52 = add nsw i32 %51, 1
store i32 %52, i32* @ipmicmd.msgid
%53 = getelementptr inbounds %struct.ipmi_req, %struct.ipmi_req* %13, i64 0, i32 1
store i32 %52, i32* %53
%54 = getelementptr inbounds %struct.ipmi_req, %struct.ipmi_req* %13, i64 0, i32 2, i32 0
store i32 %2, i32* %54
%55 = getelementptr inbounds %struct.ipmi_req, %struct.ipmi_req* %13, i64 0, i32 2, i32 1
store i32 %3, i32* %55
%56 = getelementptr inbounds %struct.ipmi_req, %struct.ipmi_req* %13, i64 0, i32 2, i32 2
store i32 %4, i32* %56
%57 = getelementptr inbounds %struct.ipmi_req, %struct.ipmi_req* %13, i64 0, i32 2, i32 3
store i8* %5, i8** %57
%58 = load i32, i32* @IPMICTL_SEND_COMMAND
%59 = call i32 @ioctl(i32 %28, i32 %58, i8* %19)
%60 = icmp eq i32 %59, 0
br i1 %60, label %63, label %61
61: ; preds = %48
%62 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %95
63: ; preds = %48
%64 = call i32 @FD_ZERO(i32* %15)
%65 = call i32 @FD_SET(i32 %28, i32* %15)
%66 = add nuw nsw i32 %28, 1
%67 = call i32 @select(i32 %66, i32* %15, i32* null, i32* null, i32* null)
%68 = icmp slt i32 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %63
%70 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %95
71: ; preds = %63
%72 = getelementptr inbounds %struct.ipmi_recv, %struct.ipmi_recv* %14, i64 0, i32 1, i32 0
store i32* %25, i32** %72
%73 = getelementptr inbounds %struct.ipmi_recv, %struct.ipmi_recv* %14, i64 0, i32 1, i32 1
store i32 %22, i32* %73
%74 = getelementptr inbounds %struct.ipmi_recv, %struct.ipmi_recv* %14, i64 0, i32 2
%75 = bitcast i8** %74 to %struct.ipmi_addr**
store %struct.ipmi_addr* %12, %struct.ipmi_addr** %75
%76 = getelementptr inbounds %struct.ipmi_recv, %struct.ipmi_recv* %14, i64 0, i32 0
store i32 4, i32* %76
%77 = load i32, i32* @IPMICTL_RECEIVE_MSG_TRUNC
%78 = call i32 @ioctl(i32 %28, i32 %77, i8* %20)
%79 = icmp eq i32 %78, 0
br i1 %79, label %86, label %80
80: ; preds = %71
%81 = load i64, i64* @errno
%82 = load i64, i64* @EMSGSIZE
%83 = icmp eq i64 %81, %82
br i1 %83, label %86, label %84
84: ; preds = %80
%85 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %95
86: ; preds = %80, %71
%87 = load i32*, i32** %72
%88 = load i32, i32* %87
%89 = icmp eq i32 %88, 0
br i1 %89, label %90, label %95
90: ; preds = %86
%91 = load i32, i32* %73
%92 = add nsw i32 %91, -1
store i32 %92, i32* %7
%93 = getelementptr inbounds i32, i32* %87, i64 1
%94 = call i32 @memcpy(i8* %8, i32* %93, i32 %92)
br label %95
95: ; preds = %86, %90, %84, %69, %61
%96 = phi i32 [ %59, %61 ], [ %67, %69 ], [ %78, %84 ], [ 0, %90 ], [ %88, %86 ]
%97 = call i32 @close(i32 %28)
br label %98
98: ; preds = %9, %95
%99 = phi i32 [ %96, %95 ], [ -1, %9 ]
ret i32 %99
}