#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ timeout;
struct timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};

/* Variables and functions */
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVTIMEO;
int /*<<< orphan*/ SO_SNDTIMEO;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
void setup_publish_server(struct sockaddr_in *serv_addr, int *serverSocket,
                          char *ip_addr) {
  printf("Connecting to server "
         "\x1b[36m"
         "%s"
         "\x1b[0m"
         "...\n",
         ip_addr);
  memset((char *)serv_addr, 0, sizeof(&serv_addr));
  serv_addr->sin_family = PF_INET;
  serv_addr->sin_addr.s_addr = inet_addr(ip_addr);
  serv_addr->sin_port = htons(4001);
  if ((*serverSocket = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
    perror("Socket error.");
    exit(1);
  }
  struct timeval timeout;
  timeout.tv_sec = 5;
  timeout.tv_usec = 0;
  if (setsockopt(*serverSocket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout,
                 sizeof(timeout)) < 0) {
  }
  if (setsockopt(*serverSocket, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout,
                 sizeof(timeout)) < 0) {
  }
}


x86 assembly (clang, -O0):
<setup_publish_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe61(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x18(%rbp),%rdi
call   1070 <inet_addr@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    $0xfa1,%edi
call   1040 <htons@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
mov    0x2de0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    -0x10(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0x0,%eax
jge    1226 <setup_publish_server+0xa6>
lea    0xe0e(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movl   $0x5,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    0x2d9e(%rip),%rax
mov    (%rax),%esi
mov    0x2d7d(%rip),%rax
mov    (%rax),%edx
lea    -0x28(%rbp),%rcx
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    126b <setup_publish_server+0xeb>
jmp    126b <setup_publish_server+0xeb>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    0x2d68(%rip),%rax
mov    (%rax),%esi
mov    0x2d6f(%rip),%rax
mov    (%rax),%edx
lea    -0x28(%rbp),%rcx
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    12a1 <setup_publish_server+0x121>
jmp    12a1 <setup_publish_server+0x121>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_publish_server>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe65(%rip),%rdi
mov    %rdx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    0x2e07(%rip),%r12
mov    (%r12),%eax
mov    %eax,0x8(%rbx)
mov    %r15,%rdi
call   1070 <inet_addr@plt>
mov    %eax,0x4(%rbx)
mov    $0xfa1,%edi
call   1040 <htons@plt>
mov    %eax,(%rbx)
mov    (%r12),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,(%r14)
test   %eax,%eax
js     1252 <setup_publish_server+0xd2>
movl   $0x5,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x2dd6(%rip),%rbx
mov    (%rbx),%esi
mov    0x2db5(%rip),%rcx
mov    (%rcx),%edx
lea    0x8(%rsp),%r15
mov    %eax,%edi
mov    %r15,%rcx
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
mov    (%r14),%edi
mov    (%rbx),%esi
mov    0x2dba(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rcx
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdcc(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i64 }
@.str = [37 x i8] c"Connecting to server \1B[36m%s\1B[0m...\0A\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [14 x i8] c"Socket error.\00"
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@SO_SNDTIMEO = global i32 0
define void @setup_publish_server(%struct.sockaddr_in* %0, i32* %1, i8* %2) {
%4 = alloca %struct.sockaddr_in*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca %struct.timeval
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %6
%9 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%11 = bitcast %struct.sockaddr_in* %10 to i8*
%12 = call i32 @memset(i8* %11, i32 0, i32 8)
%13 = load i32, i32* @PF_INET
%14 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 2
store i32 %13, i32* %15
%16 = load i8*, i8** %6
%17 = call i32 @inet_addr(i8* %16)
%18 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 1
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
store i32 %17, i32* %20
%21 = call i32 @htons(i32 4001)
%22 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %22, i32 0, i32 0
store i32 %21, i32* %23
%24 = load i32, i32* @PF_INET
%25 = load i32, i32* @SOCK_DGRAM
%26 = call i32 @socket(i32 %24, i32 %25, i32 0)
%27 = load i32*, i32** %5
store i32 %26, i32* %27
%28 = icmp slt i32 %26, 0
br i1 %28, label %29, label %32
29: ; preds = %3
%30 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %3
%33 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
store i32 5, i32* %33
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
store i64 0, i64* %34
%35 = load i32*, i32** %5
%36 = load i32, i32* %35
%37 = load i32, i32* @SOL_SOCKET
%38 = load i32, i32* @SO_RCVTIMEO
%39 = bitcast %struct.timeval* %7 to i8*
%40 = call i64 @setsockopt(i32 %36, i32 %37, i32 %38, i8* %39, i32 16)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %32
br label %43
43: ; preds = %42, %32
%44 = load i32*, i32** %5
%45 = load i32, i32* %44
%46 = load i32, i32* @SOL_SOCKET
%47 = load i32, i32* @SO_SNDTIMEO
%48 = bitcast %struct.timeval* %7 to i8*
%49 = call i64 @setsockopt(i32 %45, i32 %46, i32 %47, i8* %48, i32 16)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %43
br label %52
52: ; preds = %51, %43
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i64 }
@.str = [37 x i8] c"Connecting to server \1B[36m%s\1B[0m...\0A\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [14 x i8] c"Socket error.\00"
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@SO_SNDTIMEO = global i32 0
define void @setup_publish_server(%struct.sockaddr_in* %0, i32* nocapture %1, i8* %2) {
%4 = alloca %struct.timeval
%5 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %2)
%6 = bitcast %struct.sockaddr_in* %0 to i8*
%7 = tail call i32 @memset(i8* %6, i32 0, i32 8)
%8 = load i32, i32* @PF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 2
store i32 %8, i32* %9
%10 = tail call i32 @inet_addr(i8* %2)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 1, i32 0
store i32 %10, i32* %11
%12 = tail call i32 @htons(i32 4001)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 0
store i32 %12, i32* %13
%14 = load i32, i32* @PF_INET
%15 = load i32, i32* @SOCK_DGRAM
%16 = tail call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %1
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %3
%19 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %3
%22 = bitcast %struct.timeval* %4 to i8*
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
store i32 5, i32* %23
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
store i64 0, i64* %24
%25 = load i32, i32* @SOL_SOCKET
%26 = load i32, i32* @SO_RCVTIMEO
%27 = call i64 @setsockopt(i32 %16, i32 %25, i32 %26, i8* %22, i32 16)
%28 = load i32, i32* %1
%29 = load i32, i32* @SOL_SOCKET
%30 = load i32, i32* @SO_SNDTIMEO
%31 = call i64 @setsockopt(i32 %28, i32 %29, i32 %30, i8* %22, i32 16)
ret void
}