#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 */
typedef int uint16_t;

/* Variables and functions */
int USHRT_MAX;
int /*<<< orphan*/ assert(char const *);
scalar_t__ errno;
int strlen(char const *);
int strtol(char const *, char **, int /*<<< orphan*/);
int host_is_valid(const char *addr, const char *port, uint16_t *portptr) {
  assert(addr);
  if (strlen(addr) > 64)
    return (0);
  if (port) {
    char *endptr;
    int tmp;
    errno = 0;
    tmp = strtol(port, &endptr, 0);
    if (errno || endptr[0] != '\0' || tmp <= 0 || tmp > USHRT_MAX)
      return 0;
    if (portptr)
      *portptr = tmp;
  }
  return (1);
}


x86 assembly (clang, -O0):
<host_is_valid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x40,%eax
jle    116b <host_is_valid+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    11ff <host_is_valid+0xcf>
cmpq   $0x0,-0x18(%rbp)
je     11f8 <host_is_valid+0xc8>
mov    0x2e5b(%rip),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2e3b(%rip),%rax
cmpq   $0x0,(%rax)
jne    11d3 <host_is_valid+0xa3>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11d3 <host_is_valid+0xa3>
cmpl   $0x0,-0x2c(%rbp)
jle    11d3 <host_is_valid+0xa3>
mov    -0x2c(%rbp),%eax
mov    0x2e1d(%rip),%rcx
cmp    (%rcx),%eax
jle    11df <host_is_valid+0xaf>
movl   $0x0,-0x4(%rbp)
jmp    11ff <host_is_valid+0xcf>
cmpq   $0x0,-0x20(%rbp)
je     11f3 <host_is_valid+0xc3>
mov    -0x2c(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    11f8 <host_is_valid+0xc8>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<host_is_valid>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%rbp
call   1040 <assert@plt>
mov    %rbp,%rdi
call   1030 <strlen@plt>
xor    %ebp,%ebp
cmp    $0x40,%eax
jg     11a6 <host_is_valid+0x76>
mov    $0x1,%ebp
test   %rbx,%rbx
je     11a6 <host_is_valid+0x76>
mov    0x2e73(%rip),%r15
movq   $0x0,(%r15)
mov    %rsp,%rsi
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <strtol@plt>
cmpq   $0x0,(%r15)
jne    11a6 <host_is_valid+0x76>
mov    (%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    11a6 <host_is_valid+0x76>
test   %eax,%eax
jle    11a6 <host_is_valid+0x76>
mov    0x2e53(%rip),%rcx
cmp    (%rcx),%eax
jg     11a6 <host_is_valid+0x76>
test   %r14,%r14
je     11a1 <host_is_valid+0x71>
mov    %eax,(%r14)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@USHRT_MAX = global i32 0
define i32 @host_is_valid(i8* %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%10 = load i8*, i8** %5
%11 = call i32 @assert(i8* %10)
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
%14 = icmp sgt i32 %13, 64
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 0, i32* %4
br label %46
16: ; preds = %3
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %45
19: ; preds = %16
store i64 0, i64* @errno
%20 = load i8*, i8** %6
%21 = call i32 @strtol(i8* %20, i8** %8, i32 0)
store i32 %21, i32* %9
%22 = load i64, i64* @errno
%23 = icmp ne i64 %22, 0
br i1 %23, label %37, label %24
24: ; preds = %19
%25 = load i8*, i8** %8
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 0
br i1 %29, label %37, label %30
30: ; preds = %24
%31 = load i32, i32* %9
%32 = icmp sle i32 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %30
%34 = load i32, i32* %9
%35 = load i32, i32* @USHRT_MAX
%36 = icmp sgt i32 %34, %35
br i1 %36, label %37, label %38
37: ; preds = %33, %30, %24, %19
store i32 0, i32* %4
br label %46
38: ; preds = %33
%39 = load i32*, i32** %7
%40 = icmp ne i32* %39, null
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i32, i32* %9
%43 = load i32*, i32** %7
store i32 %42, i32* %43
br label %44
44: ; preds = %41, %38
br label %45
45: ; preds = %44, %16
store i32 1, i32* %4
br label %46
46: ; preds = %45, %37, %15
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
@errno = global i64 0
@USHRT_MAX = global i32 0
define i32 @host_is_valid(i8* %0, i8* %1, i32* writeonly %2) {
%4 = alloca i8*
%5 = tail call i32 @assert(i8* %0)
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp sgt i32 %6, 64
br i1 %7, label %29, label %8
8: ; preds = %3
%9 = icmp eq i8* %1, null
br i1 %9, label %29, label %10
10: ; preds = %8
%11 = bitcast i8** %4 to i8*
store i64 0, i64* @errno
%12 = call i32 @strtol(i8* %1, i8** %4, i32 0)
%13 = load i64, i64* @errno
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %28
15: ; preds = %10
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
%19 = icmp slt i32 %12, 1
%20 = select i1 %18, i1 true, i1 %19
%21 = load i32, i32* @USHRT_MAX
%22 = icmp sgt i32 %12, %21
%23 = select i1 %20, i1 true, i1 %22
br i1 %23, label %28, label %24
24: ; preds = %15
%25 = icmp eq i32* %2, null
br i1 %25, label %27, label %26
26: ; preds = %24
store i32 %12, i32* %2
br label %27
27: ; preds = %26, %24
br label %29
28: ; preds = %10, %15
br label %29
29: ; preds = %8, %27, %28, %3
%30 = phi i32 [ 0, %28 ], [ 0, %3 ], [ 1, %27 ], [ 1, %8 ]
ret i32 %30
}