#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_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 inSocket(long listen_addr, short listen_port, int protocol) {
  int n = 1;
  int socket_in;
  struct sockaddr_in sin;
  socket_in = socket(PF_INET, SOCK_DGRAM, protocol);
  if (socket_in == -1) {
    syslog(LOG_ERR, "server socket error");
    printf("server socket error\n");
    exit(0);
  }
  if (setsockopt(socket_in, SOL_SOCKET, SO_REUSEADDR, (char *)&n, sizeof(n)) ==
      -1) {
    printf("couldnt set option\n");
  }
  bzero(&sin, sizeof(sin));
  sin.sin_family = AF_INET;
  sin.sin_port = htons(listen_port);
  sin.sin_addr.s_addr = listen_addr;
  if (bind(socket_in, (struct sockaddr *)&sin, sizeof(struct sockaddr)) == -1) {
    syslog(LOG_ERR, "sock_listen bind error");
    perror("sock_listen bind error -");
    exit(0);
  }
  return socket_in;
}


x86 assembly (clang, -O0):
<inSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    0x2e14(%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 <inSocket+0x6c>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
lea    0xe1c(%rip),%rsi
call   1060 <syslog@plt>
lea    0xe24(%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    0x2db1(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1235 <inSocket+0xa5>
lea    0xdf9(%rip),%rdi
call   1050 <printf@plt>
lea    -0x28(%rbp),%rdi
mov    $0x10,%esi
call   1090 <bzero@plt>
mov    0x2d96(%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    12a5 <inSocket+0x115>
mov    0x2d2c(%rip),%rax
mov    (%rax),%edi
lea    0xdb0(%rip),%rsi
call   1060 <syslog@plt>
lea    0xdbb(%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):
<inSocket>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r15d
mov    %rdi,%r14
movl   $0x1,0x4(%rsp)
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
je     1251 <inSocket+0xc1>
mov    %eax,%ebx
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
mov    0x2de6(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    11ff <inSocket+0x6f>
lea    0xe36(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x10,%esi
call   1090 <bzero@plt>
mov    0x2dc8(%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     1278 <inSocket+0xe8>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
lea    0xde2(%rip),%rbx
mov    %rbx,%rsi
call   1060 <syslog@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
lea    0xd78(%rip),%rsi
call   1060 <syslog@plt>
lea    0xd83(%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 = [20 x i8] c"server socket error\00"
@.str.1 = [21 x i8] c"server socket error\0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [20 x i8] c"couldnt set option\0A\00"
@AF_INET = global i32 0
@.str.3 = [23 x i8] c"sock_listen bind error\00"
@.str.4 = [25 x i8] c"sock_listen bind error -\00"
define i32 @inSocket(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 1, 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 ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 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 %30
28: ; preds = %21
%29 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %28, %21
%31 = call i32 @bzero(%struct.sockaddr_in* %9, i32 16)
%32 = load i32, i32* @AF_INET
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %32, i32* %33
%34 = load i16, i16* %5
%35 = call i32 @htons(i16 signext %34)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %35, i32* %36
%37 = load i64, i64* %4
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%39 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %38, i32 0, i32 0
store i64 %37, i64* %39
%40 = load i32, i32* %8
%41 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%42 = call i32 @bind(i32 %40, %struct.sockaddr* %41, i32 4)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %49
44: ; preds = %30
%45 = load i32, i32* @LOG_ERR
%46 = call i32 @syslog(i32 %45, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%47 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%48 = call i32 @exit(i32 0)
unreachable
49: ; preds = %30
%50 = load i32, i32* %8
ret i32 %50
}

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
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@AF_INET = global i32 0
@.str.3 = [23 x i8] c"sock_listen bind error\00"
@.str.4 = [25 x i8] c"sock_listen bind error -\00"
@str = [19 x i8] c"couldnt set option\00"
@str.5 = [20 x i8] c"server socket error\00"
define i32 @inSocket(i64 %0, i16 signext %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = bitcast i32* %4 to i8*
store i32 1, 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 ([20 x i8], [20 x i8]* @str.5, i64 0, i64 0))
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.5, 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 %24
22: ; preds = %17
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %24
24: ; preds = %22, %17
%25 = call i32 @bzero(%struct.sockaddr_in* %5, i32 16)
%26 = load i32, i32* @AF_INET
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %26, i32* %27
%28 = call i32 @htons(i16 signext %1)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %28, i32* %29
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
store i64 %0, i64* %30
%31 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%32 = call i32 @bind(i32 %10, %struct.sockaddr* %31, i32 4)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %39
34: ; preds = %24
%35 = load i32, i32* @LOG_ERR
%36 = call i32 @syslog(i32 %35, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%37 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%38 = call i32 @exit(i32 0)
unreachable
39: ; preds = %24
ret i32 %10
}