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

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVTIMEO;
int /*<<< orphan*/ perror(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char const *, int);
int multicast_set_socket_timeout(int sockfd, time_t sec, suseconds_t usec) {
  struct timeval sock_timeout;
  sock_timeout.tv_sec = sec;
  sock_timeout.tv_usec = usec;
  int ret = 0;
  ret = setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (const char *)&sock_timeout,
                   sizeof(struct timeval));
  if (ret < 0)
    perror("setting socket timeout");
  return ret;
}


x86 assembly (clang, -O0):
<multicast_set_socket_timeout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e9a(%rip),%rax
mov    (%rax),%esi
mov    0x2e81(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1181 <multicast_set_socket_timeout+0x61>
lea    0xe84(%rip),%rdi
call   1040 <perror@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multicast_set_socket_timeout>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,0xc(%rsp)
mov    %edx,0x8(%rsp)
mov    0x2eb4(%rip),%rax
mov    (%rax),%esi
mov    0x2e9b(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
mov    %eax,%ebx
test   %eax,%eax
js     115d <multicast_set_socket_timeout+0x3d>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe9c(%rip),%rdi
call   1040 <perror@plt>
jmp    1155 <multicast_set_socket_timeout+0x35>

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

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@.str = [23 x i8] c"setting socket timeout\00"
define i32 @multicast_set_socket_timeout(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 1
store i32 %1, i32* %6
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
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 slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %3
ret i32 %10
}