#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 atoi(char const *);
int get_free_port();
int /*<<< orphan*/ isdigit(unsigned char);
int parse_address(const char *addr) {
  if (!addr)
    return get_free_port();
  if (*addr == 0)
    return 0;
  if (*addr == ':')
    addr++;
  if (!isdigit((unsigned char)*addr))
    return -1;
  else
    return atoi(addr);
}


x86 assembly (clang, -O0):
<parse_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1156 <parse_address+0x26>
mov    $0x0,%al
call   1040 <get_free_port@plt>
mov    %eax,-0x4(%rbp)
jmp    11bb <parse_address+0x8b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1172 <parse_address+0x42>
movl   $0x0,-0x4(%rbp)
jmp    11bb <parse_address+0x8b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    118e <parse_address+0x5e>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    11af <parse_address+0x7f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bb <parse_address+0x8b>
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_address>:
push   %rbx
test   %rdi,%rdi
je     115f <parse_address+0x2f>
mov    %rdi,%rbx
mov    (%rdi),%al
test   %al,%al
je     1167 <parse_address+0x37>
cmp    $0x3a,%al
jne    114a <parse_address+0x1a>
mov    0x1(%rbx),%al
add    $0x1,%rbx
movzbl %al,%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     116b <parse_address+0x3b>
mov    %rbx,%rdi
pop    %rbx
jmp    1050 <atoi@plt>
xor    %eax,%eax
pop    %rbx
jmp    1040 <get_free_port@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @parse_address(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = icmp ne i8* %4, null
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = call i32 (...) @get_free_port()
store i32 %7, i32* %2
br label %31
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %8
store i32 0, i32* %2
br label %31
14: ; preds = %8
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 58
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %3
br label %22
22: ; preds = %19, %14
%23 = load i8*, i8** %3
%24 = load i8, i8* %23
%25 = call i32 @isdigit(i8 zeroext %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %22
store i32 -1, i32* %2
br label %31
28: ; preds = %22
%29 = load i8*, i8** %3
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %2
br label %31
31: ; preds = %28, %27, %13, %6
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
define i32 @parse_address(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 (...) @get_free_port()
br label %17
5: ; preds = %1
%6 = load i8, i8* %0
switch i8 %6, label %10 [
i8 0, label %17
i8 58, label %7
]
7: ; preds = %5
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = load i8, i8* %8
br label %10
10: ; preds = %5, %7
%11 = phi i8 [ %9, %7 ], [ %6, %5 ]
%12 = phi i8* [ %8, %7 ], [ %0, %5 ]
%13 = tail call i32 @isdigit(i8 zeroext %11)
%14 = icmp eq i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %10
%16 = tail call i32 @atoi(i8* %12)
br label %17
17: ; preds = %10, %5, %15, %3
%18 = phi i32 [ %16, %15 ], [ %4, %3 ], [ 0, %5 ], [ -1, %10 ]
ret i32 %18
}