#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 noly_tcp_socket(int, int);
int noly_tcp_socket_from(int start, int *port, int max_cli) {
  int i = start;
  int sk = (-1);
  for (i = start; i < 65535; i++) {
    if ((sk = noly_tcp_socket(i, max_cli)) > 0) {
      *port = i;
      return sk;
    }
  }
  return (-1);
}


x86 assembly (clang, -O0):
<noly_tcp_socket_from>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0xffff,-0x18(%rbp)
jge    1180 <noly_tcp_socket_from+0x70>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <noly_tcp_socket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    116d <noly_tcp_socket_from+0x5d>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1187 <noly_tcp_socket_from+0x77>
jmp    1172 <noly_tcp_socket_from+0x62>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1135 <noly_tcp_socket_from+0x25>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<noly_tcp_socket_from>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%r15d
cmp    $0xfffe,%edi
jg     1150 <noly_tcp_socket_from+0x40>
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%ebp
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %ebx,%esi
call   1030 <noly_tcp_socket@plt>
test   %eax,%eax
jg     114a <noly_tcp_socket_from+0x3a>
add    $0x1,%ebp
cmp    $0xffff,%ebp
jne    1130 <noly_tcp_socket_from+0x20>
jmp    1150 <noly_tcp_socket_from+0x40>
mov    %ebp,(%r14)
mov    %eax,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @noly_tcp_socket_from(i32 %0, i32* nocapture writeonly %1, i32 %2) {
%4 = icmp slt i32 %0, 65535
br i1 %4, label %5, label %13
5: ; preds = %3, %10
%6 = phi i32 [ %11, %10 ], [ %0, %3 ]
%7 = tail call i32 @noly_tcp_socket(i32 %6, i32 %2)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %5
store i32 %6, i32* %1
br label %13
10: ; preds = %5
%11 = add i32 %6, 1
%12 = icmp eq i32 %11, 65535
br i1 %12, label %13, label %5
13: ; preds = %10, %3, %9
%14 = phi i32 [ %7, %9 ], [ -1, %3 ], [ -1, %10 ]
ret i32 %14
}