#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 */
struct timeval {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, void *,
               int /*<<< orphan*/);
int htxcmd_set_socket_option(int socket_fd, struct timeval *timeout) {
  int result;
  socklen_t option_length = 0;
  result = setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, (void *)timeout,
                      option_length);
  if (result == -1) {
    perror("ERROR: while setting socket options. Exiting...");
    exit(1);
  }
  return result;
}


x86 assembly (clang, -O0):
<htxcmd_set_socket_option>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
mov    0x2e7f(%rip),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    118b <htxcmd_set_socket_option+0x5b>
lea    0xe84(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<htxcmd_set_socket_option>:
push   %rax
mov    %rsi,%rcx
mov    0x2ead(%rip),%rax
mov    (%rax),%esi
mov    0x2e94(%rip),%rax
mov    (%rax),%edx
xor    %r8d,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1155 <htxcmd_set_socket_option+0x25>
pop    %rcx
ret
lea    0xea4(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
%struct.timeval = type { i32 }
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str = [48 x i8] c"ERROR: while setting socket options. Exiting...\00"
define i32 @htxcmd_set_socket_option(i32 %0, %struct.timeval* %1) {
%3 = load i32, i32* @SOL_SOCKET
%4 = load i32, i32* @SO_REUSEADDR
%5 = bitcast %struct.timeval* %1 to i8*
%6 = tail call i32 @setsockopt(i32 %0, i32 %3, i32 %4, i8* %5, i32 0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
ret i32 %6
}