#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 */
typedef int /*<<< orphan*/ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ TCP_NODELAY;
int errno;
int /*<<< orphan*/ send(int, void const *, size_t, int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              char *, int);
ssize_t send_with_flush(int sockfd, const void *buf, size_t len, int flags) {
  int flag, err;
  ssize_t wr;
  flag = 1;
  setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int));
  wr = send(sockfd, buf, len, flags);
  err = errno;
  flag = 0;
  setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int));
  errno = err;
  return wr;
}


x86 assembly (clang, -O0):
<send_with_flush>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
mov    0x2e98(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1040 <send@plt>
mov    %eax,-0x28(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
mov    0x2e4b(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x24(%rbp),%ecx
mov    0x2e18(%rip),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_with_flush>:
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
movl   $0x1,0x4(%rsp)
mov    0x2e9b(%rip),%r13
mov    0x0(%r13),%esi
mov    0x2e98(%rip),%r12
mov    (%r12),%edx
lea    0x4(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1040 <send@plt>
mov    %eax,%r15d
mov    0x2e52(%rip),%r14
mov    (%r14),%ebp
movl   $0x0,0x4(%rsp)
mov    0x0(%r13),%esi
mov    (%r12),%edx
mov    %ebx,%edi
lea    0x4(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %ebp,(%r14)
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@IPPROTO_TCP = global i32 0
@TCP_NODELAY = global i32 0
@errno = global i32 0
define i32 @send_with_flush(i32 %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32 %3, i32* %8
store i32 1, i32* %9
%12 = load i32, i32* %5
%13 = load i32, i32* @IPPROTO_TCP
%14 = load i32, i32* @TCP_NODELAY
%15 = bitcast i32* %9 to i8*
%16 = call i32 @setsockopt(i32 %12, i32 %13, i32 %14, i8* %15, i32 4)
%17 = load i32, i32* %5
%18 = load i8*, i8** %6
%19 = load i64, i64* %7
%20 = load i32, i32* %8
%21 = call i32 @send(i32 %17, i8* %18, i64 %19, i32 %20)
store i32 %21, i32* %11
%22 = load i32, i32* @errno
store i32 %22, i32* %10
store i32 0, i32* %9
%23 = load i32, i32* %5
%24 = load i32, i32* @IPPROTO_TCP
%25 = load i32, i32* @TCP_NODELAY
%26 = bitcast i32* %9 to i8*
%27 = call i32 @setsockopt(i32 %23, i32 %24, i32 %25, i8* %26, i32 4)
%28 = load i32, i32* %10
store i32 %28, i32* @errno
%29 = load i32, i32* %11
ret i32 %29
}

LLVM IR (-O2):
@IPPROTO_TCP = global i32 0
@TCP_NODELAY = global i32 0
@errno = global i32 0
define i32 @send_with_flush(i32 %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
store i32 1, i32* %5
%7 = load i32, i32* @IPPROTO_TCP
%8 = load i32, i32* @TCP_NODELAY
%9 = call i32 @setsockopt(i32 %0, i32 %7, i32 %8, i8* %6, i32 4)
%10 = call i32 @send(i32 %0, i8* %1, i64 %2, i32 %3)
%11 = load i32, i32* @errno
store i32 0, i32* %5
%12 = load i32, i32* @IPPROTO_TCP
%13 = load i32, i32* @TCP_NODELAY
%14 = call i32 @setsockopt(i32 %0, i32 %12, i32 %13, i8* %6, i32 4)
store i32 %11, i32* @errno
ret i32 %10
}