#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__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ address;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
scalar_t__ listen(int, int);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
void startsws(char *i_address, int p_port) {
  int bufsize = 1024;
  char *buffer = malloc(bufsize);
  int socket_fd, newsocket_fd;
  socklen_t addrlen;
  struct sockaddr_in address;
  printf("\n-----------Starting Sever-----------\n");
  if ((socket_fd = socket(AF_INET, SOCK_STREAM, 0)) > 0) {
    printf("Socket created: %d\n", socket_fd);
    printf("Binding socket ...\n");
    printf(
        "(Please re-run sws if pending a long time for socket binging.)\n\n");
  }
  address.sin_family = AF_INET;
  address.sin_addr.s_addr = inet_addr(i_address);
  address.sin_port = htons(p_port);
  if (bind(socket_fd, (struct sockaddr *)&address, sizeof(address)) == 0) {
    printf(
        "Socket Binding Completed:\n Socket: %d | Port: %d | Address: %s \n\n",
        socket_fd, p_port, i_address);
  }
  while (1) {
    if (listen(socket_fd, 5) < 0) {
      perror("server: listen");
      exit(1);
    }
    if ((newsocket_fd =
             accept(socket_fd, (struct sockaddr *)&address, &addrlen)) < 0) {
      perror("server: accept");
      exit(1);
    }
    if (newsocket_fd > 0) {
      printf("-----------------------");
      printf("Client~ INFO");
      printf("-----------------------\n");
    }
    recv(newsocket_fd, buffer, bufsize, 0);
    printf("%s\n", buffer);
    write(newsocket_fd, buffer, 100);
    close(newsocket_fd);
  }
  free(buffer);
  close(socket_fd);
}


