#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 sockaddr_in {
  int dummy;
};
typedef int /*<<< orphan*/ n;

/* Variables and functions */
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 /*<<< orphan*/ exit(int /*<<< orphan*/);
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 outSocket3(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");
  }
  return send_socket;
}


x86 assembly (clang, -O0):
<outSocket3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
mov    -0x4(%rbp),%edx
call   1070 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11b1 <outSocket3+0x61>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
call   1050 <syslog@plt>
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0xc(%rbp),%edi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
mov    0x2dfc(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    11ff <outSocket3+0xaf>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
call   1050 <syslog@plt>
lea    0xe42(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
mov    0x2dc6(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    124d <outSocket3+0xfd>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
lea    0xde6(%rip),%rsi
call   1050 <syslog@plt>
lea    0xdf4(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<outSocket3>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%edx
movl   $0x2,0x4(%rsp)
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
call   1070 <socket@plt>
cmp    $0xffffffff,%eax
je     1219 <outSocket3+0xc9>
mov    %eax,%ebx
mov    0x2e61(%rip),%r14
mov    (%r14),%esi
mov    0x2e2f(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    11cb <outSocket3+0x7b>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
call   1050 <syslog@plt>
lea    0xe64(%rip),%rdi
call   1030 <puts@plt>
mov    (%r14),%esi
mov    0x2e03(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    120f <outSocket3+0xbf>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
call   1050 <syslog@plt>
lea    0xe20(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
lea    0xdd7(%rip),%rsi
call   1050 <syslog@plt>
lea    0xe08(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = 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
define i32 @outSocket3(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
store i32 %0, i32* %2
store i32 2, i32* %3
%6 = load i32, i32* @PF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = load i32, i32* %2
%9 = call i32 @socket(i32 %6, i32 %7, i32 %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %17
12: ; preds = %1
%13 = load i32, i32* @LOG_ERR
%14 = call i32 @syslog(i32 %13, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %1
%18 = load i32, i32* %4
%19 = load i32, i32* @SOL_SOCKET
%20 = load i32, i32* @SO_REUSEADDR
%21 = bitcast i32* %3 to i8*
%22 = call i32 @setsockopt(i32 %18, i32 %19, i32 %20, i8* %21, i32 4)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %28
24: ; preds = %17
%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 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %24, %17
%29 = load i32, i32* %4
%30 = load i32, i32* @SOL_SOCKET
%31 = load i32, i32* @SO_BROADCAST
%32 = bitcast i32* %3 to i8*
%33 = call i32 @setsockopt(i32 %29, i32 %30, i32 %31, i8* %32, i32 4)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %39
35: ; preds = %28
%36 = load i32, i32* @LOG_ERR
%37 = call i32 @syslog(i32 %36, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %35, %28
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
@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
@str.4 = [19 x i8] c"couldnt set option\00"
@str.5 = [17 x i8] c"snd socket error\00"
define i32 @outSocket3(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 2, i32* %2
%4 = load i32, i32* @PF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 %0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i32, i32* @LOG_ERR
%10 = tail call i32 @syslog(i32 %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.5, i64 0, i64 0))
%12 = tail call i32 @exit(i32 0)
unreachable
13: ; preds = %1
%14 = load i32, i32* @SOL_SOCKET
%15 = load i32, i32* @SO_REUSEADDR
%16 = call i32 @setsockopt(i32 %6, i32 %14, i32 %15, i8* %3, i32 4)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i32, i32* @LOG_ERR
%20 = call i32 @syslog(i32 %19, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.4, i64 0, i64 0))
br label %22
22: ; preds = %18, %13
%23 = load i32, i32* @SOL_SOCKET
%24 = load i32, i32* @SO_BROADCAST
%25 = call i32 @setsockopt(i32 %6, i32 %23, i32 %24, i8* %3, i32 4)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = load i32, i32* @LOG_ERR
%29 = call i32 @syslog(i32 %28, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.4, i64 0, i64 0))
br label %31
31: ; preds = %27, %22
ret i32 %6
}