#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 void *u_int8_t;
typedef void *u_int16_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int EINVAL;
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *strchr(char *, char);
int /*<<< orphan*/ strncpy(char *, char *, int);
void *strtoul(char *, int /*<<< orphan*/ *, int);
int parse_ioreg(u_int16_t *reg, u_int8_t *index, char *str) {
  char *dot;
  char buf[255];
  memset(buf, 0, sizeof(*buf));
  strncpy(buf, str, sizeof(buf) - 1);
  dot = strchr(buf, '.');
  if (!dot)
    return -EINVAL;
  *dot = '\0';
  *reg = strtoul(buf, NULL, 16);
  *index = strtoul(dot + 1, NULL, 16);
  return 0;
}


x86 assembly (clang, -O0):
<parse_ioreg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1050 <memset@plt>
lea    -0x130(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0xfe,%edx
call   1030 <strncpy@plt>
lea    -0x130(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b2 <parse_ioreg+0x72>
xor    %eax,%eax
mov    0x2e38(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11ff <parse_ioreg+0xbf>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x130(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_ioreg>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsp,%r13
xor    %r12d,%r12d
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1050 <memset@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0xfe,%edx
call   1030 <strncpy@plt>
mov    %r13,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11c0 <parse_ioreg+0x80>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %rax,(%r15)
add    $0x1,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %rax,(%r14)
jmp    11cd <parse_ioreg+0x8d>
mov    0x2e19(%rip),%rax
xor    %r12d,%r12d
sub    (%rax),%r12d
mov    %r12d,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EINVAL = global i32 0
define i32 @parse_ioreg(i8** %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [255 x i8]
store i8** %0, i8*** %5
store i8** %1, i8*** %6
store i8* %2, i8** %7
%10 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%11 = call i32 @memset(i8* %10, i32 0, i32 1)
%12 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%13 = load i8*, i8** %7
%14 = call i32 @strncpy(i8* %12, i8* %13, i32 254)
%15 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%16 = call i8* @strchr(i8* %15, i8 signext 46)
store i8* %16, i8** %8
%17 = load i8*, i8** %8
%18 = icmp ne i8* %17, null
br i1 %18, label %22, label %19
19: ; preds = %3
%20 = load i32, i32* @EINVAL
%21 = sub nsw i32 0, %20
store i32 %21, i32* %4
br label %31
22: ; preds = %3
%23 = load i8*, i8** %8
store i8 0, i8* %23
%24 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%25 = call i8* @strtoul(i8* %24, i32* null, i32 16)
%26 = load i8**, i8*** %5
store i8* %25, i8** %26
%27 = load i8*, i8** %8
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = call i8* @strtoul(i8* %28, i32* null, i32 16)
%30 = load i8**, i8*** %6
store i8* %29, i8** %30
store i32 0, i32* %4
br label %31
31: ; preds = %22, %19
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
@EINVAL = global i32 0
define i32 @parse_ioreg(i8** nocapture writeonly %0, i8** nocapture writeonly %1, i8* %2) {
%4 = alloca [255 x i8]
%5 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 1)
%7 = call i32 @strncpy(i8* %5, i8* %2, i32 254)
%8 = call i8* @strchr(i8* %5, i8 signext 46)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i32, i32* @EINVAL
%12 = sub nsw i32 0, %11
br label %17
13: ; preds = %3
store i8 0, i8* %8
%14 = call i8* @strtoul(i8* nocapture %5, i32* null, i32 16)
store i8* %14, i8** %0
%15 = getelementptr inbounds i8, i8* %8, i64 1
%16 = call i8* @strtoul(i8* nocapture %15, i32* null, i32 16)
store i8* %16, i8** %1
br label %17
17: ; preds = %13, %10
%18 = phi i32 [ 0, %13 ], [ %12, %10 ]
ret i32 %18
}