#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 /*<<< orphan*/ socklen_t;

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ connect(int, struct sockaddr const *, int /*<<< orphan*/);
scalar_t__ errno;
int make_connection(int sock, const struct sockaddr *addr, socklen_t addrlen) {
  while (1) {
    if (connect(sock, addr, addrlen) == 0)
      return 0;
    if (errno != EINTR)
      return -1;
  }
}


x86 assembly (clang, -O0):
<make_connection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <connect@plt>
cmp    $0x0,%rax
jne    1147 <make_connection+0x37>
movl   $0x0,-0x4(%rbp)
jmp    1172 <make_connection+0x62>
mov    0x2e92(%rip),%rax
mov    (%rax),%rax
mov    0x2e80(%rip),%rcx
cmp    (%rcx),%rax
je     116d <make_connection+0x5d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1172 <make_connection+0x62>
jmp    1122 <make_connection+0x12>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_connection>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2eb9(%rip),%r15
mov    0x2eaa(%rip),%r12
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <connect@plt>
test   %rax,%rax
je     1152 <make_connection+0x42>
mov    (%r15),%rax
cmp    (%r12),%rax
je     1130 <make_connection+0x20>
mov    $0xffffffff,%eax
jmp    1154 <make_connection+0x44>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
define i32 @make_connection(i32 %0, %struct.sockaddr* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr*
%7 = alloca i32
store i32 %0, i32* %5
store %struct.sockaddr* %1, %struct.sockaddr** %6
store i32 %2, i32* %7
br label %8
8: ; preds = %3, %20
%9 = load i32, i32* %5
%10 = load %struct.sockaddr*, %struct.sockaddr** %6
%11 = load i32, i32* %7
%12 = call i64 @connect(i32 %9, %struct.sockaddr* %10, i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %8
store i32 0, i32* %4
br label %21
15: ; preds = %8
%16 = load i64, i64* @errno
%17 = load i64, i64* @EINTR
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 -1, i32* %4
br label %21
20: ; preds = %15
br label %8
21: ; preds = %19, %14
%22 = load i32, i32* %4
ret i32 %22
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
define i32 @make_connection(i32 %0, %struct.sockaddr* %1, i32 %2) {
br label %4
4: ; preds = %7, %3
%5 = tail call i64 @connect(i32 %0, %struct.sockaddr* %1, i32 %2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %11, label %7
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, %4
%12 = phi i32 [ 0, %4 ], [ -1, %7 ]
ret i32 %12
}