#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*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ rlClose(int);
int rlConnect(int, char const *, short const);
int /*<<< orphan*/ rlIsValidSocket(int);
int rlOpen(short const);
int /*<<< orphan*/ sleep(int const);
int rlWaitForConnection(const char *address, const short port,
                        const int retryTimeout) {
  int theConnection = 0;
  int isConnected = -1;
  while (isConnected == -1) {
    theConnection = rlOpen(port);
    assert(rlIsValidSocket(theConnection));
    isConnected = rlConnect(theConnection, address, port);
    if (isConnected == -1) {
      rlClose(theConnection);
      sleep(retryTimeout);
      ;
    }
  }
  return theConnection;
}


x86 assembly (clang, -O0):
<rlWaitForConnection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11db <rlWaitForConnection+0x7b>
movswl -0xa(%rbp),%edi
call   1050 <rlOpen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <rlIsValidSocket@plt>
mov    %eax,%edi
call   1070 <assert@plt>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rsi
movswl -0xa(%rbp),%edx
call   1030 <rlConnect@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11d6 <rlWaitForConnection+0x76>
mov    -0x14(%rbp),%edi
call   1060 <rlClose@plt>
mov    -0x10(%rbp),%edi
call   1080 <sleep@plt>
jmp    1184 <rlWaitForConnection+0x24>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rlWaitForConnection>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebx
mov    %rdi,%r15
mov    %esi,%edi
call   1050 <rlOpen@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <rlIsValidSocket@plt>
mov    %eax,%edi
call   1070 <assert@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <rlConnect@plt>
cmp    $0xffffffff,%eax
jne    11d7 <rlWaitForConnection+0x77>
movswl %bx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1060 <rlClose@plt>
mov    %r14d,%edi
call   1080 <sleep@plt>
mov    %ebx,%edi
call   1050 <rlOpen@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <rlIsValidSocket@plt>
mov    %eax,%edi
call   1070 <assert@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <rlConnect@plt>
cmp    $0xffffffff,%eax
je     11a0 <rlWaitForConnection+0x40>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @rlWaitForConnection(i8* %0, i16 signext %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i16
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i16 %1, i16* %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i32 -1, i32* %8
br label %9
9: ; preds = %29, %3
%10 = load i32, i32* %8
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %30
12: ; preds = %9
%13 = load i16, i16* %5
%14 = call i32 @rlOpen(i16 signext %13)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = call i32 @rlIsValidSocket(i32 %15)
%17 = call i32 @assert(i32 %16)
%18 = load i32, i32* %7
%19 = load i8*, i8** %4
%20 = load i16, i16* %5
%21 = call i32 @rlConnect(i32 %18, i8* %19, i16 signext %20)
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %29
24: ; preds = %12
%25 = load i32, i32* %7
%26 = call i32 @rlClose(i32 %25)
%27 = load i32, i32* %6
%28 = call i32 @sleep(i32 %27)
br label %29
29: ; preds = %24, %12
br label %9
30: ; preds = %9
%31 = load i32, i32* %7
ret i32 %31
}

LLVM IR (-O2):
define i32 @rlWaitForConnection(i8* %0, i16 signext %1, i32 %2) {
%4 = tail call i32 @rlOpen(i16 signext %1)
%5 = tail call i32 @rlIsValidSocket(i32 %4)
%6 = tail call i32 @assert(i32 %5)
%7 = tail call i32 @rlConnect(i32 %4, i8* %0, i16 signext %1)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %18
9: ; preds = %3, %9
%10 = phi i32 [ %13, %9 ], [ %4, %3 ]
%11 = tail call i32 @rlClose(i32 %10)
%12 = tail call i32 @sleep(i32 %2)
%13 = tail call i32 @rlOpen(i16 signext %1)
%14 = tail call i32 @rlIsValidSocket(i32 %13)
%15 = tail call i32 @assert(i32 %14)
%16 = tail call i32 @rlConnect(i32 %13, i8* %0, i16 signext %1)
%17 = icmp eq i32 %16, -1
br i1 %17, label %9, label %18
18: ; preds = %9, %3
%19 = phi i32 [ %4, %3 ], [ %13, %9 ]
ret i32 %19
}