#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*/ close(int);
int tcpconnect_accept_single(int);
int tcpconnect_start_multiple(char const *);
int tcpconnect_start_server(const char *port) {
  int stubfd = tcpconnect_start_multiple(port);
  if (stubfd < 0) {
    return -1;
  }
  int sockfd = tcpconnect_accept_single(stubfd);
  close(stubfd);
  if (sockfd < 0) {
    return -1;
  }
  return sockfd;
}


x86 assembly (clang, -O0):
<tcpconnect_start_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <tcpconnect_start_multiple@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    115e <tcpconnect_start_server+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    118d <tcpconnect_start_server+0x5d>
mov    -0x14(%rbp),%edi
call   1040 <tcpconnect_accept_single@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x0,-0x18(%rbp)
jge    1187 <tcpconnect_start_server+0x57>
movl   $0xffffffff,-0x4(%rbp)
jmp    118d <tcpconnect_start_server+0x5d>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcpconnect_start_server>:
push   %rbp
push   %rbx
push   %rax
call   1050 <tcpconnect_start_multiple@plt>
test   %eax,%eax
js     115a <tcpconnect_start_server+0x2a>
mov    %eax,%ebx
mov    %eax,%edi
call   1040 <tcpconnect_accept_single@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1030 <close@plt>
test   %ebp,%ebp
mov    $0xffffffff,%eax
cmovns %ebp,%eax
jmp    115f <tcpconnect_start_server+0x2f>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @tcpconnect_start_server(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @tcpconnect_start_multiple(i8* %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %21
11: ; preds = %1
%12 = load i32, i32* %4
%13 = call i32 @tcpconnect_accept_single(i32 %12)
store i32 %13, i32* %5
%14 = load i32, i32* %4
%15 = call i32 @close(i32 %14)
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %11
store i32 -1, i32* %2
br label %21
19: ; preds = %11
%20 = load i32, i32* %5
store i32 %20, i32* %2
br label %21
21: ; preds = %19, %18, %10
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
define i32 @tcpconnect_start_server(i8* %0) {
%2 = tail call i32 @tcpconnect_start_multiple(i8* %0)
%3 = icmp slt i32 %2, 0
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = tail call i32 @tcpconnect_accept_single(i32 %2)
%6 = tail call i32 @close(i32 %2)
%7 = icmp sgt i32 %5, -1
%8 = select i1 %7, i32 %5, i32 -1
br label %9
9: ; preds = %1, %4
%10 = phi i32 [ %8, %4 ], [ -1, %1 ]
ret i32 %10
}