#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 tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVTIMEO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(struct timeval *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, void const *,
                      int);
void set_rcvtimeo_timeout(int fd) {
  struct timeval timeout;
  memset(&timeout, 0, sizeof(struct timeval));
  timeout.tv_sec = (100 / 1000);
  timeout.tv_usec = (100 % 1000) * 1000;
  if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (const void *)&timeout,
                 sizeof(struct timeval)) < 0) {
    perror("setsockopt SO_RCVTIMEO");
    close(fd);
  }
}


x86 assembly (clang, -O0):
<set_rcvtimeo_timeout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x186a0,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
mov    0x2e5c(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    11ab <set_rcvtimeo_timeout+0x6b>
lea    0xe62(%rip),%rdi
call   1060 <perror@plt>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_rcvtimeo_timeout>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
movabs $0x186a000000000,%rax
mov    %rax,(%rsp)
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    %rbx,%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
js     1193 <set_rcvtimeo_timeout+0x53>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe66(%rip),%rdi
call   1060 <perror@plt>
mov    %ebp,%edi
call   1050 <close@plt>
jmp    118c <set_rcvtimeo_timeout+0x4c>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@.str = [23 x i8] c"setsockopt SO_RCVTIMEO\00"
define void @set_rcvtimeo_timeout(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
store i32 %0, i32* %2
%4 = call i32 @memset(%struct.timeval* %3, i32 0, i32 8)
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
store i32 0, i32* %5
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
store i32 100000, i32* %6
%7 = load i32, i32* %2
%8 = load i32, i32* @SOL_SOCKET
%9 = load i32, i32* @SO_RCVTIMEO
%10 = bitcast %struct.timeval* %3 to i8*
%11 = call i64 @setsockopt(i32 %7, i32 %8, i32 %9, i8* %10, i32 8)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %1
%14 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* %2
%16 = call i32 @close(i32 %15)
br label %17
17: ; preds = %13, %1
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@.str = [23 x i8] c"setsockopt SO_RCVTIMEO\00"
define void @set_rcvtimeo_timeout(i32 %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = call i32 @memset(%struct.timeval* %2, i32 0, i32 8)
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
store i32 0, i32* %5
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
store i32 100000, i32* %6
%7 = load i32, i32* @SOL_SOCKET
%8 = load i32, i32* @SO_RCVTIMEO
%9 = call i64 @setsockopt(i32 %0, i32 %7, i32 %8, i8* %3, i32 8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @close(i32 %0)
br label %14
14: ; preds = %11, %1
ret void
}