#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 timeval {
  int tv_sec;
  int /*<<< orphan*/ tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVTIMEO;
int /*<<< orphan*/ SO_SNDTIMEO;
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                      struct timeval *, int);
int settimeout(int fd) {
  struct timeval timeout = {.tv_sec = 10, .tv_usec = 0};
  if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &timeout,
                 sizeof(struct timeval)) != 0) {
    return -1;
  }
  if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout,
                 sizeof(struct timeval)) != 0) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<settimeout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    0xede(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2eb0(%rip),%rax
mov    (%rax),%esi
mov    0x2eb7(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
je     1160 <settimeout+0x50>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a1 <settimeout+0x91>
mov    -0x8(%rbp),%edi
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
mov    0x2e5d(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
je     119a <settimeout+0x8a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a1 <settimeout+0x91>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<settimeout>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
movq   $0xa,(%rsp)
mov    0x2ebb(%rip),%r14
mov    (%r14),%esi
mov    0x2ec1(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    116d <settimeout+0x5d>
mov    (%r14),%esi
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rcx
mov    %ebx,%edi
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
neg    %rax
sbb    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@__const.settimeout.timeout = %struct.timeval { i32 10, i32 0 }
@SOL_SOCKET = global i32 0
@SO_SNDTIMEO = global i32 0
@SO_RCVTIMEO = global i32 0
define i32 @settimeout(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.timeval
store i32 %0, i32* %3
%5 = bitcast %struct.timeval* %4 to i8*
%6 = load i32, i32* %3
%7 = load i32, i32* @SOL_SOCKET
%8 = load i32, i32* @SO_SNDTIMEO
%9 = call i64 @setsockopt(i32 %6, i32 %7, i32 %8, %struct.timeval* %4, i32 8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 -1, i32* %2
br label %20
12: ; preds = %1
%13 = load i32, i32* %3
%14 = load i32, i32* @SOL_SOCKET
%15 = load i32, i32* @SO_RCVTIMEO
%16 = call i64 @setsockopt(i32 %13, i32 %14, i32 %15, %struct.timeval* %4, i32 8)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %12
store i32 -1, i32* %2
br label %20
19: ; preds = %12
store i32 0, i32* %2
br label %20
20: ; preds = %19, %18, %11
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@SOL_SOCKET = global i32 0
@SO_SNDTIMEO = global i32 0
@SO_RCVTIMEO = global i32 0
define i32 @settimeout(i32 %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to %struct.timeval*
%4 = bitcast i64* %2 to i8*
store i64 10, i64* %2
%5 = load i32, i32* @SOL_SOCKET
%6 = load i32, i32* @SO_SNDTIMEO
%7 = call i64 @setsockopt(i32 %0, i32 %5, i32 %6, %struct.timeval* %3, i32 8)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load i32, i32* @SOL_SOCKET
%11 = load i32, i32* @SO_RCVTIMEO
%12 = call i64 @setsockopt(i32 %0, i32 %10, i32 %11, %struct.timeval* %3, i32 8)
%13 = icmp ne i64 %12, 0
%14 = sext i1 %13 to i32
br label %15
15: ; preds = %9, %1
%16 = phi i32 [ -1, %1 ], [ %14, %9 ]
ret i32 %16
}