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


x86 assembly (clang, -O0):
<noly_udp_socket_from>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xffff,-0x14(%rbp)
jge    117a <noly_udp_socket_from+0x6a>
mov    -0x14(%rbp),%edi
call   1030 <noly_udp_socket@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jle    1167 <noly_udp_socket_from+0x57>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1181 <noly_udp_socket_from+0x71>
jmp    116c <noly_udp_socket_from+0x5c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1132 <noly_udp_socket_from+0x22>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<noly_udp_socket_from>:
push   %rbp
push   %r14
push   %rbx
mov    $0xffffffff,%ebx
cmp    $0xfffe,%edi
jg     114d <noly_udp_socket_from+0x3d>
mov    %rsi,%r14
mov    %edi,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1030 <noly_udp_socket@plt>
test   %eax,%eax
jg     1148 <noly_udp_socket_from+0x38>
add    $0x1,%ebp
cmp    $0xffff,%ebp
jne    1130 <noly_udp_socket_from+0x20>
jmp    114d <noly_udp_socket_from+0x3d>
mov    %ebp,(%r14)
mov    %eax,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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