#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 */
scalar_t__ errno;
long strtol(char const *, char **, int);
int isport(const char *digit) {
  char *end;
  long int l;
  if (digit == NULL)
    return 0;
  errno = 0;
  l = strtol(digit, &end, 10);
  if (*end == '\0' && errno == 0 && l < 0xFFFF && l > 0)
    return (int)l;
  return 0;
}


x86 assembly (clang, -O0):
<isport>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1133 <isport+0x23>
movl   $0x0,-0x4(%rbp)
jmp    11a4 <isport+0x94>
mov    0x2ea6(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    119d <isport+0x8d>
mov    0x2e72(%rip),%rax
cmpq   $0x0,(%rax)
jne    119d <isport+0x8d>
cmpq   $0xffff,-0x20(%rbp)
jge    119d <isport+0x8d>
cmpq   $0x0,-0x20(%rbp)
jle    119d <isport+0x8d>
mov    -0x20(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    11a4 <isport+0x94>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isport>:
test   %rdi,%rdi
je     1164 <isport+0x54>
push   %rbx
sub    $0x10,%rsp
mov    0x2ebf(%rip),%rbx
movq   $0x0,(%rbx)
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,%rcx
xor    %edx,%edx
test   %rax,%rax
cmovle %edx,%eax
mov    0x8(%rsp),%rsi
cmp    $0xffff,%rcx
cmovge %edx,%eax
cmpq   $0x0,(%rbx)
cmovne %edx,%eax
cmpb   $0x0,(%rsi)
cmovne %edx,%eax
add    $0x10,%rsp
pop    %rbx
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
@errno = global i64 0
define i32 @isport(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 0, i32* %2
br label %29
9: ; preds = %1
store i64 0, i64* @errno
%10 = load i8*, i8** %3
%11 = call i64 @strtol(i8* %10, i8** %4, i32 10)
store i64 %11, i64* %5
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %9
%17 = load i64, i64* @errno
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %28
19: ; preds = %16
%20 = load i64, i64* %5
%21 = icmp slt i64 %20, 65535
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load i64, i64* %5
%24 = icmp sgt i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i64, i64* %5
%27 = trunc i64 %26 to i32
store i32 %27, i32* %2
br label %29
28: ; preds = %22, %19, %16, %9
store i32 0, i32* %2
br label %29
29: ; preds = %28, %25, %8
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
@errno = global i64 0
define i32 @isport(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %19, label %5
5: ; preds = %1
store i64 0, i64* @errno
%6 = call i64 @strtol(i8* %0, i8** %2, i32 10)
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
%10 = load i64, i64* @errno
%11 = icmp eq i64 %10, 0
%12 = select i1 %9, i1 %11, i1 false
%13 = icmp slt i64 %6, 65535
%14 = select i1 %12, i1 %13, i1 false
%15 = icmp sgt i64 %6, 0
%16 = select i1 %14, i1 %15, i1 false
%17 = trunc i64 %6 to i32
%18 = select i1 %16, i32 %17, i32 0
br label %19
19: ; preds = %5, %1
%20 = phi i32 [ 0, %1 ], [ %18, %5 ]
ret i32 %20
}