#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 unsigned long uint16_t;

/* Variables and functions */
unsigned long mdio_phy_id_c45(unsigned long, unsigned long);
unsigned long strtoul(char *, char **, int /*<<< orphan*/);
int parse_phy_id(char *text, uint16_t *phy_id) {
  unsigned long port, dev;
  char *end;
  port = strtoul(text, &end, 0);
  if (!end[0]) {
    *phy_id = port;
    return 0;
  }
  if (end[0] != ':') {
    return 1;
  }
  dev = strtoul(end + 1, &end, 0);
  if (end[0])
    return 1;
  *phy_id = mdio_phy_id_c45(port, dev);
  return 0;
}


x86 assembly (clang, -O0):
<parse_phy_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1167 <parse_phy_id+0x47>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11d1 <parse_phy_id+0xb1>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
je     1183 <parse_phy_id+0x63>
movl   $0x1,-0x4(%rbp)
jmp    11d1 <parse_phy_id+0xb1>
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
je     11b3 <parse_phy_id+0x93>
movl   $0x1,-0x4(%rbp)
jmp    11d1 <parse_phy_id+0xb1>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <mdio_phy_id_c45@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_phy_id>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rdi
mov    (%rdi),%al
test   %al,%al
je     1176 <parse_phy_id+0x56>
mov    $0x1,%ebp
cmp    $0x3a,%al
jne    117b <parse_phy_id+0x5b>
add    $0x1,%rdi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    0x8(%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    117b <parse_phy_id+0x5b>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <mdio_phy_id_c45@plt>
mov    %rax,%rbx
mov    %rbx,(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @parse_phy_id(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %4
store i64* %1, i64** %5
%9 = load i8*, i8** %4
%10 = call i64 @strtoul(i8* %9, i8** %8, i32 0)
store i64 %10, i64* %6
%11 = load i8*, i8** %8
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %2
%16 = load i64, i64* %6
%17 = load i64*, i64** %5
store i64 %16, i64* %17
store i32 0, i32* %3
br label %39
18: ; preds = %2
%19 = load i8*, i8** %8
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 58
br i1 %23, label %24, label %25
24: ; preds = %18
store i32 1, i32* %3
br label %39
25: ; preds = %18
%26 = load i8*, i8** %8
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = call i64 @strtoul(i8* %27, i8** %8, i32 0)
store i64 %28, i64* %7
%29 = load i8*, i8** %8
%30 = getelementptr inbounds i8, i8* %29, i64 0
%31 = load i8, i8* %30
%32 = icmp ne i8 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %25
store i32 1, i32* %3
br label %39
34: ; preds = %25
%35 = load i64, i64* %6
%36 = load i64, i64* %7
%37 = call i64 @mdio_phy_id_c45(i64 %35, i64 %36)
%38 = load i64*, i64** %5
store i64 %37, i64* %38
store i32 0, i32* %3
br label %39
39: ; preds = %34, %33, %24, %15
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
define i32 @parse_phy_id(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i64 @strtoul(i8* %0, i8** %3, i32 0)
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
switch i8 %7, label %18 [
i8 0, label %16
i8 58, label %8
]
8: ; preds = %2
%9 = getelementptr inbounds i8, i8* %6, i64 1
%10 = call i64 @strtoul(i8* %9, i8** %3, i32 0)
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %8
%15 = tail call i64 @mdio_phy_id_c45(i64 %5, i64 %10)
br label %16
16: ; preds = %2, %14
%17 = phi i64 [ %15, %14 ], [ %5, %2 ]
store i64 %17, i64* %1
br label %18
18: ; preds = %16, %8, %2
%19 = phi i32 [ 1, %2 ], [ 1, %8 ], [ 0, %16 ]
ret i32 %19
}