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

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVTIMEO;
int /*<<< orphan*/ SO_SNDTIMEO;
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, struct timeval *,
               int);
int set_txrx_timeouts(int fd) {
  struct timeval t;
  socklen_t optlen;
  memset((void *)&t, 0, sizeof(t));
  t.tv_sec = 180;
  t.tv_usec = 0;
  optlen = sizeof(t);
  if (-1 == setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &t, optlen)) {
    return -14;
  }
  if (-1 == setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &t, optlen)) {
    return -14;
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_txrx_timeouts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
movl   $0xb4,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x10,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
mov    0x2e8c(%rip),%rax
mov    (%rax),%edx
mov    -0x1c(%rbp),%r8d
lea    -0x18(%rbp),%rcx
call   1030 <setsockopt@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    118e <set_txrx_timeouts+0x6e>
movl   $0xfffffff2,-0x4(%rbp)
jmp    11d2 <set_txrx_timeouts+0xb2>
mov    -0x8(%rbp),%edi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
mov    0x2e2f(%rip),%rax
mov    (%rax),%edx
mov    -0x1c(%rbp),%r8d
lea    -0x18(%rbp),%rcx
call   1030 <setsockopt@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11cb <set_txrx_timeouts+0xab>
movl   $0xfffffff2,-0x4(%rbp)
jmp    11d2 <set_txrx_timeouts+0xb2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_txrx_timeouts>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
lea    0x8(%rsp),%r14
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
movl   $0xb4,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x2e86(%rip),%r15
mov    (%r15),%esi
mov    0x2e8c(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    %r14,%rcx
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     11a6 <set_txrx_timeouts+0x86>
mov    (%r15),%esi
mov    0x2e4b(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    %ebp,%edi
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
mov    $0xfffffff2,%eax
cmove  %eax,%ebx
jmp    11ab <set_txrx_timeouts+0x8b>
mov    $0xfffffff2,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@SOL_SOCKET = global i32 0
@SO_SNDTIMEO = global i32 0
@SO_RCVTIMEO = global i32 0
define i32 @set_txrx_timeouts(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.timeval
%5 = alloca i32
store i32 %0, i32* %3
%6 = bitcast %struct.timeval* %4 to i8*
%7 = call i32 @memset(i8* %6, i32 0, i32 16)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
store i32 180, i32* %8
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
store i64 0, i64* %9
store i32 16, i32* %5
%10 = load i32, i32* %3
%11 = load i32, i32* @SOL_SOCKET
%12 = load i32, i32* @SO_SNDTIMEO
%13 = load i32, i32* %5
%14 = call i32 @setsockopt(i32 %10, i32 %11, i32 %12, %struct.timeval* %4, i32 %13)
%15 = icmp eq i32 -1, %14
br i1 %15, label %16, label %17
16: ; preds = %1
store i32 -14, i32* %2
br label %26
17: ; preds = %1
%18 = load i32, i32* %3
%19 = load i32, i32* @SOL_SOCKET
%20 = load i32, i32* @SO_RCVTIMEO
%21 = load i32, i32* %5
%22 = call i32 @setsockopt(i32 %18, i32 %19, i32 %20, %struct.timeval* %4, i32 %21)
%23 = icmp eq i32 -1, %22
br i1 %23, label %24, label %25
24: ; preds = %17
store i32 -14, i32* %2
br label %26
25: ; preds = %17
store i32 0, i32* %2
br label %26
26: ; preds = %25, %24, %16
%27 = load i32, i32* %2
ret i32 %27
}

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