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

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVTIMEO;
int /*<<< orphan*/ SO_SNDTIMEO;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, struct timeval *,
               int);
int /*<<< orphan*/ stderr;
int socket_set_timeout(int sockfd, float secs) {
  int res;
  struct timeval tv;
  float scaled = 1000000.0f * secs;
  tv.tv_sec = scaled / 1000000;
  tv.tv_usec = scaled - (float)(tv.tv_sec * 1000000);
  res = setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
  if (res != -1)
    res = setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
  if (res == -1)
    fprintf(stderr, "archive: failed to set timeout on socket\n");
  return res == 0;
}


x86 assembly (clang, -O0):
<socket_set_timeout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movss  %xmm0,-0x8(%rbp)
movss  0xec8(%rip),%xmm0
mulss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  0xeb1(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x1c(%rbp),%xmm1
movss  -0x18(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  0xe89(%rip),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
je     11dc <socket_set_timeout+0xbc>
mov    -0x4(%rbp),%edi
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
mov    0x2e28(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11fb <socket_set_timeout+0xdb>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
lea    0xe0e(%rip),%rsi
call   1040 <fprintf@plt>
cmpl   $0x0,-0xc(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_set_timeout>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
movss  0xed2(%rip),%xmm1
mulss  %xmm1,%xmm0
movaps %xmm0,%xmm2
divss  %xmm1,%xmm2
movss  %xmm2,(%rsp)
mulss  %xmm1,%xmm2
subss  %xmm2,%xmm0
movss  %xmm0,0x4(%rsp)
mov    0x2e8d(%rip),%r14
mov    (%r14),%esi
mov    0x2e73(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1193 <socket_set_timeout+0x73>
mov    (%r14),%esi
mov    0x2e74(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rcx
mov    %ebx,%edi
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    11ad <socket_set_timeout+0x8d>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { float, float }
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@SO_SNDTIMEO = global i32 0
@stderr = global i32 0
@.str = [42 x i8] c"archive: failed to set timeout on socket\0A\00"
define i32 @socket_set_timeout(i32 %0, float %1) {
%3 = alloca i32
%4 = alloca float
%5 = alloca i32
%6 = alloca %struct.timeval
%7 = alloca float
store i32 %0, i32* %3
store float %1, float* %4
%8 = load float, float* %4
%9 = fmul float 1.000000e+06, %8
store float %9, float* %7
%10 = load float, float* %7
%11 = fdiv float %10, 1.000000e+06
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
store float %11, float* %12
%13 = load float, float* %7
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%15 = load float, float* %14
%16 = fneg float %15
%17 = call float @llvm.fmuladd.f32(float %16, float 1.000000e+06, float %13)
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
store float %17, float* %18
%19 = load i32, i32* %3
%20 = load i32, i32* @SOL_SOCKET
%21 = load i32, i32* @SO_RCVTIMEO
%22 = call i32 @setsockopt(i32 %19, i32 %20, i32 %21, %struct.timeval* %6, i32 8)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = icmp ne i32 %23, -1
br i1 %24, label %25, label %30
25: ; preds = %2
%26 = load i32, i32* %3
%27 = load i32, i32* @SOL_SOCKET
%28 = load i32, i32* @SO_SNDTIMEO
%29 = call i32 @setsockopt(i32 %26, i32 %27, i32 %28, %struct.timeval* %6, i32 8)
store i32 %29, i32* %5
br label %30
30: ; preds = %25, %2
%31 = load i32, i32* %5
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %36
36: ; preds = %33, %30
%37 = load i32, i32* %5
%38 = icmp eq i32 %37, 0
%39 = zext i1 %38 to i32
ret i32 %39
}

LLVM IR (-O2):
%struct.timeval = type { float, float }
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@SO_SNDTIMEO = global i32 0
@stderr = global i32 0
@.str = [42 x i8] c"archive: failed to set timeout on socket\0A\00"
define i32 @socket_set_timeout(i32 %0, float %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = fmul float %1, 1.000000e+06
%6 = fdiv float %5, 1.000000e+06
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
store float %6, float* %7
%8 = fneg float %6
%9 = tail call float @llvm.fmuladd.f32(float %8, float 1.000000e+06, float %5)
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
store float %9, float* %10
%11 = load i32, i32* @SOL_SOCKET
%12 = load i32, i32* @SO_RCVTIMEO
%13 = call i32 @setsockopt(i32 %0, i32 %11, i32 %12, %struct.timeval* %3, i32 8)
%14 = icmp eq i32 %13, -1
br i1 %14, label %20, label %15
15: ; preds = %2
%16 = load i32, i32* @SOL_SOCKET
%17 = load i32, i32* @SO_SNDTIMEO
%18 = call i32 @setsockopt(i32 %0, i32 %16, i32 %17, %struct.timeval* %3, i32 8)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %2, %15
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %20, %15
%24 = phi i32 [ -1, %20 ], [ %18, %15 ]
%25 = icmp eq i32 %24, 0
%26 = zext i1 %25 to i32
ret i32 %26
}