#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*/ EXIT_FAILURE;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fscanf(int /*<<< orphan*/, char *, int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
void getPort(int *port) {
  assert(NULL != port);
  *port = 0;
  while (0 >= *port || 65535 < *port) {
    fprintf(stdout, "Enter port (default = 6667): ");
    if (1 != fscanf(stdin, "%d", port)) {
      perror("fscanf error");
      exit(EXIT_FAILURE);
    }
    if (0 >= *port)
      fprintf(stdout, "Port must be greater than zero\n");
    else if (65535 < *port)
      fprintf(stdout, "Port must be less than %d\n", 65535);
  }
}


x86 assembly (clang, -O0):
<getPort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rdx
mov    $0x1,%al
xor    %ecx,%ecx
cmp    (%rdx),%ecx
mov    %al,-0x9(%rbp)
jge    119d <getPort+0x4d>
mov    -0x8(%rbp),%rcx
mov    $0xffff,%eax
cmp    (%rcx),%eax
setl   %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    11ad <getPort+0x5d>
jmp    1267 <getPort+0x117>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe46(%rip),%rsi
call   1030 <fscanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
je     1206 <getPort+0xb6>
lea    0xe2e(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rcx
xor    %eax,%eax
cmp    (%rcx),%eax
jl     1230 <getPort+0xe0>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1262 <getPort+0x112>
mov    -0x8(%rbp),%rcx
mov    $0xffff,%eax
cmp    (%rcx),%eax
jge    125d <getPort+0x10d>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
mov    $0xffff,%edx
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1262 <getPort+0x112>
jmp    1179 <getPort+0x29>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1040 <assert@plt>
movl   $0x0,(%rbx)
mov    0x2e57(%rip),%rbp
lea    0xe80(%rip),%r14
mov    0x2e61(%rip),%r13
lea    0xe90(%rip),%r15
mov    $0xffff0000,%r12d
jmp    11bd <getPort+0x6d>
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%rbp),%edi
lea    0xe84(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%eax
add    %r12d,%eax
cmp    $0xffff0001,%eax
jae    1203 <getPort+0xb3>
mov    0x0(%rbp),%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%r13),%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1030 <fscanf@plt>
cmp    $0x1,%eax
jne    1212 <getPort+0xc2>
mov    (%rbx),%eax
test   %eax,%eax
jle    11a0 <getPort+0x50>
cmp    $0x10000,%eax
jb     11b1 <getPort+0x61>
mov    0x0(%rbp),%edi
lea    0xe59(%rip),%rsi
mov    $0xffff,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11b1 <getPort+0x61>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe08(%rip),%rdi
call   1060 <perror@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [30 x i8] c"Enter port (default = 6667): \00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [13 x i8] c"fscanf error\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [32 x i8] c"Port must be greater than zero\0A\00"
@.str.4 = [27 x i8] c"Port must be less than %d\0A\00"
define void @getPort(i32* %0) {
%2 = alloca i32*
store i32* %0, i32** %2
%3 = load i32*, i32** %2
%4 = icmp ne i32* null, %3
%5 = zext i1 %4 to i32
%6 = call i32 @assert(i32 %5)
%7 = load i32*, i32** %2
store i32 0, i32* %7
br label %8
8: ; preds = %44, %1
%9 = load i32*, i32** %2
%10 = load i32, i32* %9
%11 = icmp sge i32 0, %10
br i1 %11, label %16, label %12
12: ; preds = %8
%13 = load i32*, i32** %2
%14 = load i32, i32* %13
%15 = icmp slt i32 65535, %14
br label %16
16: ; preds = %12, %8
%17 = phi i1 [ true, %8 ], [ %15, %12 ]
br i1 %17, label %18, label %45
18: ; preds = %16
%19 = load i32, i32* @stdout
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @stdin
%22 = load i32*, i32** %2
%23 = call i32 @fscanf(i32 %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %22)
%24 = icmp ne i32 1, %23
br i1 %24, label %25, label %29
25: ; preds = %18
%26 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %18
%30 = load i32*, i32** %2
%31 = load i32, i32* %30
%32 = icmp sge i32 0, %31
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i32, i32* @stdout
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %44
36: ; preds = %29
%37 = load i32*, i32** %2
%38 = load i32, i32* %37
%39 = icmp slt i32 65535, %38
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i32, i32* @stdout
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 65535)
br label %43
43: ; preds = %40, %36
br label %44
44: ; preds = %43, %33
br label %8
45: ; preds = %16
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [30 x i8] c"Enter port (default = 6667): \00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [13 x i8] c"fscanf error\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [32 x i8] c"Port must be greater than zero\0A\00"
@.str.4 = [27 x i8] c"Port must be less than %d\0A\00"
define void @getPort(i32* %0) {
%2 = icmp ne i32* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
store i32 0, i32* %0
br label %5
5: ; preds = %1, %26
%6 = load i32, i32* @stdout
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @stdin
%9 = tail call i32 @fscanf(i32 %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %0)
%10 = icmp eq i32 %9, 1
br i1 %10, label %15, label %11
11: ; preds = %5
%12 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %5
%16 = load i32, i32* %0
%17 = icmp slt i32 %16, 1
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* @stdout
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %26
21: ; preds = %15
%22 = icmp ugt i32 %16, 65535
br i1 %22, label %23, label %26
23: ; preds = %21
%24 = load i32, i32* @stdout
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 65535)
br label %26
26: ; preds = %21, %23, %18
%27 = load i32, i32* %0
%28 = add i32 %27, -65536
%29 = icmp ult i32 %28, -65535
br i1 %29, label %5, label %30
30: ; preds = %26
ret void
}