#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 */
struct sockaddr {
  int dummy;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ LOG_ERR;
int connect(int, struct sockaddr const *, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ strerror(scalar_t__);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int Connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen) {
  ssize_t ret;
restart_connect:
  if ((ret = connect(sockfd, serv_addr, addrlen)) == -1) {
    if (errno == EINTR) {
      goto restart_connect;
    }
    syslog(LOG_ERR, "connect: %s", strerror(errno));
  }
  return ret;
}


x86 assembly (clang, -O0):
<Connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <connect@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    11a8 <Connect+0x78>
mov    0x2e7c(%rip),%rax
mov    (%rax),%rax
mov    0x2e6a(%rip),%rcx
cmp    (%rcx),%rax
jne    117c <Connect+0x4c>
jmp    1142 <Connect+0x12>
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e51(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%edx
lea    0xe5d(%rip),%rsi
call   1030 <syslog@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Connect>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x2e96(%rip),%r12
mov    0x2e87(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1040 <connect@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    119c <Connect+0x6c>
mov    (%r12),%rdi
cmp    0x0(%r13),%rdi
je     1160 <Connect+0x30>
mov    0x2e43(%rip),%rax
mov    (%rax),%ebp
call   1050 <strerror@plt>
lea    0xe6d(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
call   1030 <syslog@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@LOG_ERR = global i32 0
@.str = [12 x i8] c"connect: %s\00"
define i32 @Connect(i32 %0, %struct.sockaddr* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store %struct.sockaddr* %1, %struct.sockaddr** %5
store i32 %2, i32* %6
br label %8
8: ; preds = %18, %3
%9 = load i32, i32* %4
%10 = load %struct.sockaddr*, %struct.sockaddr** %5
%11 = load i32, i32* %6
%12 = call i32 @connect(i32 %9, %struct.sockaddr* %10, i32 %11)
store i32 %12, i32* %7
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %24
14: ; preds = %8
%15 = load i64, i64* @errno
%16 = load i64, i64* @EINTR
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %14
br label %8
19: ; preds = %14
%20 = load i32, i32* @LOG_ERR
%21 = load i64, i64* @errno
%22 = call i32 @strerror(i64 %21)
%23 = call i32 @syslog(i32 %20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %19, %8
%25 = load i32, i32* %7
ret i32 %25
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@LOG_ERR = global i32 0
@.str = [12 x i8] c"connect: %s\00"
define i32 @Connect(i32 %0, %struct.sockaddr* %1, i32 %2) {
br label %4
4: ; preds = %7, %3
%5 = tail call i32 @connect(i32 %0, %struct.sockaddr* %1, i32 %2)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %15
7: ; preds = %4
%8 = load i64, i64* @errno
%9 = load i64, i64* @EINTR
%10 = icmp eq i64 %8, %9
br i1 %10, label %4, label %11
11: ; preds = %7
%12 = load i32, i32* @LOG_ERR
%13 = tail call i32 @strerror(i64 %8)
%14 = tail call i32 @syslog(i32 %12, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %4, %11
ret i32 %5
}