char *get_port(char *addr) {
  char *s;
  s = strchr(addr, '!');
  if (s == ((void *)0)) {
    ixp_werrstr("no port provided");
    return ((void *)0);
  }
  *s++ = '\0';
  if (*s == '\0') {
    ixp_werrstr("invalid port number");
    return ((void *)0);
  }
  return s;
}


x86 assembly (clang, -O0):
<get_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x21,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1164 <get_port+0x44>
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1040 <ixp_werrstr@plt>
movq   $0x0,-0x8(%rbp)
jmp    11a9 <get_port+0x89>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11a1 <get_port+0x81>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <ixp_werrstr@plt>
movq   $0x0,-0x8(%rbp)
jmp    11a9 <get_port+0x89>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_port>:
push   %rbx
mov    $0x21,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1142 <get_port+0x22>
mov    %rax,%rbx
movb   $0x0,(%rax)
cmpb   $0x0,0x1(%rax)
je     114b <get_port+0x2b>
add    $0x1,%rbx
jmp    115b <get_port+0x3b>
lea    0xeb7(%rip),%rdi
jmp    1152 <get_port+0x32>
lea    0xebf(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <ixp_werrstr@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"no port provided\00"
@.str.1 = [20 x i8] c"invalid port number\00"
define i8* @get_port(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i8* @strchr(i8* %5, i32 33)
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 (i8*, ...) bitcast (i32 (...)* @ixp_werrstr to i32 (i8*, ...)*)(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %22
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %4
store i8 0, i8* %12
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = call i32 (i8*, ...) bitcast (i32 (...)* @ixp_werrstr to i32 (i8*, ...)*)(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %2
br label %22
20: ; preds = %11
%21 = load i8*, i8** %4
store i8* %21, i8** %2
br label %22
22: ; preds = %20, %18, %9
%23 = load i8*, i8** %2
ret i8* %23
}

LLVM IR (-O2):
@.str = [17 x i8] c"no port provided\00"
@.str.1 = [20 x i8] c"invalid port number\00"
define i8* @get_port(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 33)
%3 = icmp eq i8* %2, null
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %2, i64 1
store i8 0, i8* %2
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %4, %1
%9 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), %4 ]
%10 = tail call i32 (i8*, ...) bitcast (i32 (...)* @ixp_werrstr to i32 (i8*, ...)*)(i8* %9)
br label %11
11: ; preds = %8, %4
%12 = phi i8* [ %5, %4 ], [ null, %8 ]
ret i8* %12
}