#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*/ tv;
struct timeval {
  short tv_sec;
  short tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVTIMEO;
int /*<<< orphan*/ perror(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, struct timeval *,
               int);
int set_rtmout(int sockfd, short sec, short usec) {
  struct timeval tv;
  int rc = 0;
  tv.tv_sec = sec;
  tv.tv_usec = usec;
  rc = setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
  if (-1 == rc) {
    perror("setsockopt SO_RCVTIMEIO");
  }
  return rc;
}


x86 assembly (clang, -O0):
<set_rtmout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dx,%ax
mov    %si,%cx
mov    %edi,-0x4(%rbp)
mov    %cx,-0x6(%rbp)
mov    %ax,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x6(%rbp),%ax
mov    %ax,-0x10(%rbp)
mov    -0x8(%rbp),%ax
mov    %ax,-0xe(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
mov    0x2e75(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    1191 <set_rtmout+0x71>
lea    0xe74(%rip),%rdi
call   1040 <perror@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_rtmout>:
push   %rbx
sub    $0x10,%rsp
mov    %si,0x8(%rsp)
mov    %dx,0xa(%rsp)
mov    0x2eb2(%rip),%rax
mov    (%rax),%esi
mov    0x2e99(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     1160 <set_rtmout+0x40>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe99(%rip),%rdi
call   1040 <perror@plt>
jmp    1158 <set_rtmout+0x38>

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

LLVM IR (-O2):
%struct.timeval = type { i16, i16 }
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@.str = [24 x i8] c"setsockopt SO_RCVTIMEIO\00"
define i32 @set_rtmout(i32 %0, i16 signext %1, i16 signext %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 i16 %1, i16* %6
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
store i16 %2, i16* %7
%8 = load i32, i32* @SOL_SOCKET
%9 = load i32, i32* @SO_RCVTIMEO
%10 = call i32 @setsockopt(i32 %0, i32 %8, i32 %9, %struct.timeval* %4, i32 4)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %3
ret i32 %10
}