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

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_TCP;
int getsockopt(int, int /*<<< orphan*/, int, int *, int *);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int, int *, int);
void x_set_sock_no_delay(int s) {
  int opt;
  socklen_t optlen;
  optlen = sizeof opt;
  if (getsockopt(s, IPPROTO_TCP, 1, &opt, &optlen) == -1) {
    return;
  }
  if (opt == 1) {
    return;
  }
  opt = 1;
  setsockopt(s, IPPROTO_TCP, 1, &opt, sizeof(opt));
  return;
}


x86 assembly (clang, -O0):
<x_set_sock_no_delay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x4,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2eac(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
lea    -0x8(%rbp),%rcx
lea    -0xc(%rbp),%r8
call   1040 <getsockopt@plt>
cmp    $0xffffffff,%eax
jne    115e <x_set_sock_no_delay+0x3e>
jmp    1194 <x_set_sock_no_delay+0x74>
cmpl   $0x1,-0x8(%rbp)
jne    116d <x_set_sock_no_delay+0x4d>
jmp    1194 <x_set_sock_no_delay+0x74>
movl   $0x1,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
lea    -0x8(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<x_set_sock_no_delay>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
movl   $0x4,0x4(%rsp)
mov    0x2eb3(%rip),%r14
mov    (%r14),%esi
mov    %rsp,%rcx
lea    0x4(%rsp),%r8
mov    $0x1,%edx
call   1040 <getsockopt@plt>
cmp    $0xffffffff,%eax
je     1174 <x_set_sock_no_delay+0x54>
cmpl   $0x1,(%rsp)
je     1174 <x_set_sock_no_delay+0x54>
movl   $0x1,(%rsp)
mov    (%r14),%esi
mov    %rsp,%rcx
mov    %ebx,%edi
mov    $0x1,%edx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@IPPROTO_TCP = global i32 0
define void @x_set_sock_no_delay(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 4, i32* %4
%5 = load i32, i32* %2
%6 = load i32, i32* @IPPROTO_TCP
%7 = call i32 @getsockopt(i32 %5, i32 %6, i32 1, i32* %3, i32* %4)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %10
9: ; preds = %1
br label %18
10: ; preds = %1
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %10
br label %18
14: ; preds = %10
store i32 1, i32* %3
%15 = load i32, i32* %2
%16 = load i32, i32* @IPPROTO_TCP
%17 = call i32 @setsockopt(i32 %15, i32 %16, i32 1, i32* %3, i32 4)
br label %18
18: ; preds = %14, %13, %9
ret void
}

LLVM IR (-O2):
@IPPROTO_TCP = global i32 0
define void @x_set_sock_no_delay(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
store i32 4, i32* %3
%6 = load i32, i32* @IPPROTO_TCP
%7 = call i32 @getsockopt(i32 %0, i32 %6, i32 1, i32* %2, i32* %3)
%8 = icmp eq i32 %7, -1
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 1
%11 = select i1 %8, i1 true, i1 %10
br i1 %11, label %15, label %12
12: ; preds = %1
store i32 1, i32* %2
%13 = load i32, i32* @IPPROTO_TCP
%14 = call i32 @setsockopt(i32 %0, i32 %13, i32 1, i32* %2, i32 4)
br label %15
15: ; preds = %1, %12
ret void
}