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

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVTIMEO;
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int setReciveTimeout(int sock, int sec, int usec) {
  struct timeval timeout;
  timeout.tv_sec = sec;
  timeout.tv_usec = usec;
  if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout,
                 sizeof(timeout)) == -1) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<setReciveTimeout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2eb1(%rip),%rax
mov    (%rax),%esi
mov    0x2e98(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1166 <setReciveTimeout+0x56>
movl   $0xffffffff,-0x4(%rbp)
jmp    116d <setReciveTimeout+0x5d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setReciveTimeout>:
push   %rax
mov    %esi,(%rsp)
mov    %edx,0x4(%rsp)
mov    0x2ec9(%rip),%rax
mov    (%rax),%esi
mov    0x2eb0(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
xor    %ecx,%ecx
cmp    $0xffffffff,%eax
sete   %cl
neg    %ecx
mov    %ecx,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
define i32 @setReciveTimeout(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %4 to i8*
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
store i32 %1, i32* %6
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
store i32 %2, i32* %7
%8 = load i32, i32* @SOL_SOCKET
%9 = load i32, i32* @SO_RCVTIMEO
%10 = call i32 @setsockopt(i32 %0, i32 %8, i32 %9, i8* %5, i32 8)
%11 = icmp eq i32 %10, -1
%12 = sext i1 %11 to i32
ret i32 %12
}