#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*/ AF_INET;
int ReconnectSock(int, char *, int, int);
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int ConnectToHost(char *Host, int Port, int Flags) {
  int sock, result;
  sock = socket(AF_INET, SOCK_STREAM, 0);
  if (sock < 0)
    return (-1);
  result = ReconnectSock(sock, Host, Port, Flags);
  if (result == -1) {
    close(sock);
    return (-1);
  }
  return (sock);
}


x86 assembly (clang, -O0):
<ConnectToHost>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    0x2e9f(%rip),%rax
mov    (%rax),%edi
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1174 <ConnectToHost+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ad <ConnectToHost+0x7d>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1040 <ReconnectSock@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    11a7 <ConnectToHost+0x77>
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ad <ConnectToHost+0x7d>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ConnectToHost>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%r12
mov    0x2ea0(%rip),%rax
mov    (%rax),%edi
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <socket@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
js     1185 <ConnectToHost+0x55>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r12,%rsi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1040 <ReconnectSock@plt>
cmp    $0xffffffff,%eax
je     117e <ConnectToHost+0x4e>
mov    %ebx,%ebp
jmp    1185 <ConnectToHost+0x55>
mov    %ebx,%edi
call   1030 <close@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
define i32 @ConnectToHost(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 -1, i32* %4
br label %29
16: ; preds = %3
%17 = load i32, i32* %8
%18 = load i8*, i8** %5
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = call i32 @ReconnectSock(i32 %17, i8* %18, i32 %19, i32 %20)
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %16
%25 = load i32, i32* %8
%26 = call i32 @close(i32 %25)
store i32 -1, i32* %4
br label %29
27: ; preds = %16
%28 = load i32, i32* %8
store i32 %28, i32* %4
br label %29
29: ; preds = %27, %24, %15
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
define i32 @ConnectToHost(i8* %0, i32 %1, i32 %2) {
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_STREAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %3
%9 = tail call i32 @ReconnectSock(i32 %6, i8* %0, i32 %1, i32 %2)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @close(i32 %6)
br label %13
13: ; preds = %8, %3, %11
%14 = phi i32 [ -1, %11 ], [ -1, %3 ], [ %6, %8 ]
ret i32 %14
}