#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;
};

/* Variables and functions */
scalar_t__ EINTR;
int connect(int, struct sockaddr *, size_t);
scalar_t__ errno;
int gtm_connect(int socket, struct sockaddr *address, size_t address_len) {
  int res;
  do {
    res = connect(socket, address, address_len);
  } while (-1 == res && EINTR == errno);
  return (res);
}


x86 assembly (clang, -O0):
<gtm_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <connect@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    -0x1c(%rbp),%ecx
mov    %al,-0x1d(%rbp)
jne    1163 <gtm_connect+0x53>
mov    0x2e88(%rip),%rax
mov    (%rax),%rax
mov    0x2e86(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1123 <gtm_connect+0x13>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gtm_connect>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2eb1(%rip),%r15
mov    0x2eb2(%rip),%r12
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <connect@plt>
cmp    $0xffffffff,%eax
jne    114b <gtm_connect+0x3b>
mov    (%r12),%rcx
cmp    %rcx,(%r15)
je     1130 <gtm_connect+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@EINTR = global i64 0
@errno = global i64 0
define i32 @gtm_connect(i32 %0, %struct.sockaddr* %1, i64 %2) {
br label %4
4: ; preds = %4, %3
%5 = tail call i32 @connect(i32 %0, %struct.sockaddr* %1, i64 %2)
%6 = icmp eq i32 %5, -1
%7 = load i64, i64* @EINTR
%8 = load i64, i64* @errno
%9 = icmp eq i64 %7, %8
%10 = select i1 %6, i1 %9, i1 false
br i1 %10, label %4, label %11
11: ; preds = %4
ret i32 %5
}