#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;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ sin;
typedef int /*<<< orphan*/ n;

/* Variables and functions */
int /*<<< orphan*/ 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 /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ 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 outSocket2(long send_from_addr, short send_from_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);
  }
  return send_socket;
}


x86 assembly (clang, -O0):
<outSocket2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x2,-0x14(%rbp)
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
call   10b0 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11fc <outSocket2+0x6c>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
lea    0xe1c(%rip),%rsi
call   1060 <syslog@plt>
lea    0xe20(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%edi
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
mov    0x2da9(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    124a <outSocket2+0xba>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
lea    0xde9(%rip),%rsi
call   1060 <syslog@plt>
lea    0xdf7(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%edi
mov    0x2d94(%rip),%rax
mov    (%rax),%esi
mov    0x2d73(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1298 <outSocket2+0x108>
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
lea    0xd9b(%rip),%rsi
call   1060 <syslog@plt>
lea    0xda9(%rip),%rdi
call   1050 <printf@plt>
lea    -0x28(%rbp),%rdi
mov    $0x10,%esi
call   1090 <bzero@plt>
mov    0x2d33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
movswl -0xa(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1070 <bind@plt>
cmp    $0xffffffff,%eax
jne    1308 <outSocket2+0x178>
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
lea    0xd60(%rip),%rsi
call   1060 <syslog@plt>
lea    0xd64(%rip),%rdi
call   1080 <perror@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<outSocket2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r15d
mov    %rdi,%r14
movl   $0x2,0x4(%rsp)
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
je     12ab <outSocket2+0x11b>
mov    %eax,%ebx
mov    0x2e17(%rip),%rbp
mov    0x0(%rbp),%esi
mov    0x2ddd(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1215 <outSocket2+0x85>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
call   1060 <syslog@plt>
lea    0xe41(%rip),%rdi
call   1030 <puts@plt>
mov    0x0(%rbp),%esi
mov    0x2db1(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1259 <outSocket2+0xc9>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
lea    0xdc8(%rip),%rsi
call   1060 <syslog@plt>
lea    0xdfd(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x10,%esi
call   1090 <bzero@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
movswl %r15w,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %r14,0x8(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1070 <bind@plt>
cmp    $0xffffffff,%eax
je     12d3 <outSocket2+0x143>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
lea    0xd45(%rip),%rsi
call   1060 <syslog@plt>
lea    0xd9d(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
lea    0xd47(%rip),%rsi
call   1060 <syslog@plt>
lea    0xd4b(%rip),%rdi
call   1080 <perror@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

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

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