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

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_SNDTIMEO;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char const *,
                      int);
char *strerror(int /*<<< orphan*/);
void http_socket_sendtimeout(int sk, int timeout) {
  struct timeval tv;
  tv.tv_sec = timeout;
  tv.tv_usec = 0;
  if (setsockopt(sk, SOL_SOCKET, SO_SNDTIMEO, (const char *)&tv, sizeof(tv)) !=
      0) {
    printf("setsockopt SO_SNDTIMEO failure %s\n", strerror(errno));
  }
}


x86 assembly (clang, -O0):
<http_socket_sendtimeout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
mov    0x2e91(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
je     1197 <http_socket_sendtimeout+0x67>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rsi
lea    0xe6e(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_socket_sendtimeout>:
sub    $0x18,%rsp
mov    %esi,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
mov    0x2e9f(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
je     1185 <http_socket_sendtimeout+0x55>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe83(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@SOL_SOCKET = global i32 0
@SO_SNDTIMEO = global i32 0
@.str = [35 x i8] c"setsockopt SO_SNDTIMEO failure %s\0A\00"
@errno = global i32 0
define void @http_socket_sendtimeout(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timeval
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
store i32 %6, i32* %7
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
store i64 0, i64* %8
%9 = load i32, i32* %3
%10 = load i32, i32* @SOL_SOCKET
%11 = load i32, i32* @SO_SNDTIMEO
%12 = bitcast %struct.timeval* %5 to i8*
%13 = call i64 @setsockopt(i32 %9, i32 %10, i32 %11, i8* %12, i32 16)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %15, %2
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@SOL_SOCKET = global i32 0
@SO_SNDTIMEO = global i32 0
@.str = [35 x i8] c"setsockopt SO_SNDTIMEO failure %s\0A\00"
@errno = global i32 0
define void @http_socket_sendtimeout(i32 %0, i32 %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
store i32 %1, i32* %5
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
store i64 0, i64* %6
%7 = load i32, i32* @SOL_SOCKET
%8 = load i32, i32* @SO_SNDTIMEO
%9 = call i64 @setsockopt(i32 %0, i32 %7, i32 %8, i8* %4, i32 16)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %11, %2
ret void
}