#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*/ ECONNREFUSED;
int /*<<< orphan*/ errno;
char *getenv(char *);
int /*<<< orphan*/ strspn(char *, char *);
long strtol(char *, char **, int);
int port_is_okay(unsigned short port) {
  char *p, *q;
  long l;
  p = getenv("NOPORT");
  while ((p != NULL) && (*p != '\0')) {
    l = strtol(p, &q, 10);
    if ((q == NULL) || (q == p)) {
      break;
    }
    if ((*q == '\0') || (*q == ',')) {
      if (port == l) {
        errno = ECONNREFUSED;
        return -1;
      }
    }
    p = q;
    p += strspn(p, ",");
  }
  return 0;
}


x86 assembly (clang, -O0):
<port_is_okay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %di,%ax
mov    %ax,-0x6(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x21(%rbp)
je     116f <port_is_okay+0x3f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    117f <port_is_okay+0x4f>
jmp    1231 <port_is_okay+0x101>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ae <port_is_okay+0x7e>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    11b3 <port_is_okay+0x83>
jmp    1231 <port_is_okay+0x101>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d3 <port_is_okay+0xa3>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2c,%eax
jne    1204 <port_is_okay+0xd4>
movzwl -0x6(%rbp),%eax
cmp    -0x20(%rbp),%rax
jne    11ff <port_is_okay+0xcf>
mov    0x2e00(%rip),%rax
mov    (%rax),%ecx
mov    0x2de7(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1238 <port_is_okay+0x108>
jmp    1204 <port_is_okay+0xd4>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdf0(%rip),%rsi
call   1040 <strspn@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    114f <port_is_okay+0x1f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<port_is_okay>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0xebc(%rip),%rdi
call   1030 <getenv@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     11d0 <port_is_okay+0xa0>
mov    %rax,%rbp
cmpb   $0x0,(%rax)
je     11d0 <port_is_okay+0xa0>
movzwl %bx,%r13d
mov    %rsp,%r12
lea    0xea0(%rip),%r15
jmp    118c <port_is_okay+0x5c>
nopl   0x0(%rax)
cmp    %r13,%rax
je     11b8 <port_is_okay+0x88>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strspn@plt>
cltq
lea    (%rbx,%rax,1),%rbp
cmpb   $0x0,(%rbx,%rax,1)
je     11d0 <port_is_okay+0xa0>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    (%rsp),%rbx
test   %rbx,%rbx
je     11d0 <port_is_okay+0xa0>
cmp    %rbp,%rbx
je     11d0 <port_is_okay+0xa0>
movzbl (%rbx),%ecx
cmp    $0x2c,%cl
je     1170 <port_is_okay+0x40>
test   %cl,%cl
je     1170 <port_is_okay+0x40>
jmp    1175 <port_is_okay+0x45>
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    0x2e10(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"NOPORT\00"
@ECONNREFUSED = global i32 0
@errno = global i32 0
@.str.1 = [2 x i8] c",\00"
define i32 @port_is_okay(i16 zeroext %0) {
%2 = alloca i32
%3 = alloca i16
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i16 %0, i16* %3
%7 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %4
br label %8
8: ; preds = %46, %1
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br label %16
16: ; preds = %11, %8
%17 = phi i1 [ false, %8 ], [ %15, %11 ]
br i1 %17, label %18, label %53
18: ; preds = %16
%19 = load i8*, i8** %4
%20 = call i64 @strtol(i8* %19, i8** %5, i32 10)
store i64 %20, i64* %6
%21 = load i8*, i8** %5
%22 = icmp eq i8* %21, null
br i1 %22, label %27, label %23
23: ; preds = %18
%24 = load i8*, i8** %5
%25 = load i8*, i8** %4
%26 = icmp eq i8* %24, %25
br i1 %26, label %27, label %28
27: ; preds = %23, %18
br label %53
28: ; preds = %23
%29 = load i8*, i8** %5
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 0
br i1 %32, label %38, label %33
33: ; preds = %28
%34 = load i8*, i8** %5
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 44
br i1 %37, label %38, label %46
38: ; preds = %33, %28
%39 = load i16, i16* %3
%40 = zext i16 %39 to i64
%41 = load i64, i64* %6
%42 = icmp eq i64 %40, %41
br i1 %42, label %43, label %45
43: ; preds = %38
%44 = load i32, i32* @ECONNREFUSED
store i32 %44, i32* @errno
store i32 -1, i32* %2
br label %54
45: ; preds = %38
br label %46
46: ; preds = %45, %33
%47 = load i8*, i8** %5
store i8* %47, i8** %4
%48 = load i8*, i8** %4
%49 = call i32 @strspn(i8* %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%50 = load i8*, i8** %4
%51 = sext i32 %49 to i64
%52 = getelementptr inbounds i8, i8* %50, i64 %51
store i8* %52, i8** %4
br label %8
53: ; preds = %27, %16
store i32 0, i32* %2
br label %54
54: ; preds = %53, %43
%55 = load i32, i32* %2
ret i32 %55
}

LLVM IR (-O2):
@.str = [7 x i8] c"NOPORT\00"
@ECONNREFUSED = global i32 0
@errno = global i32 0
@.str.1 = [2 x i8] c",\00"
define i32 @port_is_okay(i16 zeroext %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %29, label %6
6: ; preds = %1
%7 = zext i16 %0 to i64
%8 = load i8, i8* %4
%9 = icmp eq i8 %8, 0
br i1 %9, label %29, label %10
10: ; preds = %6, %23
%11 = phi i8* [ %26, %23 ], [ %4, %6 ]
%12 = call i64 @strtol(i8* %11, i8** %2, i32 10)
%13 = load i8*, i8** %2
%14 = icmp eq i8* %13, null
%15 = icmp eq i8* %13, %11
%16 = or i1 %14, %15
br i1 %16, label %29, label %17
17: ; preds = %10
%18 = load i8, i8* %13
switch i8 %18, label %23 [
i8 0, label %19
i8 44, label %19
]
19: ; preds = %17, %17
%20 = icmp eq i64 %12, %7
br i1 %20, label %21, label %23
21: ; preds = %19
%22 = load i32, i32* @ECONNREFUSED
store i32 %22, i32* @errno
br label %29
23: ; preds = %17, %19
%24 = tail call i32 @strspn(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %13, i64 %25
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %29, label %10
29: ; preds = %23, %10, %6, %1, %21
%30 = phi i32 [ -1, %21 ], [ 0, %1 ], [ 0, %6 ], [ 0, %10 ], [ 0, %23 ]
ret i32 %30
}