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

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVTIMEO;
int /*<<< orphan*/ SO_SNDTIMEO;
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              char *, int);
void set_socket_timeout(int *fd) {
  struct timeval timeout;
  timeout.tv_sec = 1;
  timeout.tv_usec = 0;
  setsockopt(*fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout));
  setsockopt(*fd, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout));
}


x86 assembly (clang, -O0):
<set_socket_timeout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
mov    0x2e8f(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
mov    0x2e88(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_socket_timeout>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movl   $0x1,(%rsp)
movq   $0x0,0x8(%rsp)
mov    (%rdi),%edi
mov    0x2eab(%rip),%r15
mov    (%r15),%esi
mov    0x2e91(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%r14
mov    %r14,%rcx
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
mov    (%rbx),%edi
mov    (%r15),%esi
mov    0x2e92(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rcx
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@SO_SNDTIMEO = global i32 0
define void @set_socket_timeout(i32* %0) {
%2 = alloca i32*
%3 = alloca %struct.timeval
store i32* %0, i32** %2
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
store i32 1, i32* %4
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
store i64 0, i64* %5
%6 = load i32*, i32** %2
%7 = load i32, i32* %6
%8 = load i32, i32* @SOL_SOCKET
%9 = load i32, i32* @SO_RCVTIMEO
%10 = bitcast %struct.timeval* %3 to i8*
%11 = call i32 @setsockopt(i32 %7, i32 %8, i32 %9, i8* %10, i32 16)
%12 = load i32*, i32** %2
%13 = load i32, i32* %12
%14 = load i32, i32* @SOL_SOCKET
%15 = load i32, i32* @SO_SNDTIMEO
%16 = bitcast %struct.timeval* %3 to i8*
%17 = call i32 @setsockopt(i32 %13, i32 %14, i32 %15, i8* %16, i32 16)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@SO_SNDTIMEO = global i32 0
define void @set_socket_timeout(i32* nocapture %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
store i32 1, i32* %4
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
store i64 0, i64* %5
%6 = load i32, i32* %0
%7 = load i32, i32* @SOL_SOCKET
%8 = load i32, i32* @SO_RCVTIMEO
%9 = call i32 @setsockopt(i32 %6, i32 %7, i32 %8, i8* %3, i32 16)
%10 = load i32, i32* %0
%11 = load i32, i32* @SOL_SOCKET
%12 = load i32, i32* @SO_SNDTIMEO
%13 = call i32 @setsockopt(i32 %10, i32 %11, i32 %12, i8* %3, i32 16)
ret void
}