#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strtoul(char *, char **, int);
unsigned short parse_port(char *at, int *rc) {
  unsigned short result = 0;
  if (*at != '\0' && *(++at) != '\0') {
    char *endptr = at;
    result = (unsigned short)strtoul(at, &endptr, 10);
    if (*endptr != '\0') {
      fprintf(stderr, "invalid port number '%s'", at);
      *rc = 2;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<parse_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movw   $0x0,-0x12(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11b8 <parse_port+0x98>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     11b8 <parse_port+0x98>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %ax,-0x12(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11b3 <parse_port+0x93>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe5c(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%rax
movl   $0x2,(%rax)
jmp    11b8 <parse_port+0x98>
movzwl -0x12(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_port>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
cmpb   $0x0,(%rdi)
je     1183 <parse_port+0x63>
mov    %rdi,%rbx
cmpb   $0x0,0x1(%rdi)
je     1183 <parse_port+0x63>
mov    %rsi,%r14
add    $0x1,%rbx
mov    %rbx,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,%r15
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     1186 <parse_port+0x66>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
movl   $0x2,(%r14)
jmp    1186 <parse_port+0x66>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"invalid port number '%s'\00"
define zeroext i16 @parse_port(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i16
%6 = alloca i8*
store i8* %0, i8** %3
store i32* %1, i32** %4
store i16 0, i16* %5
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %32
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %3
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %32
17: ; preds = %11
%18 = load i8*, i8** %3
store i8* %18, i8** %6
%19 = load i8*, i8** %3
%20 = call i64 @strtoul(i8* %19, i8** %6, i32 10)
%21 = trunc i64 %20 to i16
store i16 %21, i16* %5
%22 = load i8*, i8** %6
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %17
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %3
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %28)
%30 = load i32*, i32** %4
store i32 2, i32* %30
br label %31
31: ; preds = %26, %17
br label %32
32: ; preds = %31, %11, %2
%33 = load i16, i16* %5
ret i16 %33
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"invalid port number '%s'\00"
define zeroext i16 @parse_port(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i8*
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %21, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %21, label %10
10: ; preds = %6
%11 = bitcast i8** %3 to i8*
store i8* %7, i8** %3
%12 = call i64 @strtoul(i8* %7, i8** %3, i32 10)
%13 = trunc i64 %12 to i16
%14 = load i8*, i8** %3
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %10
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %7)
store i32 2, i32* %1
br label %20
20: ; preds = %17, %10
br label %21
21: ; preds = %20, %6, %2
%22 = phi i16 [ %13, %20 ], [ 0, %6 ], [ 0, %2 ]
ret i16 %22
}