#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 */
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ LOG(char *, int /*<<< orphan*/);
int /*<<< orphan*/ TCP_NODELAY;
int /*<<< orphan*/ errno;
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int set_no_delay(int fd) {
  int flag = 1;
  if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)) <
      0) {
    LOG("could not set TCP_NODELAY on socket (%s)\n", strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_no_delay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e94(%rip),%rax
mov    (%rax),%esi
mov    0x2e93(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    1198 <set_no_delay+0x68>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %eax,%esi
lea    0xe79(%rip),%rdi
call   1040 <LOG@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    119f <set_no_delay+0x6f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_no_delay>:
push   %rax
movl   $0x1,0x4(%rsp)
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
mov    0x2e9f(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
js     1167 <set_no_delay+0x37>
pop    %rcx
ret
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe84(%rip),%rdi
mov    %eax,%esi
call   1040 <LOG@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@IPPROTO_TCP = global i32 0
@TCP_NODELAY = global i32 0
@.str = [42 x i8] c"could not set TCP_NODELAY on socket (%s)\0A\00"
@errno = global i32 0
define i32 @set_no_delay(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 1, i32* %4
%5 = load i32, i32* %3
%6 = load i32, i32* @IPPROTO_TCP
%7 = load i32, i32* @TCP_NODELAY
%8 = bitcast i32* %4 to i8*
%9 = call i64 @setsockopt(i32 %5, i32 %6, i32 %7, i8* %8, i32 4)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = load i32, i32* @errno
%13 = call i32 @strerror(i32 %12)
%14 = call i32 @LOG(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 -1, i32* %2
br label %16
15: ; preds = %1
store i32 0, i32* %2
br label %16
16: ; preds = %15, %11
%17 = load i32, i32* %2
ret i32 %17
}

LLVM IR (-O2):
@IPPROTO_TCP = global i32 0
@TCP_NODELAY = global i32 0
@.str = [42 x i8] c"could not set TCP_NODELAY on socket (%s)\0A\00"
@errno = global i32 0
define i32 @set_no_delay(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%4 = load i32, i32* @IPPROTO_TCP
%5 = load i32, i32* @TCP_NODELAY
%6 = call i64 @setsockopt(i32 %0, i32 %4, i32 %5, i8* %3, i32 4)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i32, i32* @errno
%10 = call i32 @strerror(i32 %9)
%11 = call i32 @LOG(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %1, %8
%13 = phi i32 [ -1, %8 ], [ 0, %1 ]
ret i32 %13
}