#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*/ serv_addr;
typedef int /*<<< orphan*/ cli_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int atoi(char *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ printf(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ work(int, char **, char *);
int main(int argc, char *argv[]) {
  int sockfd, portno, clilen, newsockfd, pid;
  struct sockaddr_in serv_addr, cli_addr;
  char *arr[4], *file_buffer;
  if (argc < 2) {
    fprintf(stderr, " ERROR!! No Port Provided");
    exit(1);
  }
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0)
    error("ERROR !! Could not open socket");
  bzero((char *)&serv_addr, sizeof(serv_addr));
  portno = atoi(argv[1]);
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = INADDR_ANY;
  serv_addr.sin_port = htons(portno);
  if (bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
    error("ERROR!! on Binding");
  listen(sockfd, 5);
  printf("\nServer is listening for connections...\n");
  clilen = sizeof(cli_addr);
  while (1) {
    newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen);
    if (newsockfd < 0)
      error("ERROR !! on accept");
    pid = fork();
    if (pid < 0)
      error("ERROR !! on fork");
    if (pid == 0) {
      close(sockfd);
      work(newsockfd, arr, file_buffer);
      exit(0);
    } else
      close(newsockfd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    121f <main+0x3f>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
lea    0xdf0(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1251 <main+0x71>
lea    0xdce(%rip),%rdi
call   10a0 <error@plt>
lea    -0x30(%rbp),%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
cmp    $0x0,%rax
jge    12b9 <main+0xd9>
lea    0xd85(%rip),%rdi
call   10a0 <error@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   1080 <listen@plt>
lea    0xd7f(%rip),%rdi
call   1050 <printf@plt>
movl   $0xc,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   10c0 <accept@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1302 <main+0x122>
lea    0xd78(%rip),%rdi
call   10a0 <error@plt>
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1322 <main+0x142>
lea    0xd6b(%rip),%rdi
call   10a0 <error@plt>
cmpl   $0x0,-0x24(%rbp)
jne    134b <main+0x16b>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x20(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    -0x68(%rbp),%rdx
call   1030 <work@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
mov    -0x20(%rbp),%edi
call   1060 <close@plt>
jmp    12d9 <main+0xf9>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
cmp    $0x1,%edi
jg     1212 <main+0x32>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    %rsi,%rbp
mov    0x2dcc(%rip),%r15
mov    (%r15),%edi
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1241 <main+0x61>
lea    0xdde(%rip),%rdi
call   10a0 <error@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    0x8(%rbp),%rdi
call   10d0 <atoi@plt>
mov    (%r15),%ecx
mov    %ecx,0x18(%rsp)
mov    0x2d76(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x14(%rsp)
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
test   %rax,%rax
jns    129b <main+0xbb>
lea    0xda3(%rip),%rdi
call   10a0 <error@plt>
mov    %ebx,%edi
mov    $0x5,%esi
call   1080 <listen@plt>
lea    0xdc2(%rip),%rdi
call   1030 <puts@plt>
movl   $0xc,0xc(%rsp)
lea    0x20(%rsp),%r14
lea    0xc(%rsp),%r15
lea    0xd80(%rip),%r12
lea    0xd8c(%rip),%r13
jmp    12ef <main+0x10f>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
call   10a0 <error@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   10c0 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    130a <main+0x12a>
mov    %r12,%rdi
call   10a0 <error@plt>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
js     12e0 <main+0x100>
jne    12e8 <main+0x108>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0x30(%rsp),%rsi
mov    %ebp,%edi
call   1040 <work@plt>
xor    %edi,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [26 x i8] c" ERROR!! No Port Provided\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [31 x i8] c"ERROR !! Could not open socket\00"
@INADDR_ANY = global i32 0
@.str.2 = [19 x i8] c"ERROR!! on Binding\00"
@.str.3 = [41 x i8] c"\0AServer is listening for connections...\0A\00"
@.str.4 = [19 x i8] c"ERROR !! on accept\00"
@.str.5 = [17 x i8] c"ERROR !! on fork\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.sockaddr_in
%12 = alloca %struct.sockaddr_in
%13 = alloca [4 x i8*]
%14 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i32, i32* @AF_INET
%23 = load i32, i32* @SOCK_STREAM
%24 = call i32 @socket(i32 %22, i32 %23, i32 0)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = call i32 @error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %21
%30 = bitcast %struct.sockaddr_in* %11 to i8*
%31 = call i32 @bzero(i8* %30, i32 12)
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
store i32 %35, i32* %7
%36 = load i32, i32* @AF_INET
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %36, i32* %37
%38 = load i32, i32* @INADDR_ANY
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%40 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %39, i32 0, i32 0
store i32 %38, i32* %40
%41 = load i32, i32* %7
%42 = call i32 @htons(i32 %41)
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
store i32 %42, i32* %43
%44 = load i32, i32* %6
%45 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%46 = call i64 @bind(i32 %44, %struct.sockaddr* %45, i32 12)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %29
%49 = call i32 @error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %50
50: ; preds = %48, %29
%51 = load i32, i32* %6
%52 = call i32 @listen(i32 %51, i32 5)
%53 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
store i32 12, i32* %8
br label %54
54: ; preds = %50, %82
%55 = load i32, i32* %6
%56 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%57 = call i32 @accept(i32 %55, %struct.sockaddr* %56, i32* %8)
store i32 %57, i32* %9
%58 = load i32, i32* %9
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %54
%61 = call i32 @error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %62
62: ; preds = %60, %54
%63 = call i32 (...) @fork()
store i32 %63, i32* %10
%64 = load i32, i32* %10
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %62
%67 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %68
68: ; preds = %66, %62
%69 = load i32, i32* %10
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %79
71: ; preds = %68
%72 = load i32, i32* %6
%73 = call i32 @close(i32 %72)
%74 = load i32, i32* %9
%75 = getelementptr inbounds [4 x i8*], [4 x i8*]* %13, i64 0, i64 0
%76 = load i8*, i8** %14
%77 = call i32 @work(i32 %74, i8** %75, i8* %76)
%78 = call i32 @exit(i32 0)
unreachable
79: ; preds = %68
%80 = load i32, i32* %9
%81 = call i32 @close(i32 %80)
br label %82
82: ; preds = %79
br label %54
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [26 x i8] c" ERROR!! No Port Provided\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [31 x i8] c"ERROR !! Could not open socket\00"
@INADDR_ANY = global i32 0
@.str.2 = [19 x i8] c"ERROR!! on Binding\00"
@.str.4 = [19 x i8] c"ERROR !! on accept\00"
@.str.5 = [17 x i8] c"ERROR !! on fork\00"
@str = [40 x i8] c"\0AServer is listening for connections...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca [4 x i8*]
%7 = bitcast i32* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = bitcast [4 x i8*]* %6 to i8*
%11 = icmp slt i32 %0, 2
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = tail call i32 @socket(i32 %17, i32 %18, i32 0)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = tail call i32 @error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %16
%24 = call i32 @bzero(i8* %8, i32 12)
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = tail call i32 @atoi(i8* %26)
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %28, i32* %29
%30 = load i32, i32* @INADDR_ANY
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %30, i32* %31
%32 = tail call i32 @htons(i32 %27)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %32, i32* %33
%34 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%35 = call i64 @bind(i32 %19, %struct.sockaddr* %34, i32 12)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %23
%38 = call i32 @error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %37, %23
%40 = call i32 @listen(i32 %19, i32 5)
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
store i32 12, i32* %3
%42 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
br label %43
43: ; preds = %60, %39
%44 = call i32 @accept(i32 %19, %struct.sockaddr* %42, i32* %3)
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 @error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %48
48: ; preds = %46, %43
%49 = call i32 (...) @fork()
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %48
%52 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %60
53: ; preds = %48
%54 = icmp eq i32 %49, 0
br i1 %54, label %55, label %60
55: ; preds = %53
%56 = call i32 @close(i32 %19)
%57 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 0
%58 = call i32 @work(i32 %44, i8** %57, i8* undef)
%59 = call i32 @exit(i32 0)
unreachable
60: ; preds = %51, %53
%61 = call i32 @close(i32 %44)
br label %43
}