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

/* Variables and functions */
int AF_INET;
int INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int atoi(char *);
int bind(int, struct sockaddr *, int);
int close(int);
int /*<<< orphan*/ getsockname(int, struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int);
int listen(int, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int socket(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ write(int, char *, scalar_t__);
int main(int argc, char *argv[]) {
  int hSocket, hServerSocket;
  struct hostent *pHostInfo;
  struct sockaddr_in Address;
  int nAddressSize = sizeof(struct sockaddr_in);
  char pBuffer[100];
  int nHostPort;
  if (argc < 2) {
    printf("\nUsage: server host-port\n");
    return 0;
  } else {
    nHostPort = atoi(argv[1]);
  }
  printf("\nStarting server");
  printf("\nMaking socket");
  hServerSocket = socket(AF_INET, SOCK_STREAM, 0);
  if (hServerSocket == -1) {
    printf("\nCould not make a socket\n");
    return 0;
  }
  Address.sin_addr.s_addr = INADDR_ANY;
  Address.sin_port = htons(nHostPort);
  Address.sin_family = AF_INET;
  printf("\nBinding to port %d", nHostPort);
  if (bind(hServerSocket, (struct sockaddr *)&Address, sizeof(Address)) == -1) {
    printf("\nCould not connect to host\n");
    return 0;
  }
  getsockname(hServerSocket, (struct sockaddr *)&Address,
              (socklen_t *)&nAddressSize);
  printf("opened socket as fd (%d) on port (%d) for stream i/o\n",
         hServerSocket, ntohs(Address.sin_port));
  printf("Server\n              sin_family        = %d\n              "
         "sin_addr.s_addr   = %d\n              sin_port          = %d\n",
         Address.sin_family, Address.sin_addr.s_addr, ntohs(Address.sin_port));
  printf("\nMaking a listen queue of %d elements", 5);
  if (listen(hServerSocket, 5) == -1) {
    printf("\nCould not listen\n");
    return 0;
  }
  for (;;) {
    printf("\nWaiting for a connection\n");
    hSocket = accept(hServerSocket, (struct sockaddr *)&Address,
                     (socklen_t *)&nAddressSize);
    printf("\nGot a connection from %X (%d)\n", Address.sin_addr.s_addr,
           ntohs(Address.sin_port));
    strcpy(pBuffer, "This is the message I'm sending back and forth");
    printf("\nSending \"%s\" to client", pBuffer);
    write(hSocket, pBuffer, strlen(pBuffer) + 1);
    memset(pBuffer, 0, sizeof(pBuffer));
    read(hSocket, pBuffer, 100);
    if (strcmp(pBuffer, "This is the message I'm sending back and forth") == 0)
      printf("\nThe messages match");
    else
      printf("\nSomething was changed in the message");
    printf("\nClosing the socket");
    if (close(hSocket) == -1) {
      printf("\nCould not close socket\n");
      return 0;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xc,-0x34(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1244 <main+0x44>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1525 <main+0x325>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1110 <atoi@plt>
mov    %eax,-0xa4(%rbp)
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
mov    0x2d4d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    12b3 <main+0xb3>
lea    0xd9a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1525 <main+0x325>
mov    0x2d26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0xa4(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2d14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0xa4(%rbp),%esi
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1321 <main+0x121>
lea    0xd5a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1525 <main+0x325>
mov    -0x18(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   1100 <getsockname@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0xb0(%rbp)
mov    -0x2c(%rbp),%edi
call   10d0 <ntohs@plt>
mov    -0xb0(%rbp),%esi
mov    %eax,%edx
lea    0xd33(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0xac(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0xa8(%rbp)
mov    -0x2c(%rbp),%edi
call   10d0 <ntohs@plt>
mov    -0xac(%rbp),%esi
mov    -0xa8(%rbp),%edx
mov    %eax,%ecx
lea    0xd33(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xd9c(%rip),%rdi
mov    $0x5,%esi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%edi
mov    $0x5,%esi
call   10c0 <listen@plt>
cmp    $0xffffffff,%eax
jne    13d1 <main+0x1d1>
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1525 <main+0x325>
jmp    13d6 <main+0x1d6>
lea    0xd8d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   10f0 <accept@plt>
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0xc0(%rbp)
mov    -0x2c(%rbp),%edi
call   10d0 <ntohs@plt>
mov    -0xc0(%rbp),%esi
mov    %eax,%edx
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xd79(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0xa0(%rbp),%rsi
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0xbc(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xb8(%rbp)
lea    -0xa0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xbc(%rbp),%edi
mov    -0xb8(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <write@plt>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1080 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x64,%edx
call   10a0 <read@plt>
lea    -0xa0(%rbp),%rdi
lea    0xcee(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
jne    14d9 <main+0x2d9>
lea    0xd1f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    14e7 <main+0x2e7>
lea    0xd20(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xd38(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
cmp    $0xffffffff,%eax
jne    1520 <main+0x320>
lea    0xd2d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1525 <main+0x325>
jmp    13d6 <main+0x1d6>
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
movl   $0xc,0xc(%rsp)
cmp    $0x1,%edi
jg     1237 <main+0x27>
lea    0x1002(%rip),%rdi
jmp    1455 <main+0x245>
mov    0x8(%rsi),%rdi
call   1120 <atoi@plt>
mov    %eax,%ebp
lea    0xdb7(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xdba(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2d83(%rip),%r14
mov    (%r14),%edi
mov    0x2d61(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
cmp    $0xffffffff,%eax
je     143c <main+0x22c>
mov    %eax,%ebx
mov    0x2d56(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
call   1070 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%r14),%eax
mov    %eax,(%rsp)
lea    0xd78(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10f0 <bind@plt>
cmp    $0xffffffff,%eax
je     1445 <main+0x235>
mov    %rsp,%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1110 <getsockname@plt>
mov    0x4(%rsp),%edi
call   10e0 <ntohs@plt>
lea    0xd4c(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x8(%rsp),%r14d
mov    (%rsp),%ebp
mov    0x4(%rsp),%edi
call   10e0 <ntohs@plt>
lea    0xd5f(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xdc1(%rip),%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebx,%edi
mov    $0x5,%esi
call   10d0 <listen@plt>
cmp    $0xffffffff,%eax
je     144e <main+0x23e>
lea    0xddf(%rip),%rbp
lea    0x10(%rsp),%r14
lea    0xe54(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xe55(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
mov    %rsp,%rsi
lea    0xc(%rsp),%rdx
call   1100 <accept@plt>
mov    %eax,%r13d
mov    0x4(%rsp),%edi
mov    0x8(%rsp),%r15d
call   10e0 <ntohs@plt>
lea    0xd74(%rip),%rdi
mov    %r15d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
lea    0xda5(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r13d,%edi
mov    %r14,%rsi
call   1050 <write@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1090 <memset@plt>
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x64,%edx
call   10b0 <read@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
lea    0xd7c(%rip),%rdi
lea    0xd61(%rip),%rax
cmove  %rax,%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r13d,%edi
call   10a0 <close@plt>
cmp    $0xffffffff,%eax
jne    1360 <main+0x150>
lea    0xd9c(%rip),%rdi
jmp    1455 <main+0x245>
lea    0xdd8(%rip),%rdi
jmp    1455 <main+0x245>
lea    0xdb4(%rip),%rdi
jmp    1455 <main+0x245>
lea    0xd99(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i32 }
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [26 x i8] c"\0AUsage: server host-port\0A\00"
@.str.1 = [17 x i8] c"\0AStarting server\00"
@.str.2 = [15 x i8] c"\0AMaking socket\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [26 x i8] c"\0ACould not make a socket\0A\00"
@INADDR_ANY = global i32 0
@.str.4 = [20 x i8] c"\0ABinding to port %d\00"
@.str.5 = [28 x i8] c"\0ACould not connect to host\0A\00"
@.str.6 = [54 x i8] c"opened socket as fd (%d) on port (%d) for stream i/o\0A\00"
@.str.7 = [119 x i8] c"Server\0A sin_family = %d\0A sin_addr.s_addr = %d\0A sin_port = %d\0A\00"
@.str.8 = [38 x i8] c"\0AMaking a listen queue of %d elements\00"
@.str.9 = [19 x i8] c"\0ACould not listen\0A\00"
@.str.10 = [27 x i8] c"\0AWaiting for a connection\0A\00"
@.str.11 = [32 x i8] c"\0AGot a connection from %X (%d)\0A\00"
@.str.12 = [47 x i8] c"This is the message I'm sending back and forth\00"
@.str.13 = [24 x i8] c"\0ASending \22%s\22 to client\00"
@.str.14 = [20 x i8] c"\0AThe messages match\00"
@.str.15 = [38 x i8] c"\0ASomething was changed in the message\00"
@.str.16 = [20 x i8] c"\0AClosing the socket\00"
@.str.17 = [25 x i8] c"\0ACould not close socket\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 %struct.hostent*
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca [100 x i8]
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 12, i32* %10
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %116
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %12
br label %22
22: ; preds = %17
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* @AF_INET
%26 = load i32, i32* @SOCK_STREAM
%27 = call i32 @socket(i32 %25, i32 %26, i32 0)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %22
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %116
32: ; preds = %22
%33 = load i32, i32* @INADDR_ANY
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
%35 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %34, i32 0, i32 0
store i32 %33, i32* %35
%36 = load i32, i32* %12
%37 = call i32 @htons(i32 %36)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %37, i32* %38
%39 = load i32, i32* @AF_INET
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %39, i32* %40
%41 = load i32, i32* %12
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %7
%44 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%45 = call i32 @bind(i32 %43, %struct.sockaddr* %44, i32 12)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %49
47: ; preds = %32
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %116
49: ; preds = %32
%50 = load i32, i32* %7
%51 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%52 = call i32 @getsockname(i32 %50, %struct.sockaddr* %51, i32* %10)
%53 = load i32, i32* %7
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%55 = load i32, i32* %54
%56 = call i32 @ntohs(i32 %55)
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.6, i64 0, i64 0), i32 %53, i32 %56)
%58 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%59 = load i32, i32* %58
%60 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
%61 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %60, i32 0, i32 0
%62 = load i32, i32* %61
%63 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%64 = load i32, i32* %63
%65 = call i32 @ntohs(i32 %64)
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([119 x i8], [119 x i8]* @.str.7, i64 0, i64 0), i32 %59, i32 %62, i32 %65)
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0), i32 5)
%68 = load i32, i32* %7
%69 = call i32 @listen(i32 %68, i32 5)
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %73
71: ; preds = %49
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %3
br label %116
73: ; preds = %49
br label %74
74: ; preds = %115, %73
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
%76 = load i32, i32* %7
%77 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%78 = call i32 @accept(i32 %76, %struct.sockaddr* %77, i32* %10)
store i32 %78, i32* %6
%79 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
%80 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %79, i32 0, i32 0
%81 = load i32, i32* %80
%82 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%83 = load i32, i32* %82
%84 = call i32 @ntohs(i32 %83)
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.11, i64 0, i64 0), i32 %81, i32 %84)
%86 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%87 = call i32 @strcpy(i8* %86, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.12, i64 0, i64 0))
%88 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.13, i64 0, i64 0), i8* %88)
%90 = load i32, i32* %6
%91 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%92 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%93 = call i64 @strlen(i8* %92)
%94 = add nsw i64 %93, 1
%95 = call i32 @write(i32 %90, i8* %91, i64 %94)
%96 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%97 = call i32 @memset(i8* %96, i32 0, i32 100)
%98 = load i32, i32* %6
%99 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%100 = call i32 @read(i32 %98, i8* %99, i32 100)
%101 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%102 = call i64 @strcmp(i8* %101, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.12, i64 0, i64 0))
%103 = icmp eq i64 %102, 0
br i1 %103, label %104, label %106
104: ; preds = %74
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.14, i64 0, i64 0))
br label %108
106: ; preds = %74
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.15, i64 0, i64 0))
br label %108
108: ; preds = %106, %104
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.16, i64 0, i64 0))
%110 = load i32, i32* %6
%111 = call i32 @close(i32 %110)
%112 = icmp eq i32 %111, -1
br i1 %112, label %113, label %115
113: ; preds = %108
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.17, i64 0, i64 0))
store i32 0, i32* %3
br label %116
115: ; preds = %108
br label %74
116: ; preds = %113, %71, %47, %30, %15
%117 = load i32, i32* %3
ret i32 %117
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32 }
%struct.sockaddr = type { i32 }
@.str.1 = [17 x i8] c"\0AStarting server\00"
@.str.2 = [15 x i8] c"\0AMaking socket\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@.str.4 = [20 x i8] c"\0ABinding to port %d\00"
@.str.6 = [54 x i8] c"opened socket as fd (%d) on port (%d) for stream i/o\0A\00"
@.str.7 = [119 x i8] c"Server\0A sin_family = %d\0A sin_addr.s_addr = %d\0A sin_port = %d\0A\00"
@.str.8 = [38 x i8] c"\0AMaking a listen queue of %d elements\00"
@.str.11 = [32 x i8] c"\0AGot a connection from %X (%d)\0A\00"
@.str.12 = [47 x i8] c"This is the message I'm sending back and forth\00"
@.str.13 = [24 x i8] c"\0ASending \22%s\22 to client\00"
@.str.14 = [20 x i8] c"\0AThe messages match\00"
@.str.15 = [38 x i8] c"\0ASomething was changed in the message\00"
@.str.16 = [20 x i8] c"\0AClosing the socket\00"
@str = [26 x i8] c"\0AWaiting for a connection\00"
@str.18 = [24 x i8] c"\0ACould not close socket\00"
@str.19 = [18 x i8] c"\0ACould not listen\00"
@str.20 = [27 x i8] c"\0ACould not connect to host\00"
@str.21 = [25 x i8] c"\0ACould not make a socket\00"
@str.22 = [25 x i8] c"\0AUsage: server host-port\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [100 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = bitcast i32* %4 to i8*
store i32 12, i32* %4
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%9 = icmp slt i32 %0, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.22, i64 0, i64 0))
br label %75
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%18 = load i32, i32* @AF_INET
%19 = load i32, i32* @SOCK_STREAM
%20 = tail call i32 @socket(i32 %18, i32 %19, i32 0)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %12
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.21, i64 0, i64 0))
br label %75
24: ; preds = %12
%25 = load i32, i32* @INADDR_ANY
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2, i32 0
store i32 %25, i32* %26
%27 = tail call i32 @htons(i32 %15)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %27, i32* %28
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %29, i32* %30
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %15)
%32 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%33 = call i32 @bind(i32 %20, %struct.sockaddr* %32, i32 12)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %24
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.20, i64 0, i64 0))
br label %75
37: ; preds = %24
%38 = call i32 @getsockname(i32 %20, %struct.sockaddr* %32, i32* %4)
%39 = load i32, i32* %28
%40 = call i32 @ntohs(i32 %39)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.6, i64 0, i64 0), i32 %20, i32 %40)
%42 = load i32, i32* %30
%43 = load i32, i32* %26
%44 = load i32, i32* %28
%45 = call i32 @ntohs(i32 %44)
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([119 x i8], [119 x i8]* @.str.7, i64 0, i64 0), i32 %42, i32 %43, i32 %45)
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0), i32 5)
%48 = call i32 @listen(i32 %20, i32 5)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %52
50: ; preds = %37
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.19, i64 0, i64 0))
br label %75
52: ; preds = %37, %52
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%54 = call i32 @accept(i32 %20, %struct.sockaddr* %32, i32* %4)
%55 = load i32, i32* %26
%56 = load i32, i32* %28
%57 = call i32 @ntohs(i32 %56)
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.11, i64 0, i64 0), i32 %55, i32 %57)
%59 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.12, i64 0, i64 0))
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.13, i64 0, i64 0), i8* %8)
%61 = call i64 @strlen(i8* %8)
%62 = add nsw i64 %61, 1
%63 = call i32 @write(i32 %54, i8* %8, i64 %62)
%64 = call i32 @memset(i8* %8, i32 0, i32 100)
%65 = call i32 @read(i32 %54, i8* %8, i32 100)
%66 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.12, i64 0, i64 0))
%67 = icmp eq i64 %66, 0
%68 = select i1 %67, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.14, i64 0, i64 0), i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.15, i64 0, i64 0)
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %68)
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.16, i64 0, i64 0))
%71 = call i32 @close(i32 %54)
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %52
73: ; preds = %52
%74 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.18, i64 0, i64 0))
br label %75
75: ; preds = %73, %50, %35, %22, %10
ret i32 0
}