#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 */
struct TYPE_2__ {
  long s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  void *sin_port;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ sin;
typedef int /*<<< orphan*/ n;

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BROADCAST;
int /*<<< orphan*/ SO_REUSEADDR;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
void *htons(short);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
int outSocket(long send_from_addr, short send_from_port, long send_addr,
              short send_port, int protocol) {
  int n = 2;
  int send_socket;
  struct sockaddr_in sin;
  send_socket = socket(PF_INET, SOCK_DGRAM, protocol);
  if (send_socket == -1) {
    syslog(LOG_ERR, "send socket err");
    printf("snd socket error\n");
    exit(0);
  }
  if (setsockopt(send_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&n,
                 sizeof(n)) == -1) {
    syslog(LOG_ERR, "Couldnt set socket option");
    printf("couldnt set option\n");
  }
  if (setsockopt(send_socket, SOL_SOCKET, SO_BROADCAST, (char *)&n,
                 sizeof(n)) == -1) {
    syslog(LOG_ERR, "Couldnt set socket option");
    printf("couldnt set option\n");
  }
  bzero(&sin, sizeof(sin));
  sin.sin_family = AF_INET;
  sin.sin_port = htons(send_from_port);
  sin.sin_addr.s_addr = send_from_addr;
  if (bind(send_socket, (struct sockaddr *)&sin, sizeof(struct sockaddr)) ==
      -1) {
    syslog(LOG_ERR, "send bind error");
    perror("sock_send bind error -");
    exit(0);
  }
  bzero(&sin, sizeof(sin));
  sin.sin_family = AF_INET;
  sin.sin_port = htons(send_port);
  sin.sin_addr.s_addr = send_addr;
  if (connect(send_socket, (struct sockaddr *)&sin, sizeof(struct sockaddr)) ==
      -1) {
    syslog(LOG_ERR, "send connect error");
    perror("send connect error\n");
    exit(0);
  }
  return send_socket;
}


x86 assembly (clang, -O0):
<outSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %cx,%ax
mov    %si,%cx
mov    %rdi,-0x8(%rbp)
mov    %cx,-0xa(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ax,-0x1a(%rbp)
mov    %r8d,-0x20(%rbp)
movl   $0x2,-0x24(%rbp)
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%edx
call   10c0 <socket@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    1218 <outSocket+0x78>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
call   1060 <syslog@plt>
lea    0xe04(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x28(%rbp),%edi
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
mov    0x2d8d(%rip),%rax
mov    (%rax),%edx
lea    -0x24(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1266 <outSocket+0xc6>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
lea    0xdcd(%rip),%rsi
call   1060 <syslog@plt>
lea    0xddb(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%edi
mov    0x2d78(%rip),%rax
mov    (%rax),%esi
mov    0x2d57(%rip),%rax
mov    (%rax),%edx
lea    -0x24(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    12b4 <outSocket+0x114>
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
lea    0xd7f(%rip),%rsi
call   1060 <syslog@plt>
lea    0xd8d(%rip),%rdi
call   1050 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    $0x18,%esi
call   1090 <bzero@plt>
mov    0x2d17(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
movswl -0xa(%rbp),%edi
call   1040 <htons@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x4,%edx
call   1070 <bind@plt>
cmp    $0xffffffff,%eax
jne    1327 <outSocket+0x187>
mov    0x2ca2(%rip),%rax
mov    (%rax),%edi
lea    0xd41(%rip),%rsi
call   1060 <syslog@plt>
lea    0xd45(%rip),%rdi
call   1080 <perror@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    -0x40(%rbp),%rdi
mov    $0x18,%esi
call   1090 <bzero@plt>
mov    0x2ca4(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
movswl -0x1a(%rbp),%edi
call   1040 <htons@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x4,%edx
call   10b0 <connect@plt>
cmp    $0xffffffff,%eax
jne    139a <outSocket+0x1fa>
mov    0x2c2f(%rip),%rax
mov    (%rax),%edi
lea    0xcf5(%rip),%rsi
call   1060 <syslog@plt>
lea    0xcfc(%rip),%rdi
call   1080 <perror@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x28(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<outSocket>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,%ebx
mov    %rdx,%r15
mov    %esi,%r13d
mov    %rdi,%r12
movl   $0x2,0x8(%rsp)
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
mov    %r8d,%edx
call   10c0 <socket@plt>
cmp    $0xffffffff,%eax
je     1314 <outSocket+0x174>
mov    %eax,%ebp
mov    %ebx,0xc(%rsp)
mov    0x2df7(%rip),%r14
mov    (%r14),%esi
mov    0x2dbd(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1235 <outSocket+0x95>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
lea    0xdec(%rip),%rsi
call   1060 <syslog@plt>
lea    0xe48(%rip),%rdi
call   1030 <puts@plt>
mov    (%r14),%esi
mov    0x2d91(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1279 <outSocket+0xd9>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
lea    0xda8(%rip),%rsi
call   1060 <syslog@plt>
lea    0xe04(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x18,%esi
call   1090 <bzero@plt>
mov    0x2d4e(%rip),%r14
mov    (%r14),%rax
mov    %rax,0x20(%rsp)
movswl %r13w,%edi
call   1050 <htons@plt>
mov    %rax,0x18(%rsp)
mov    %r12,0x10(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1070 <bind@plt>
cmp    $0xffffffff,%eax
je     133c <outSocket+0x19c>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x18,%esi
call   1090 <bzero@plt>
mov    (%r14),%rax
mov    %rax,0x20(%rsp)
movswl 0xc(%rsp),%edi
call   1050 <htons@plt>
mov    %rax,0x18(%rsp)
mov    %r15,0x10(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   10b0 <connect@plt>
cmp    $0xffffffff,%eax
je     135a <outSocket+0x1ba>
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c8d(%rip),%rax
mov    (%rax),%edi
lea    0xcdc(%rip),%rsi
call   1060 <syslog@plt>
lea    0xd5b(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    0x2c65(%rip),%rax
mov    (%rax),%edi
lea    0xcde(%rip),%rsi
call   1060 <syslog@plt>
lea    0xce2(%rip),%rdi
jmp    1376 <outSocket+0x1d6>
mov    0x2c47(%rip),%rax
mov    (%rax),%edi
lea    0xce7(%rip),%rsi
call   1060 <syslog@plt>
lea    0xcee(%rip),%rdi
call   1080 <perror@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i8* }
%struct.TYPE_2__ = type { i64 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@LOG_ERR = global i32 0
@.str = [16 x i8] c"send socket err\00"
@.str.1 = [18 x i8] c"snd socket error\0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [26 x i8] c"Couldnt set socket option\00"
@.str.3 = [20 x i8] c"couldnt set option\0A\00"
@SO_BROADCAST = global i32 0
@AF_INET = global i8* null
@.str.4 = [16 x i8] c"send bind error\00"
@.str.5 = [23 x i8] c"sock_send bind error -\00"
@.str.6 = [19 x i8] c"send connect error\00"
@.str.7 = [20 x i8] c"send connect error\0A\00"
define i32 @outSocket(i64 %0, i16 signext %1, i64 %2, i16 signext %3, i32 %4) {
%6 = alloca i64
%7 = alloca i16
%8 = alloca i64
%9 = alloca i16
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.sockaddr_in
store i64 %0, i64* %6
store i16 %1, i16* %7
store i64 %2, i64* %8
store i16 %3, i16* %9
store i32 %4, i32* %10
store i32 2, i32* %11
%14 = load i32, i32* @PF_INET
%15 = load i32, i32* @SOCK_DGRAM
%16 = load i32, i32* %10
%17 = call i32 @socket(i32 %14, i32 %15, i32 %16)
store i32 %17, i32* %12
%18 = load i32, i32* %12
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %25
20: ; preds = %5
%21 = load i32, i32* @LOG_ERR
%22 = call i32 @syslog(i32 %21, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %5
%26 = load i32, i32* %12
%27 = load i32, i32* @SOL_SOCKET
%28 = load i32, i32* @SO_REUSEADDR
%29 = bitcast i32* %11 to i8*
%30 = call i32 @setsockopt(i32 %26, i32 %27, i32 %28, i8* %29, i32 4)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %36
32: ; preds = %25
%33 = load i32, i32* @LOG_ERR
%34 = call i32 @syslog(i32 %33, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %32, %25
%37 = load i32, i32* %12
%38 = load i32, i32* @SOL_SOCKET
%39 = load i32, i32* @SO_BROADCAST
%40 = bitcast i32* %11 to i8*
%41 = call i32 @setsockopt(i32 %37, i32 %38, i32 %39, i8* %40, i32 4)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %47
43: ; preds = %36
%44 = load i32, i32* @LOG_ERR
%45 = call i32 @syslog(i32 %44, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%46 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %43, %36
%48 = call i32 @bzero(%struct.sockaddr_in* %13, i32 24)
%49 = load i8*, i8** @AF_INET
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 2
store i8* %49, i8** %50
%51 = load i16, i16* %7
%52 = call i8* @htons(i16 signext %51)
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 1
store i8* %52, i8** %53
%54 = load i64, i64* %6
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 0
%56 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %55, i32 0, i32 0
store i64 %54, i64* %56
%57 = load i32, i32* %12
%58 = bitcast %struct.sockaddr_in* %13 to %struct.sockaddr*
%59 = call i32 @bind(i32 %57, %struct.sockaddr* %58, i32 4)
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %66
61: ; preds = %47
%62 = load i32, i32* @LOG_ERR
%63 = call i32 @syslog(i32 %62, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%64 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%65 = call i32 @exit(i32 0)
unreachable
66: ; preds = %47
%67 = call i32 @bzero(%struct.sockaddr_in* %13, i32 24)
%68 = load i8*, i8** @AF_INET
%69 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 2
store i8* %68, i8** %69
%70 = load i16, i16* %9
%71 = call i8* @htons(i16 signext %70)
%72 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 1
store i8* %71, i8** %72
%73 = load i64, i64* %8
%74 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 0
%75 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %74, i32 0, i32 0
store i64 %73, i64* %75
%76 = load i32, i32* %12
%77 = bitcast %struct.sockaddr_in* %13 to %struct.sockaddr*
%78 = call i32 @connect(i32 %76, %struct.sockaddr* %77, i32 4)
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %85
80: ; preds = %66
%81 = load i32, i32* @LOG_ERR
%82 = call i32 @syslog(i32 %81, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%83 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%84 = call i32 @exit(i32 0)
unreachable
85: ; preds = %66
%86 = load i32, i32* %12
ret i32 %86
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i8* }
%struct.TYPE_2__ = type { i64 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@LOG_ERR = global i32 0
@.str = [16 x i8] c"send socket err\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [26 x i8] c"Couldnt set socket option\00"
@SO_BROADCAST = global i32 0
@AF_INET = global i8* null
@.str.4 = [16 x i8] c"send bind error\00"
@.str.5 = [23 x i8] c"sock_send bind error -\00"
@.str.6 = [19 x i8] c"send connect error\00"
@.str.7 = [20 x i8] c"send connect error\0A\00"
@str.8 = [19 x i8] c"couldnt set option\00"
@str.9 = [17 x i8] c"snd socket error\00"
define i32 @outSocket(i64 %0, i16 signext %1, i64 %2, i16 signext %3, i32 %4) {
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = bitcast i32* %6 to i8*
store i32 2, i32* %6
%9 = bitcast %struct.sockaddr_in* %7 to i8*
%10 = load i32, i32* @PF_INET
%11 = load i32, i32* @SOCK_DGRAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 %4)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %19
14: ; preds = %5
%15 = load i32, i32* @LOG_ERR
%16 = tail call i32 @syslog(i32 %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.9, i64 0, i64 0))
%18 = tail call i32 @exit(i32 0)
unreachable
19: ; preds = %5
%20 = load i32, i32* @SOL_SOCKET
%21 = load i32, i32* @SO_REUSEADDR
%22 = call i32 @setsockopt(i32 %12, i32 %20, i32 %21, i8* %8, i32 4)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = load i32, i32* @LOG_ERR
%26 = call i32 @syslog(i32 %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.8, i64 0, i64 0))
br label %28
28: ; preds = %24, %19
%29 = load i32, i32* @SOL_SOCKET
%30 = load i32, i32* @SO_BROADCAST
%31 = call i32 @setsockopt(i32 %12, i32 %29, i32 %30, i8* %8, i32 4)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = load i32, i32* @LOG_ERR
%35 = call i32 @syslog(i32 %34, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.8, i64 0, i64 0))
br label %37
37: ; preds = %33, %28
%38 = call i32 @bzero(%struct.sockaddr_in* %7, i32 24)
%39 = load i8*, i8** @AF_INET
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 2
store i8* %39, i8** %40
%41 = call i8* @htons(i16 signext %1)
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 1
store i8* %41, i8** %42
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 0, i32 0
store i64 %0, i64* %43
%44 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%45 = call i32 @bind(i32 %12, %struct.sockaddr* %44, i32 4)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %52
47: ; preds = %37
%48 = load i32, i32* @LOG_ERR
%49 = call i32 @syslog(i32 %48, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%50 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%51 = call i32 @exit(i32 0)
unreachable
52: ; preds = %37
%53 = call i32 @bzero(%struct.sockaddr_in* %7, i32 24)
%54 = load i8*, i8** @AF_INET
store i8* %54, i8** %40
%55 = call i8* @htons(i16 signext %3)
store i8* %55, i8** %42
store i64 %2, i64* %43
%56 = call i32 @connect(i32 %12, %struct.sockaddr* %44, i32 4)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %63
58: ; preds = %52
%59 = load i32, i32* @LOG_ERR
%60 = call i32 @syslog(i32 %59, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%61 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%62 = call i32 @exit(i32 0)
unreachable
63: ; preds = %52
ret i32 %12
}