#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int /*<<< orphan*/ s6_addr;
};
struct sockaddr_in6 {
  void *sin6_port;
  void *sin6_family;
  TYPE_2__ sin6_addr;
};
struct TYPE_3__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  void *sin_port;
  void *sin_family;
  TYPE_1__ sin_addr;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int pid_t;
typedef int /*<<< orphan*/ address6;
typedef int /*<<< orphan*/ address;

/* Variables and functions */
void *AF_INET;
void *AF_INET6;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
scalar_t__ bind(int, struct sockaddr *, int);
scalar_t__ clientresponse(int, char *, char *);
int /*<<< orphan*/ close(int);
scalar_t__ daemon(int, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
void *htons(int);
TYPE_2__ in6addr_any;
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ inet_pton(void *, char *, int /*<<< orphan*/);
scalar_t__ listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ startlogging(char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ wait(int *);
void startsws(char *i_address, int p_port, char *sws_dir, char *c_dir,
              char *l_file, int host_ipv, int flag_d) {
  int socket_fd, newsocket_fd;
  socklen_t addrlen;
  pid_t pid;
  struct sockaddr_in address;
  struct sockaddr_in6 address6;
  int status;
  printf("\n-----------Starting Sever-----------\n");
  if ((host_ipv == 2) || (host_ipv == 0)) {
    if ((socket_fd = socket(AF_INET6, SOCK_STREAM, 0)) > 0) {
      printf("Socket created: %d\n", socket_fd);
      printf("Binding socket ...\n");
    } else {
      fprintf(stderr, "Unable to create socket: %s\n", strerror(errno));
      exit(1);
    }
  } else {
    if ((socket_fd = socket(AF_INET, SOCK_STREAM, 0)) > 0) {
      printf("Socket created: %d\n", socket_fd);
      printf("Binding socket ...\n");
    } else {
      fprintf(stderr, "Unable to create socket: %s\n", strerror(errno));
      exit(1);
    }
  }
  if ((host_ipv == 2) || (host_ipv == 0)) {
    if (host_ipv == 0)
      address6.sin6_addr = in6addr_any;
    else
      (void)inet_pton(AF_INET6, i_address, address6.sin6_addr.s6_addr);
    address6.sin6_family = AF_INET6;
    address6.sin6_port = htons(p_port);
  } else {
    address.sin_addr.s_addr = inet_addr(i_address);
    address.sin_family = AF_INET;
    address.sin_port = htons(p_port);
  }
  if ((host_ipv == 2) || (host_ipv == 0)) {
    if (bind(socket_fd, (struct sockaddr *)&address6, sizeof(address6)) == 0) {
      printf(
          "Socket Binding Completed:\nSocket: %d | Port: %d | Address: %s \n\n",
          socket_fd, p_port, i_address);
    } else {
      fprintf(stderr, "Unable to create bind %d: %s\n", socket_fd,
              strerror(errno));
      exit(1);
    }
  } else {
    if (bind(socket_fd, (struct sockaddr *)&address, sizeof(address)) == 0) {
      printf(
          "Socket Binding Completed:\nSocket: %d | Port: %d | Address: %s \n\n",
          socket_fd, p_port, i_address);
    } else {
      fprintf(stderr, "Unable to create bind %d: %s\n", socket_fd,
              strerror(errno));
      exit(1);
    }
  }
  if (listen(socket_fd, 5) < 0) {
    perror("server: listen");
    exit(1);
  }
  if (!flag_d && daemon(1, 0) < 0) {
    perror("daemon");
    exit(1);
  }
  while (1) {
    if ((host_ipv == 2) || (host_ipv == 0)) {
      if ((newsocket_fd =
               accept(socket_fd, (struct sockaddr *)&address6, &addrlen)) < 0) {
        perror("server: accept");
        exit(1);
      }
    } else {
      if ((newsocket_fd =
               accept(socket_fd, (struct sockaddr *)&address, &addrlen)) < 0) {
        perror("server: accept");
        exit(1);
      }
    }
    if ((pid = fork()) < 0)
      printf("Failed to fork process to response client request.\n");
    if (pid == 0) {
      close(socket_fd);
      if (clientresponse(newsocket_fd, sws_dir, c_dir) > 0)
        printf("Client Response Error. PID: %d\n", pid);
      startlogging(sws_dir, l_file);
      exit(0);
    } else
      close(newsocket_fd);
    if (flag_d)
      wait(&status);
  }
}


x86 assembly (clang, -O0):
<startsws>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x2,-0x2c(%rbp)
je     1267 <startsws+0x47>
cmpl   $0x0,-0x2c(%rbp)
jne    12ee <startsws+0xce>
mov    0x2d6a(%rip),%rax
mov    (%rax),%rdi
mov    0x2d48(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jle    12b1 <startsws+0x91>
mov    -0x30(%rbp),%esi
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12e9 <startsws+0xc9>
mov    0x2d10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
mov    0x2cf4(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x78(%rbp),%edi
mov    %rax,%rdx
lea    0xd77(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
jmp    1375 <startsws+0x155>
mov    0x2ceb(%rip),%rax
mov    (%rax),%rdi
mov    0x2cc1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jle    1338 <startsws+0x118>
mov    -0x30(%rbp),%esi
lea    0xd09(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd0f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1370 <startsws+0x150>
mov    0x2c89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
mov    0x2c6d(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x7c(%rbp),%edi
mov    %rax,%rdx
lea    0xcf0(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
jmp    1375 <startsws+0x155>
cmpl   $0x2,-0x2c(%rbp)
je     1389 <startsws+0x169>
cmpl   $0x0,-0x2c(%rbp)
jne    13d9 <startsws+0x1b9>
cmpl   $0x0,-0x2c(%rbp)
jne    13a4 <startsws+0x184>
mov    0x2c56(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
jmp    13ba <startsws+0x19a>
mov    0x2c2d(%rip),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x60(%rbp),%edx
call   1090 <inet_pton@plt>
mov    0x2c17(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x68(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <htons@plt>
mov    %rax,-0x70(%rbp)
jmp    13ff <startsws+0x1df>
mov    -0x8(%rbp),%rdi
call   1070 <inet_addr@plt>
mov    %eax,-0x48(%rbp)
mov    0x2bf4(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <htons@plt>
mov    %rax,-0x58(%rbp)
cmpl   $0x2,-0x2c(%rbp)
je     1413 <startsws+0x1f3>
cmpl   $0x0,-0x2c(%rbp)
jne    1497 <startsws+0x277>
mov    -0x30(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x18,%edx
call   10c0 <bind@plt>
cmp    $0x0,%rax
jne    144b <startsws+0x22b>
mov    -0x30(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rcx
lea    0xc2d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1492 <startsws+0x272>
mov    0x2b76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x80(%rbp)
mov    0x2b51(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x84(%rbp),%edi
mov    -0x80(%rbp),%edx
mov    %rax,%rcx
lea    0xc2c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
jmp    1521 <startsws+0x301>
mov    -0x30(%rbp),%edi
lea    -0x58(%rbp),%rsi
mov    $0x18,%edx
call   10c0 <bind@plt>
cmp    $0x0,%rax
jne    14cf <startsws+0x2af>
mov    -0x30(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rcx
lea    0xba9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    151c <startsws+0x2fc>
mov    0x2af2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x88(%rbp)
mov    0x2aca(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x8c(%rbp),%edi
mov    -0x88(%rbp),%edx
mov    %rax,%rcx
lea    0xba2(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
jmp    1521 <startsws+0x301>
mov    -0x30(%rbp),%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
cmp    $0x0,%rax
jge    154e <startsws+0x32e>
lea    0xb8c(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
cmpl   $0x0,0x10(%rbp)
jne    1584 <startsws+0x364>
mov    $0x1,%edi
xor    %esi,%esi
call   10b0 <daemon@plt>
cmp    $0x0,%rax
jge    1584 <startsws+0x364>
lea    0xb65(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
jmp    1589 <startsws+0x369>
cmpl   $0x2,-0x2c(%rbp)
je     159d <startsws+0x37d>
cmpl   $0x0,-0x2c(%rbp)
jne    15d4 <startsws+0x3b4>
mov    -0x30(%rbp),%edi
lea    -0x70(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    15cf <startsws+0x3af>
lea    0xb21(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
jmp    160b <startsws+0x3eb>
mov    -0x30(%rbp),%edi
lea    -0x58(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    1606 <startsws+0x3e6>
lea    0xaea(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
jmp    160b <startsws+0x3eb>
mov    $0x0,%al
call   1120 <fork@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0x0,%eax
jge    162c <startsws+0x40c>
lea    0xacb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x3c(%rbp)
jne    167d <startsws+0x45d>
mov    -0x30(%rbp),%edi
call   1060 <close@plt>
mov    -0x34(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1130 <clientresponse@plt>
cmp    $0x0,%rax
jle    1669 <startsws+0x449>
mov    -0x3c(%rbp),%esi
lea    0xac2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <startlogging@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    -0x34(%rbp),%edi
call   1060 <close@plt>
cmpl   $0x0,0x10(%rbp)
je     1698 <startsws+0x478>
lea    -0x74(%rbp),%rdi
call   1110 <wait@plt>
jmp    1589 <startsws+0x369>

x86 assembly (clang, -O2):
<startsws>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r9d,%r15d
mov    %r8,%r12
mov    %rcx,%rbp
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %rdi,%r13
lea    0xe7e(%rip),%rdi
call   1040 <puts@plt>
test   $0xfffffffd,%r15d
mov    %rbx,0x18(%rsp)
mov    %rbp,0x10(%rsp)
jne    12cb <startsws+0x9b>
mov    0x2d62(%rip),%rbp
mov    0x0(%rbp),%rdi
mov    0x2d3f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
test   %eax,%eax
jle    1331 <startsws+0x101>
mov    %eax,%ebx
lea    0xd65(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe83(%rip),%rdi
call   1040 <puts@plt>
test   %r15d,%r15d
jne    1365 <startsws+0x135>
mov    0x2d30(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x38(%rsp)
jmp    1371 <startsws+0x141>
mov    0x2d0e(%rip),%rbp
mov    0x0(%rbp),%rdi
mov    0x2ce3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
test   %eax,%eax
jle    1331 <startsws+0x101>
mov    %eax,%ebx
lea    0xd0d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe2b(%rip),%rdi
call   1040 <puts@plt>
mov    %r13,%rdi
call   1080 <inet_addr@plt>
mov    %eax,0x50(%rsp)
mov    0x0(%rbp),%rax
mov    %rax,0x48(%rsp)
mov    %r14d,%edi
call   1050 <htons@plt>
mov    %rax,0x40(%rsp)
lea    0x40(%rsp),%rsi
jmp    138c <startsws+0x15c>
mov    0x2c90(%rip),%rax
mov    (%rax),%ebx
mov    0x2c77(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xcc5(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x0(%rbp),%rdi
mov    %r13,%rsi
call   10a0 <inet_pton@plt>
mov    0x0(%rbp),%rax
mov    %rax,0x30(%rsp)
mov    %r14d,%edi
call   1050 <htons@plt>
mov    %rax,0x28(%rsp)
lea    0x28(%rsp),%rsi
mov    %ebx,%edi
mov    $0x18,%edx
call   10d0 <bind@plt>
test   %rax,%rax
jne    13d0 <startsws+0x1a0>
lea    0xc8d(%rip),%rdi
mov    %ebx,%esi
mov    %r14d,%edx
mov    %r13,%rcx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
test   %rax,%rax
jns    1406 <startsws+0x1d6>
lea    0xcc5(%rip),%rdi
jmp    14ac <startsws+0x27c>
mov    0x2bf1(%rip),%rax
mov    (%rax),%ebp
mov    0x2bd8(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xc84(%rip),%rsi
mov    %ebp,%edi
mov    %ebx,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    %r12,0x8(%rsp)
mov    0x90(%rsp),%r12d
test   %r12d,%r12d
jne    1432 <startsws+0x202>
mov    $0x1,%edi
xor    %esi,%esi
call   10c0 <daemon@plt>
test   %rax,%rax
jns    1432 <startsws+0x202>
lea    0xc6f(%rip),%rdi
jmp    14ac <startsws+0x27c>
lea    0x24(%rsp),%rbp
lea    0x40(%rsp),%r14
nopl   0x0(%rax)
mov    %ebx,%edi
test   $0xfffffffd,%r15d
je     1450 <startsws+0x220>
mov    %r14,%rsi
jmp    1455 <startsws+0x225>
lea    0x28(%rsp),%rsi
mov    %rbp,%rdx
call   10f0 <accept@plt>
mov    %eax,%r13d
test   %eax,%eax
js     14a5 <startsws+0x275>
xor    %eax,%eax
call   1130 <fork@plt>
test   %eax,%eax
js     1480 <startsws+0x250>
jne    148c <startsws+0x25c>
jmp    14bb <startsws+0x28b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xc74(%rip),%rdi
call   1040 <puts@plt>
mov    %r13d,%edi
call   1070 <close@plt>
test   %r12d,%r12d
je     1440 <startsws+0x210>
lea    0x20(%rsp),%rdi
call   1120 <wait@plt>
jmp    1440 <startsws+0x210>
lea    0xbfa(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    %ebx,%edi
call   1070 <close@plt>
mov    %r13d,%edi
mov    0x18(%rsp),%rbx
mov    %rbx,%rsi
mov    0x10(%rsp),%rdx
call   1140 <clientresponse@plt>
test   %rax,%rax
jle    14ec <startsws+0x2bc>
lea    0xbd2(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    0x8(%rsp),%rsi
call   1030 <startlogging@plt>
xor    %edi,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32 }
%struct.sockaddr_in = type { i8*, i8*, %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32 }
%struct.sockaddr_in6 = type { i8*, i8*, %struct.TYPE_4__ }
%struct.sockaddr = type { i32 }
@.str = [39 x i8] c"\0A-----------Starting Sever-----------\0A\00"
@AF_INET6 = global i8* null
@SOCK_STREAM = global i32 0
@.str.1 = [20 x i8] c"Socket created: %d\0A\00"
@.str.2 = [20 x i8] c"Binding socket ...\0A\00"
@stderr = global i32 0
@.str.3 = [29 x i8] c"Unable to create socket: %s\0A\00"
@errno = global i32 0
@AF_INET = global i8* null
@in6addr_any = global %struct.TYPE_4__ zeroinitializer
@.str.4 = [65 x i8] c"Socket Binding Completed:\0ASocket: %d | Port: %d | Address: %s \0A\0A\00"
@.str.5 = [30 x i8] c"Unable to create bind %d: %s\0A\00"
@.str.6 = [15 x i8] c"server: listen\00"
@.str.7 = [7 x i8] c"daemon\00"
@.str.8 = [15 x i8] c"server: accept\00"
@.str.9 = [52 x i8] c"Failed to fork process to response client request.\0A\00"
@.str.10 = [32 x i8] c"Client Response Error. PID: %d\0A\00"
define void @startsws(i8* %0, i32 %1, i8* %2, i8* %3, i8* %4, i32 %5, i32 %6) {
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca %struct.sockaddr_in
%20 = alloca %struct.sockaddr_in6
%21 = alloca i32
store i8* %0, i8** %8
store i32 %1, i32* %9
store i8* %2, i8** %10
store i8* %3, i8** %11
store i8* %4, i8** %12
store i32 %5, i32* %13
store i32 %6, i32* %14
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* %13
%24 = icmp eq i32 %23, 2
br i1 %24, label %28, label %25
25: ; preds = %7
%26 = load i32, i32* %13
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %44
28: ; preds = %25, %7
%29 = load i8*, i8** @AF_INET6
%30 = load i32, i32* @SOCK_STREAM
%31 = call i32 @socket(i8* %29, i32 %30, i32 0)
store i32 %31, i32* %15
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = load i32, i32* %15
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %43
37: ; preds = %28
%38 = load i32, i32* @stderr
%39 = load i32, i32* @errno
%40 = call i8* @strerror(i32 %39)
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %40)
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %33
br label %60
44: ; preds = %25
%45 = load i8*, i8** @AF_INET
%46 = load i32, i32* @SOCK_STREAM
%47 = call i32 @socket(i8* %45, i32 %46, i32 0)
store i32 %47, i32* %15
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %44
%50 = load i32, i32* %15
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %59
53: ; preds = %44
%54 = load i32, i32* @stderr
%55 = load i32, i32* @errno
%56 = call i8* @strerror(i32 %55)
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %56)
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %49
br label %60
60: ; preds = %59, %43
%61 = load i32, i32* %13
%62 = icmp eq i32 %61, 2
br i1 %62, label %66, label %63
63: ; preds = %60
%64 = load i32, i32* %13
%65 = icmp eq i32 %64, 0
br i1 %65, label %66, label %85
66: ; preds = %63, %60
%67 = load i32, i32* %13
%68 = icmp eq i32 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %66
%70 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %20, i32 0, i32 2
%71 = bitcast %struct.TYPE_4__* %70 to i8*
br label %79
72: ; preds = %66
%73 = load i8*, i8** @AF_INET6
%74 = load i8*, i8** %8
%75 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %20, i32 0, i32 2
%76 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %75, i32 0, i32 0
%77 = load i32, i32* %76
%78 = call i32 @inet_pton(i8* %73, i8* %74, i32 %77)
br label %79
79: ; preds = %72, %69
%80 = load i8*, i8** @AF_INET6
%81 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %20, i32 0, i32 1
store i8* %80, i8** %81
%82 = load i32, i32* %9
%83 = call i8* @htons(i32 %82)
%84 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %20, i32 0, i32 0
store i8* %83, i8** %84
br label %95
85: ; preds = %63
%86 = load i8*, i8** %8
%87 = call i32 @inet_addr(i8* %86)
%88 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 2
%89 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %88, i32 0, i32 0
store i32 %87, i32* %89
%90 = load i8*, i8** @AF_INET
%91 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 1
store i8* %90, i8** %91
%92 = load i32, i32* %9
%93 = call i8* @htons(i32 %92)
%94 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 0
store i8* %93, i8** %94
br label %95
95: ; preds = %85, %79
%96 = load i32, i32* %13
%97 = icmp eq i32 %96, 2
br i1 %97, label %101, label %98
98: ; preds = %95
%99 = load i32, i32* %13
%100 = icmp eq i32 %99, 0
br i1 %100, label %101, label %119
101: ; preds = %98, %95
%102 = load i32, i32* %15
%103 = bitcast %struct.sockaddr_in6* %20 to %struct.sockaddr*
%104 = call i64 @bind(i32 %102, %struct.sockaddr* %103, i32 24)
%105 = icmp eq i64 %104, 0
br i1 %105, label %106, label %111
106: ; preds = %101
%107 = load i32, i32* %15
%108 = load i32, i32* %9
%109 = load i8*, i8** %8
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.4, i64 0, i64 0), i32 %107, i32 %108, i8* %109)
br label %118
111: ; preds = %101
%112 = load i32, i32* @stderr
%113 = load i32, i32* %15
%114 = load i32, i32* @errno
%115 = call i8* @strerror(i32 %114)
%116 = call i32 (i32, i8*, ...) @fprintf(i32 %112, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %113, i8* %115)
%117 = call i32 @exit(i32 1)
unreachable
118: ; preds = %106
br label %137
119: ; preds = %98
%120 = load i32, i32* %15
%121 = bitcast %struct.sockaddr_in* %19 to %struct.sockaddr*
%122 = call i64 @bind(i32 %120, %struct.sockaddr* %121, i32 24)
%123 = icmp eq i64 %122, 0
br i1 %123, label %124, label %129
124: ; preds = %119
%125 = load i32, i32* %15
%126 = load i32, i32* %9
%127 = load i8*, i8** %8
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.4, i64 0, i64 0), i32 %125, i32 %126, i8* %127)
br label %136
129: ; preds = %119
%130 = load i32, i32* @stderr
%131 = load i32, i32* %15
%132 = load i32, i32* @errno
%133 = call i8* @strerror(i32 %132)
%134 = call i32 (i32, i8*, ...) @fprintf(i32 %130, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %131, i8* %133)
%135 = call i32 @exit(i32 1)
unreachable
136: ; preds = %124
br label %137
137: ; preds = %136, %118
%138 = load i32, i32* %15
%139 = call i64 @listen(i32 %138, i32 5)
%140 = icmp slt i64 %139, 0
br i1 %140, label %141, label %144
141: ; preds = %137
%142 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%143 = call i32 @exit(i32 1)
unreachable
144: ; preds = %137
%145 = load i32, i32* %14
%146 = icmp ne i32 %145, 0
br i1 %146, label %153, label %147
147: ; preds = %144
%148 = call i64 @daemon(i32 1, i32 0)
%149 = icmp slt i64 %148, 0
br i1 %149, label %150, label %153
150: ; preds = %147
%151 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%152 = call i32 @exit(i32 1)
unreachable
153: ; preds = %147, %144
br label %154
154: ; preds = %153, %210
%155 = load i32, i32* %13
%156 = icmp eq i32 %155, 2
br i1 %156, label %160, label %157
157: ; preds = %154
%158 = load i32, i32* %13
%159 = icmp eq i32 %158, 0
br i1 %159, label %160, label %169
160: ; preds = %157, %154
%161 = load i32, i32* %15
%162 = bitcast %struct.sockaddr_in6* %20 to %struct.sockaddr*
%163 = call i32 @accept(i32 %161, %struct.sockaddr* %162, i32* %17)
store i32 %163, i32* %16
%164 = icmp slt i32 %163, 0
br i1 %164, label %165, label %168
165: ; preds = %160
%166 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
%167 = call i32 @exit(i32 1)
unreachable
168: ; preds = %160
br label %178
169: ; preds = %157
%170 = load i32, i32* %15
%171 = bitcast %struct.sockaddr_in* %19 to %struct.sockaddr*
%172 = call i32 @accept(i32 %170, %struct.sockaddr* %171, i32* %17)
store i32 %172, i32* %16
%173 = icmp slt i32 %172, 0
br i1 %173, label %174, label %177
174: ; preds = %169
%175 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
%176 = call i32 @exit(i32 1)
unreachable
177: ; preds = %169
br label %178
178: ; preds = %177, %168
%179 = call i32 (...) @fork()
store i32 %179, i32* %18
%180 = icmp slt i32 %179, 0
br i1 %180, label %181, label %183
181: ; preds = %178
%182 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.9, i64 0, i64 0))
br label %183
183: ; preds = %181, %178
%184 = load i32, i32* %18
%185 = icmp eq i32 %184, 0
br i1 %185, label %186, label %202
186: ; preds = %183
%187 = load i32, i32* %15
%188 = call i32 @close(i32 %187)
%189 = load i32, i32* %16
%190 = load i8*, i8** %10
%191 = load i8*, i8** %11
%192 = call i64 @clientresponse(i32 %189, i8* %190, i8* %191)
%193 = icmp sgt i64 %192, 0
br i1 %193, label %194, label %197
194: ; preds = %186
%195 = load i32, i32* %18
%196 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0), i32 %195)
br label %197
197: ; preds = %194, %186
%198 = load i8*, i8** %10
%199 = load i8*, i8** %12
%200 = call i32 @startlogging(i8* %198, i8* %199)
%201 = call i32 @exit(i32 0)
unreachable
202: ; preds = %183
%203 = load i32, i32* %16
%204 = call i32 @close(i32 %203)
br label %205
205: ; preds = %202
%206 = load i32, i32* %14
%207 = icmp ne i32 %206, 0
br i1 %207, label %208, label %210
208: ; preds = %205
%209 = call i32 @wait(i32* %21)
br label %210
210: ; preds = %208, %205
br label %154
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32 }
%struct.sockaddr_in = type { i8*, i8*, %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32 }
%struct.sockaddr_in6 = type { i8*, i8*, %struct.TYPE_4__ }
%struct.sockaddr = type { i32 }
@AF_INET6 = global i8* null
@SOCK_STREAM = global i32 0
@.str.1 = [20 x i8] c"Socket created: %d\0A\00"
@stderr = global i32 0
@.str.3 = [29 x i8] c"Unable to create socket: %s\0A\00"
@errno = global i32 0
@AF_INET = global i8* null
@in6addr_any = global %struct.TYPE_4__ zeroinitializer
@.str.4 = [65 x i8] c"Socket Binding Completed:\0ASocket: %d | Port: %d | Address: %s \0A\0A\00"
@.str.5 = [30 x i8] c"Unable to create bind %d: %s\0A\00"
@.str.6 = [15 x i8] c"server: listen\00"
@.str.7 = [7 x i8] c"daemon\00"
@.str.8 = [15 x i8] c"server: accept\00"
@.str.10 = [32 x i8] c"Client Response Error. PID: %d\0A\00"
@str = [38 x i8] c"\0A-----------Starting Sever-----------\00"
@str.12 = [51 x i8] c"Failed to fork process to response client request.\00"
@str.13 = [19 x i8] c"Binding socket ...\00"
define void @startsws(i8* %0, i32 %1, i8* %2, i8* %3, i8* %4, i32 %5, i32 %6) {
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca %struct.sockaddr_in6
%11 = alloca i32
%12 = bitcast i32* %8 to i8*
%13 = bitcast %struct.sockaddr_in* %9 to i8*
%14 = bitcast %struct.sockaddr_in6* %10 to i8*
%15 = bitcast i32* %11 to i8*
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%17 = icmp eq i32 %5, 0
%18 = and i32 %5, -3
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %31
20: ; preds = %7
%21 = load i8*, i8** @AF_INET6
%22 = load i32, i32* @SOCK_STREAM
%23 = tail call i32 @socket(i8* %21, i32 %22, i32 0)
%24 = icmp sgt i32 %23, 0
br i1 %24, label %42, label %25
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = tail call i8* @strerror(i32 %27)
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %7
%32 = load i8*, i8** @AF_INET
%33 = load i32, i32* @SOCK_STREAM
%34 = tail call i32 @socket(i8* %32, i32 %33, i32 0)
%35 = icmp sgt i32 %34, 0
br i1 %35, label %65, label %36
36: ; preds = %31
%37 = load i32, i32* @stderr
%38 = load i32, i32* @errno
%39 = tail call i8* @strerror(i32 %38)
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = tail call i32 @exit(i32 1)
unreachable
42: ; preds = %20
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.13, i64 0, i64 0))
br i1 %17, label %45, label %48
45: ; preds = %42
%46 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %10, i64 0, i32 2, i32 0
%47 = load i32, i32* getelementptr inbounds (%struct.TYPE_4__, %struct.TYPE_4__* @in6addr_any, i64 0, i32 0)
store i32 %47, i32* %46
br label %51
48: ; preds = %42
%49 = load i8*, i8** @AF_INET6
%50 = tail call i32 @inet_pton(i8* %49, i8* %0, i32 undef)
br label %51
51: ; preds = %45, %48
%52 = load i8*, i8** @AF_INET6
%53 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %10, i64 0, i32 1
store i8* %52, i8** %53
%54 = tail call i8* @htons(i32 %1)
%55 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %10, i64 0, i32 0
store i8* %54, i8** %55
%56 = bitcast %struct.sockaddr_in6* %10 to %struct.sockaddr*
%57 = call i64 @bind(i32 %23, %struct.sockaddr* %56, i32 24)
%58 = icmp eq i64 %57, 0
br i1 %58, label %83, label %59
59: ; preds = %51
%60 = load i32, i32* @stderr
%61 = load i32, i32* @errno
%62 = call i8* @strerror(i32 %61)
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %23, i8* %62)
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %31
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%67 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.13, i64 0, i64 0))
%68 = tail call i32 @inet_addr(i8* %0)
%69 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 2, i32 0
store i32 %68, i32* %69
%70 = load i8*, i8** @AF_INET
%71 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 1
store i8* %70, i8** %71
%72 = tail call i8* @htons(i32 %1)
%73 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 0
store i8* %72, i8** %73
%74 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%75 = call i64 @bind(i32 %34, %struct.sockaddr* %74, i32 24)
%76 = icmp eq i64 %75, 0
br i1 %76, label %83, label %77
77: ; preds = %65
%78 = load i32, i32* @stderr
%79 = load i32, i32* @errno
%80 = call i8* @strerror(i32 %79)
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %34, i8* %80)
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %65, %51
%84 = phi i32 [ %23, %51 ], [ %34, %65 ]
%85 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.4, i64 0, i64 0), i32 %84, i32 %1, i8* %0)
%86 = call i64 @listen(i32 %84, i32 5)
%87 = icmp slt i64 %86, 0
br i1 %87, label %88, label %91
88: ; preds = %83
%89 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%90 = call i32 @exit(i32 1)
unreachable
91: ; preds = %83
%92 = icmp eq i32 %6, 0
br i1 %92, label %93, label %99
93: ; preds = %91
%94 = call i64 @daemon(i32 1, i32 0)
%95 = icmp slt i64 %94, 0
br i1 %95, label %96, label %99
96: ; preds = %93
%97 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%98 = call i32 @exit(i32 1)
unreachable
99: ; preds = %93, %91
%100 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%101 = bitcast %struct.sockaddr_in6* %10 to %struct.sockaddr*
br label %102
102: ; preds = %136, %99
br i1 %19, label %103, label %109
103: ; preds = %102
%104 = call i32 @accept(i32 %84, %struct.sockaddr* %101, i32* %8)
%105 = icmp slt i32 %104, 0
br i1 %105, label %106, label %115
106: ; preds = %103
%107 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
%108 = call i32 @exit(i32 1)
unreachable
109: ; preds = %102
%110 = call i32 @accept(i32 %84, %struct.sockaddr* %100, i32* %8)
%111 = icmp slt i32 %110, 0
br i1 %111, label %112, label %115
112: ; preds = %109
%113 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
%114 = call i32 @exit(i32 1)
unreachable
115: ; preds = %109, %103
%116 = phi i32 [ %104, %103 ], [ %110, %109 ]
%117 = call i32 (...) @fork()
%118 = icmp slt i32 %117, 0
br i1 %118, label %119, label %121
119: ; preds = %115
%120 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.12, i64 0, i64 0))
br label %132
121: ; preds = %115
%122 = icmp eq i32 %117, 0
br i1 %122, label %123, label %132
123: ; preds = %121
%124 = call i32 @close(i32 %84)
%125 = call i64 @clientresponse(i32 %116, i8* %2, i8* %3)
%126 = icmp sgt i64 %125, 0
br i1 %126, label %127, label %129
127: ; preds = %123
%128 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0), i32 0)
br label %129
129: ; preds = %127, %123
%130 = call i32 @startlogging(i8* %2, i8* %4)
%131 = call i32 @exit(i32 0)
unreachable
132: ; preds = %119, %121
%133 = call i32 @close(i32 %116)
br i1 %92, label %136, label %134
134: ; preds = %132
%135 = call i32 @wait(i32* %11)
br label %136
136: ; preds = %134, %132
br label %102
}