#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 *);
scalar_t__ isdigit(char);
int strlen(char *);
int checkPortValidity(char *port) {
  int len = strlen(port);
  if (len < 1)
    return 0;
  for (int i = 0; i < len; i++)
    if (isdigit(port[i]) == 0)
      return 0;
  int portN = atoi(port);
  return ((portN > 65535 || portN == 0) ? 0 : 1);
}


x86 assembly (clang, -O0):
<checkPortValidity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jge    115e <checkPortValidity+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    11e6 <checkPortValidity+0xb6>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ab <checkPortValidity+0x7b>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
jne    1198 <checkPortValidity+0x68>
movl   $0x0,-0x4(%rbp)
jmp    11e6 <checkPortValidity+0xb6>
jmp    119d <checkPortValidity+0x6d>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1165 <checkPortValidity+0x35>
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x1,%al
cmpl   $0xffff,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
jg     11d3 <checkPortValidity+0xa3>
cmpl   $0x0,-0x1c(%rbp)
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%dl
mov    $0x1,%eax
xor    %ecx,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkPortValidity>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1040 <strlen@plt>
test   %eax,%eax
jle    1185 <checkPortValidity+0x55>
mov    %eax,%r12d
xor    %r14d,%r14d
xor    %ebx,%ebx
nopl   0x0(%rax)
movsbl (%r15,%rbx,1),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1188 <checkPortValidity+0x58>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1150 <checkPortValidity+0x20>
mov    %r15,%rdi
call   1050 <atoi@plt>
cmp    $0x10000,%eax
setl   %cl
test   %eax,%eax
setne  %al
and    %cl,%al
movzbl %al,%r14d
jmp    1188 <checkPortValidity+0x58>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @checkPortValidity(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 1
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 0, i32* %2
br label %42
12: ; preds = %1
store i32 0, i32* %5
br label %13
13: ; preds = %27, %12
%14 = load i32, i32* %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %30
17: ; preds = %13
%18 = load i8*, i8** %3
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = call i64 @isdigit(i8 signext %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %17
store i32 0, i32* %2
br label %42
26: ; preds = %17
br label %27
27: ; preds = %26
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %13
30: ; preds = %13
%31 = load i8*, i8** %3
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = icmp sgt i32 %33, 65535
br i1 %34, label %38, label %35
35: ; preds = %30
%36 = load i32, i32* %6
%37 = icmp eq i32 %36, 0
br label %38
38: ; preds = %35, %30
%39 = phi i1 [ true, %30 ], [ %37, %35 ]
%40 = zext i1 %39 to i64
%41 = select i1 %39, i32 0, i32 1
store i32 %41, i32* %2
br label %42
42: ; preds = %38, %25, %11
%43 = load i32, i32* %2
ret i32 %43
}

LLVM IR (-O2):
define i32 @checkPortValidity(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp slt i32 %2, 1
br i1 %3, label %21, label %4
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %8
6: ; preds = %8
%7 = icmp eq i64 %14, %5
br i1 %7, label %15, label %8
8: ; preds = %4, %6
%9 = phi i64 [ 0, %4 ], [ %14, %6 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = tail call i64 @isdigit(i8 signext %11)
%13 = icmp eq i64 %12, 0
%14 = add nuw nsw i64 %9, 1
br i1 %13, label %21, label %6
15: ; preds = %6
%16 = tail call i32 @atoi(i8* %0)
%17 = icmp slt i32 %16, 65536
%18 = icmp ne i32 %16, 0
%19 = and i1 %17, %18
%20 = zext i1 %19 to i32
br label %21
21: ; preds = %8, %1, %15
%22 = phi i32 [ %20, %15 ], [ 0, %1 ], [ 0, %8 ]
ret i32 %22
}