#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;
};
struct hostent {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ serveraddr;
typedef int /*<<< orphan*/ clientaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int atoi(char *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ create_storage();
int /*<<< orphan*/ executeReq(int, int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int listenfd, connfd, port, key;
  socklen_t client_length;
  struct sockaddr_in clientaddr;
  struct sockaddr_in serveraddr;
  struct hostent *hp;
  char *haddrp;
  unsigned short client_port;
  if (argc != 3) {
    fprintf(stderr, "usage: %s <port> <key>\n", argv[0]);
    exit(0);
  }
  port = atoi(argv[1]);
  key = atoi(argv[2]);
  if ((listenfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
    fprintf(stderr, "Nope. No socket obtained.\n");
    exit(-1);
  }
  memset(&serveraddr, 0, sizeof(struct sockaddr_in));
  serveraddr.sin_family = AF_INET;
  serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
  serveraddr.sin_port = htons(port);
  if (bind(listenfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr)) < 0) {
    printf("Could not bind to port, sir.\n");
    exit(-1);
  }
  if (listen(listenfd, 5) < 0) {
    fprintf(stderr, "Listening(...) Call failed. Hanging up now.\n");
    exit(-1);
  }
  create_storage();
  while (1) {
    client_length = sizeof(clientaddr);
    connfd = accept(listenfd, (struct sockaddr *)&clientaddr, &client_length);
    if (connfd < 0) {
      fprintf(stderr, "Accept(...) call failed.\n");
      exit(-1);
    }
    executeReq(port, key, connfd);
    close(connfd);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1225 <main+0x45>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xde9(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
mov    0x2d6b(%rip),%rax
mov    (%rax),%esi
mov    0x2d7a(%rip),%rax
mov    (%rax),%edx
call   1100 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1292 <main+0xb2>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
lea    0xd97(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2d3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x40(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0x0,%rax
jge    12fb <main+0x11b>
lea    0xd47(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
cmp    $0x0,%rax
jge    1333 <main+0x153>
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
lea    0xd2f(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    $0x0,%al
call   10b0 <create_storage@plt>
movl   $0xc,-0x24(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    137f <main+0x19f>
mov    0x2c63(%rip),%rax
mov    (%rax),%edi
lea    0xd10(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1080 <executeReq@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
jmp    133a <main+0x15a>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1253 <main+0x73>
mov    0x8(%rbx),%rdi
call   10e0 <atoi@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
call   10e0 <atoi@plt>
mov    %eax,%r15d
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
mov    0x2db1(%rip),%rax
mov    (%rax),%edx
call   1100 <socket@plt>
test   %eax,%eax
jns    1274 <main+0x94>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
lea    0xdd6(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd9a(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    %eax,%r12d
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2d56(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0xc(%rsp)
mov    %r14d,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
test   %rax,%rax
jns    12e1 <main+0x101>
lea    0xda8(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    %r12d,%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
test   %rax,%rax
jns    1308 <main+0x128>
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
lea    0xd30(%rip),%rsi
jmp    1242 <main+0x62>
xor    %eax,%eax
call   10b0 <create_storage@plt>
movl   $0xc,0x4(%rsp)
lea    0x18(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %r12d,%edi
call   10d0 <accept@plt>
test   %eax,%eax
js     1370 <main+0x190>
mov    %eax,%ebp
lea    0x18(%rsp),%r13
lea    0x4(%rsp),%rbx
nopl   0x0(%rax)
mov    %r14d,%edi
mov    %r15d,%esi
mov    %ebp,%edx
call   1080 <executeReq@plt>
mov    %ebp,%edi
call   1070 <close@plt>
movl   $0xc,0x4(%rsp)
mov    %r12d,%edi
mov    %r13,%rsi
mov    %rbx,%rdx
call   10d0 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1340 <main+0x160>
mov    0x2c51(%rip),%rax
mov    (%rax),%edi
lea    0xce0(%rip),%rsi
jmp    1242 <main+0x62>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [24 x i8] c"usage: %s <port> <key>\0A\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.1 = [27 x i8] c"Nope. No socket obtained.\0A\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [30 x i8] c"Could not bind to port, sir.\0A\00"
@.str.3 = [45 x i8] c"Listening(...) Call failed. Hanging up now.\0A\00"
@.str.4 = [26 x i8] c"Accept(...) call failed.\0A\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 %struct.hostent*
%14 = alloca i8*
%15 = alloca i16
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 3
br i1 %17, label %18, label %25
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %8
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %9
%34 = load i32, i32* @PF_INET
%35 = load i32, i32* @SOCK_STREAM
%36 = load i32, i32* @IPPROTO_TCP
%37 = call i32 @socket(i32 %34, i32 %35, i32 %36)
store i32 %37, i32* %6
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %25
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%42 = call i32 @exit(i32 -1)
unreachable
43: ; preds = %25
%44 = call i32 @memset(%struct.sockaddr_in* %12, i32 0, i32 12)
%45 = load i32, i32* @AF_INET
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %45, i32* %46
%47 = load i32, i32* @INADDR_ANY
%48 = call i32 @htonl(i32 %47)
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
%50 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %49, i32 0, i32 0
store i32 %48, i32* %50
%51 = load i32, i32* %8
%52 = call i32 @htons(i32 %51)
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
store i32 %52, i32* %53
%54 = load i32, i32* %6
%55 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%56 = call i64 @bind(i32 %54, %struct.sockaddr* %55, i32 12)
%57 = icmp slt i64 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %43
%59 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%60 = call i32 @exit(i32 -1)
unreachable
61: ; preds = %43
%62 = load i32, i32* %6
%63 = call i64 @listen(i32 %62, i32 5)
%64 = icmp slt i64 %63, 0
br i1 %64, label %65, label %69
65: ; preds = %61
%66 = load i32, i32* @stderr
%67 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
%68 = call i32 @exit(i32 -1)
unreachable
69: ; preds = %61
%70 = call i32 (...) @create_storage()
br label %71
71: ; preds = %69, %81
store i32 12, i32* %10
%72 = load i32, i32* %6
%73 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%74 = call i32 @accept(i32 %72, %struct.sockaddr* %73, i32* %10)
store i32 %74, i32* %7
%75 = load i32, i32* %7
%76 = icmp slt i32 %75, 0
br i1 %76, label %77, label %81
77: ; preds = %71
%78 = load i32, i32* @stderr
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%80 = call i32 @exit(i32 -1)
unreachable
81: ; preds = %71
%82 = load i32, i32* %8
%83 = load i32, i32* %9
%84 = load i32, i32* %7
%85 = call i32 @executeReq(i32 %82, i32 %83, i32 %84)
%86 = load i32, i32* %7
%87 = call i32 @close(i32 %86)
br label %71
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [24 x i8] c"usage: %s <port> <key>\0A\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.1 = [27 x i8] c"Nope. No socket obtained.\0A\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.3 = [45 x i8] c"Listening(...) Call failed. Hanging up now.\0A\00"
@.str.4 = [26 x i8] c"Accept(...) call failed.\0A\00"
@str = [29 x i8] c"Could not bind to port, sir.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = bitcast i32* %3 to i8*
%7 = bitcast %struct.sockaddr_in* %4 to i8*
%8 = bitcast %struct.sockaddr_in* %5 to i8*
%9 = icmp eq i32 %0, 3
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %1
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = tail call i32 @exit(i32 0)
unreachable
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
%22 = load i32, i32* @PF_INET
%23 = load i32, i32* @SOCK_STREAM
%24 = load i32, i32* @IPPROTO_TCP
%25 = tail call i32 @socket(i32 %22, i32 %23, i32 %24)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %15
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%30 = tail call i32 @exit(i32 -1)
unreachable
31: ; preds = %15
%32 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 12)
%33 = load i32, i32* @AF_INET
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %33, i32* %34
%35 = load i32, i32* @INADDR_ANY
%36 = call i32 @htonl(i32 %35)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
store i32 %36, i32* %37
%38 = call i32 @htons(i32 %18)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i32 %38, i32* %39
%40 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%41 = call i64 @bind(i32 %25, %struct.sockaddr* %40, i32 12)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %31
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%45 = call i32 @exit(i32 -1)
unreachable
46: ; preds = %31
%47 = call i64 @listen(i32 %25, i32 5)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %46
%50 = load i32, i32* @stderr
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
%52 = call i32 @exit(i32 -1)
unreachable
53: ; preds = %46
%54 = call i32 (...) @create_storage()
%55 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
store i32 12, i32* %3
%56 = call i32 @accept(i32 %25, %struct.sockaddr* %55, i32* %3)
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %62, %53
%59 = load i32, i32* @stderr
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%61 = call i32 @exit(i32 -1)
unreachable
62: ; preds = %53, %62
%63 = phi i32 [ %66, %62 ], [ %56, %53 ]
%64 = call i32 @executeReq(i32 %18, i32 %21, i32 %63)
%65 = call i32 @close(i32 %63)
store i32 12, i32* %3
%66 = call i32 @accept(i32 %25, %struct.sockaddr* %55, i32* %3)
%67 = icmp slt i32 %66, 0
br i1 %67, label %58, label %62
}