x86 assembly (clang, -O0):
<startsws>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x400,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    1252 <startsws+0x82>
mov    -0x1c(%rbp),%esi
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2d8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x2c(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
cmp    $0x0,%rax
jne    12a8 <startsws+0xd8>
mov    -0x1c(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rcx
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12ad <startsws+0xdd>
mov    -0x1c(%rbp),%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
cmp    $0x0,%rax
jge    12da <startsws+0x10a>
lea    0xe07(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x1c(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    130c <startsws+0x13c>
lea    0xde4(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
cmpl   $0x0,-0x20(%rbp)
jle    1340 <startsws+0x170>
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    -0x18(%rbp),%rsi
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x64,%edx
call   1040 <write@plt>
mov    -0x20(%rbp),%edi
call   1070 <close@plt>
jmp    12ad <startsws+0xdd>

x86 assembly (clang, -O2):
<startsws>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r15d
mov    %rdi,%r14
mov    $0x400,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
lea    0xe79(%rip),%rdi
call   1040 <puts@plt>
mov    0x2dd4(%rip),%r12
mov    (%r12),%edi
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    1256 <startsws+0x76>
lea    0xdcb(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe7a(%rip),%rdi
call   1040 <puts@plt>
lea    0xe81(%rip),%rdi
call   1040 <puts@plt>
mov    (%r12),%eax
mov    %eax,0x10(%rsp)
mov    %r14,%rdi
call   1090 <inet_addr@plt>
mov    %eax,0xc(%rsp)
mov    %r15d,%edi
call   1060 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   10c0 <bind@plt>
test   %rax,%rax
jne    12a2 <startsws+0xc2>
lea    0xd81(%rip),%rdi
mov    %ebp,%esi
mov    %r15d,%edx
mov    %r14,%rcx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
test   %rax,%rax
jns    12bf <startsws+0xdf>
lea    0xd9c(%rip),%rdi
jmp    1362 <startsws+0x182>
lea    0x8(%rsp),%r14
lea    0x14(%rsp),%r15
lea    0xdd7(%rip),%r12
jmp    1323 <startsws+0x143>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1050 <write@plt>
mov    %r13d,%edi
call   1080 <close@plt>
mov    %ebp,%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
test   %rax,%rax
js     12b3 <startsws+0xd3>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   10e0 <accept@plt>
test   %eax,%eax
js     135b <startsws+0x17b>
mov    %eax,%r13d
je     12e0 <startsws+0x100>
mov    %r12,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd2a(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
jmp    12e0 <startsws+0x100>
lea    0xd03(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [39 x i8] c"\0A-----------Starting Sever-----------\0A\00"
@AF_INET = global i32 0
@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"
@.str.3 = [65 x i8] c"(Please re-run sws if pending a long time for socket binging.)\0A\0A\00"
@.str.4 = [66 x i8] c"Socket Binding Completed:\0A Socket: %d | Port: %d | Address: %s \0A\0A\00"
@.str.5 = [15 x i8] c"server: listen\00"
@.str.6 = [15 x i8] c"server: accept\00"
@.str.7 = [24 x i8] c"-----------------------\00"
@.str.8 = [13 x i8] c"Client~ INFO\00"
@.str.9 = [25 x i8] c"-----------------------\0A\00"
@.str.10 = [4 x i8] c"%s\0A\00"
define void @startsws(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 1024, i32* %5
%11 = load i32, i32* %5
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %6
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %7
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %2
%19 = load i32, i32* %7
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %18, %2
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %24, i32* %25
%26 = load i8*, i8** %3
%27 = call i32 @inet_addr(i8* %26)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i32 0, i32 0
store i32 %27, i32* %29
%30 = load i32, i32* %4
%31 = call i32 @htons(i32 %30)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %31, i32* %32
%33 = load i32, i32* %7
%34 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%35 = call i64 @bind(i32 %33, %struct.sockaddr* %34, i32 12)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %23
%38 = load i32, i32* %7
%39 = load i32, i32* %4
%40 = load i8*, i8** %3
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i64 0, i64 0), i32 %38, i32 %39, i8* %40)
br label %42
42: ; preds = %37, %23
br label %43
43: ; preds = %42, %65
%44 = load i32, i32* %7
%45 = call i64 @listen(i32 %44, i32 5)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %43
%51 = load i32, i32* %7
%52 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%53 = call i32 @accept(i32 %51, %struct.sockaddr* %52, i32* %9)
store i32 %53, i32* %8
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %50
%56 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %50
%59 = load i32, i32* %8
%60 = icmp sgt i32 %59, 0
br i1 %60, label %61, label %65
61: ; preds = %58
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0))
br label %65
65: ; preds = %61, %58
%66 = load i32, i32* %8
%67 = load i8*, i8** %6
%68 = load i32, i32* %5
%69 = call i32 @recv(i32 %66, i8* %67, i32 %68, i32 0)
%70 = load i8*, i8** %6
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* %70)
%72 = load i32, i32* %8
%73 = load i8*, i8** %6
%74 = call i32 @write(i32 %72, i8* %73, i32 100)
%75 = load i32, i32* %8
%76 = call i32 @close(i32 %75)
br label %43
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [20 x i8] c"Socket created: %d\0A\00"
@.str.4 = [66 x i8] c"Socket Binding Completed:\0A Socket: %d | Port: %d | Address: %s \0A\0A\00"
@.str.5 = [15 x i8] c"server: listen\00"
@.str.6 = [15 x i8] c"server: accept\00"
@.str.8 = [13 x i8] c"Client~ INFO\00"
@str = [38 x i8] c"\0A-----------Starting Sever-----------\00"
@str.11 = [24 x i8] c"-----------------------\00"
@str.12 = [19 x i8] c"Binding socket ...\00"
@str.13 = [64 x i8] c"(Please re-run sws if pending a long time for socket binging.)\0A\00"
define void @startsws(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%6 = bitcast i32* %3 to i8*
%7 = bitcast %struct.sockaddr_in* %4 to i8*
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.12, i64 0, i64 0))
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str.13, i64 0, i64 0))
br label %17
17: ; preds = %13, %2
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %18, i32* %19
%20 = tail call i32 @inet_addr(i8* %0)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %20, i32* %21
%22 = tail call i32 @htons(i32 %1)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %22, i32* %23
%24 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%25 = call i64 @bind(i32 %11, %struct.sockaddr* %24, i32 12)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %17
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i64 0, i64 0), i32 %11, i32 %1, i8* %0)
br label %29
29: ; preds = %27, %17
%30 = call i64 @listen(i32 %11, i32 5)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %47, %29
%33 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %29, %47
%36 = call i32 @accept(i32 %11, %struct.sockaddr* %24, i32* %3)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %35
%42 = icmp eq i32 %36, 0
br i1 %42, label %47, label %43
43: ; preds = %41
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.11, i64 0, i64 0))
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.11, i64 0, i64 0))
br label %47
47: ; preds = %43, %41
%48 = call i32 @recv(i32 %36, i8* %5, i32 1024, i32 0)
%49 = call i32 @puts(i8* dereferenceable(1) %5)
%50 = call i32 @write(i32 %36, i8* %5, i32 100)
%51 = call i32 @close(i32 %36)
%52 = call i64 @listen(i32 %11, i32 5)
%53 = icmp slt i64 %52, 0
br i1 %53, label %32, label %35
}