#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 */
scalar_t__ EINTR;
scalar_t__ errno;
int send(int, void *, size_t, int);
int gtm_send(int socket, void *buffer, size_t length, int flags) {
  int res;
  do {
    res = send(socket, buffer, length, flags);
  } while (-1 == res && EINTR == errno);
  return (res);
}


x86 assembly (clang, -O0):
<gtm_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1030 <send@plt>
mov    %eax,-0x20(%rbp)
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    -0x20(%rbp),%ecx
mov    %al,-0x21(%rbp)
jne    1169 <gtm_send+0x59>
mov    0x2e82(%rip),%rax
mov    (%rax),%rax
mov    0x2e80(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1126 <gtm_send+0x16>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gtm_send>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %edi,%ebx
mov    0x2eab(%rip),%r12
mov    0x2eac(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1030 <send@plt>
cmp    $0xffffffff,%eax
jne    115f <gtm_send+0x4f>
mov    0x0(%r13),%rcx
cmp    %rcx,(%r12)
je     1140 <gtm_send+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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