#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 */

/* Type definitions */
struct sockaddr_storage {
  int /*<<< orphan*/ ss_family;
};
struct sockaddr {
  int dummy;
};
struct sigaction {
  int dummy;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  int /*<<< orphan*/ ai_flags;
};
typedef int socklen_t;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int /*<<< orphan*/ get_in_addr(struct sockaddr *);
int /*<<< orphan*/ getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                               struct addrinfo **);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                             int);
int /*<<< orphan*/ listen(int, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main(void) {
  int sockfd, new_fd;
  struct addrinfo hints, *servinfo, *p;
  struct sockaddr_storage their_addr;
  socklen_t sin_size;
  struct sigaction sa;
  int yes = 1;
  char s[INET6_ADDRSTRLEN];
  int rv;
  char buf[100];
  int numbytes;
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = AI_PASSIVE;
  getaddrinfo(NULL, "3491", &hints, &servinfo);
  sockfd =
      socket(servinfo->ai_family, servinfo->ai_socktype, servinfo->ai_protocol);
  setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
  bind(sockfd, servinfo->ai_addr, servinfo->ai_addrlen);
  freeaddrinfo(servinfo);
  listen(sockfd, 10);
  printf("server: waiting for connections...\n");
  while (1) {
    sin_size = sizeof their_addr;
    new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size);
    inet_ntop(their_addr.ss_family, get_in_addr((struct sockaddr *)&their_addr),
              s, sizeof s);
    printf("server: got connection from %s\n", s);
    char name[100];
    char *msg = (char *)malloc(1001);
    if (!fork()) {
      close(sockfd);
      send(new_fd, "hello, world!", 13, 0);
      numbytes = recv(new_fd, buf, 100 - 1, 0);
      buf[numbytes] = '\0';
      printf("client %s registered\n", buf);
      strcpy(name, buf);
      for (;;) {
        printf("waiting for reply...\n");
        numbytes = recv(new_fd, buf, 100 - 1, 0);
        buf[numbytes] = '\0';
        printf("%s: %s\n", name, buf);
        printf("> ");
        fgets(msg, 1001, stdin);
        if ((strlen(msg) > 0) && (msg[strlen(msg) - 1] == '\n'))
          msg[strlen(msg) - 1] = '\0';
        send(new_fd, msg, strlen(msg), 0);
      }
      close(new_fd);
      exit(0);
    }
    close(new_fd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    0x2d90(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x158(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x150(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x60(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   10b0 <memset@plt>
mov    0x2d3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2d2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd42(%rip),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1120 <getaddrinfo@plt>
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x30(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%edx
call   1150 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2cf6(%rip),%rax
mov    (%rax),%esi
mov    0x2cb5(%rip),%rax
mov    (%rax),%edx
lea    -0x4c(%rbp),%rcx
mov    $0x4,%r8d
call   1070 <setsockopt@plt>
mov    -0x8(%rbp),%edi
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
call   1100 <bind@plt>
mov    -0x30(%rbp),%rdi
call   1140 <freeaddrinfo@plt>
mov    -0x8(%rbp),%edi
mov    $0xa,%esi
call   10f0 <listen@plt>
lea    0xcc7(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    134a <main+0x11a>
movl   $0x4,-0x44(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x44(%rbp),%rdx
call   1110 <accept@plt>
mov    %eax,-0xc(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x15c(%rbp)
lea    -0x40(%rbp),%rdi
call   1050 <get_in_addr@plt>
mov    -0x15c(%rbp),%edi
mov    -0x150(%rbp),%rdx
mov    %eax,%esi
mov    -0x158(%rbp),%rax
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x150(%rbp),%rsi
lea    0xc88(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    $0x3e9,%edi
call   10e0 <malloc@plt>
mov    %rax,-0x148(%rbp)
mov    $0x0,%al
call   1130 <fork@plt>
cmp    $0x0,%eax
jne    156d <main+0x33d>
mov    -0x8(%rbp),%edi
call   10c0 <close@plt>
mov    -0xc(%rbp),%edi
lea    0xc6e(%rip),%rsi
mov    $0xd,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
mov    -0xc(%rbp),%edi
lea    -0xd0(%rbp),%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0xd4(%rbp)
movslq -0xd4(%rbp),%rax
movb   $0x0,-0xd0(%rbp,%rax,1)
lea    -0xd0(%rbp),%rsi
lea    0xc37(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
lea    -0x140(%rbp),%rdi
lea    -0xd0(%rbp),%rsi
call   1060 <strcpy@plt>
lea    0xc2c(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0xd0(%rbp),%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0xd4(%rbp)
movslq -0xd4(%rbp),%rax
movb   $0x0,-0xd0(%rbp,%rax,1)
lea    -0x140(%rbp),%rsi
lea    -0xd0(%rbp),%rdx
lea    0xbfb(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
lea    0xbf5(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x148(%rbp),%rdi
mov    0x2b1d(%rip),%rax
mov    (%rax),%edx
mov    $0x3e9,%esi
call   10d0 <fgets@plt>
mov    -0x148(%rbp),%rdi
call   1080 <strlen@plt>
cmp    $0x0,%eax
jle    152f <main+0x2ff>
mov    -0x148(%rbp),%rax
mov    %rax,-0x168(%rbp)
mov    -0x148(%rbp),%rdi
call   1080 <strlen@plt>
mov    %eax,%ecx
mov    -0x168(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    152f <main+0x2ff>
mov    -0x148(%rbp),%rax
mov    %rax,-0x170(%rbp)
mov    -0x148(%rbp),%rdi
call   1080 <strlen@plt>
mov    %eax,%ecx
mov    -0x170(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
mov    %eax,-0x17c(%rbp)
mov    -0x148(%rbp),%rax
mov    %rax,-0x178(%rbp)
mov    -0x148(%rbp),%rdi
call   1080 <strlen@plt>
mov    -0x17c(%rbp),%edi
mov    -0x178(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
jmp    143a <main+0x20a>
mov    -0xc(%rbp),%edi
call   10c0 <close@plt>
jmp    1345 <main+0x115>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
movl   $0x1,-0x3c(%rbp)
mov    0x2d7e(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r15
mov    %rax,-0x48(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
lea    -0x60(%rbp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   10c0 <memset@plt>
mov    0x2d3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    0x2d19(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    0x2d2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
lea    0xd49(%rip),%rsi
lea    -0x38(%rbp),%rcx
xor    %edi,%edi
mov    %rbx,%rdx
call   1130 <getaddrinfo@plt>
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   1160 <socket@plt>
mov    %eax,%r13d
mov    0x2d07(%rip),%rax
mov    (%rax),%esi
mov    0x2cc6(%rip),%rax
mov    (%rax),%edx
lea    -0x3c(%rbp),%rcx
mov    %r13d,%edi
mov    $0x4,%r8d
call   1080 <setsockopt@plt>
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %r13d,%edi
call   1110 <bind@plt>
mov    -0x38(%rbp),%rdi
call   1150 <freeaddrinfo@plt>
mov    %r13d,%edi
mov    $0xa,%esi
call   1100 <listen@plt>
lea    0xd28(%rip),%rdi
call   1070 <puts@plt>
lea    -0x30(%rbp),%r14
cs nopw 0x0(%rax,%rax,1)
nop
movl   $0x4,-0x40(%rbp)
mov    %r13d,%edi
mov    %r14,%rsi
lea    -0x40(%rbp),%rdx
call   1120 <accept@plt>
mov    %eax,%r12d
mov    -0x30(%rbp),%ebx
mov    %r14,%rdi
call   1050 <get_in_addr@plt>
mov    %ebx,%edi
mov    %eax,%esi
mov    %r15,%rdx
mov    -0x48(%rbp),%rcx
call   1030 <inet_ntop@plt>
lea    0xc8a(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   10b0 <printf@plt>
mov    $0x3e9,%edi
call   10f0 <malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1140 <fork@plt>
test   %eax,%eax
je     13a7 <main+0x167>
mov    %r12d,%edi
call   10d0 <close@plt>
jmp    1340 <main+0x100>
mov    %r13d,%edi
call   10d0 <close@plt>
lea    0xc6f(%rip),%rsi
mov    %r12d,%edi
mov    $0xd,%edx
xor    %ecx,%ecx
call   10a0 <send@plt>
lea    -0xd0(%rbp),%r14
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
cltq
movb   $0x0,-0xd0(%rbp,%rax,1)
lea    0xc44(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   10b0 <printf@plt>
lea    -0x140(%rbp),%rdi
mov    %r14,%rsi
call   1060 <strcpy@plt>
lea    0xc42(%rip),%r13
mov    0x2bb2(%rip),%r15
jmp    1437 <main+0x1f7>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1090 <strlen@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   10a0 <send@plt>
lea    0xc39(%rip),%rdi
call   1070 <puts@plt>
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
cltq
movb   $0x0,-0xd0(%rbp,%rax,1)
lea    0xbe3(%rip),%rdi
lea    -0x140(%rbp),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   10b0 <printf@plt>
mov    %r13,%rdi
xor    %eax,%eax
call   10b0 <printf@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x3e9,%esi
call   10e0 <fgets@plt>
mov    %rbx,%rdi
call   1090 <strlen@plt>
test   %eax,%eax
jle    1420 <main+0x1e0>
mov    %rbx,%rdi
call   1090 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    1420 <main+0x1e0>
mov    %rbx,%rdi
call   1090 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
jmp    1420 <main+0x1e0>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sigaction = type { i32 }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str = [5 x i8] c"3491\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [36 x i8] c"server: waiting for connections...\0A\00"
@.str.2 = [32 x i8] c"server: got connection from %s\0A\00"
@.str.3 = [14 x i8] c"hello, world!\00"
@.str.4 = [22 x i8] c"client %s registered\0A\00"
@.str.5 = [22 x i8] c"waiting for reply...\0A\00"
@.str.6 = [8 x i8] c"%s: %s\0A\00"
@.str.7 = [3 x i8] c"> \00"
@stdin = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.addrinfo
%5 = alloca %struct.addrinfo*
%6 = alloca %struct.addrinfo*
%7 = alloca %struct.sockaddr_storage
%8 = alloca i32
%9 = alloca %struct.sigaction
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
%14 = alloca [100 x i8]
%15 = alloca i32
%16 = alloca [100 x i8]
%17 = alloca i8*
store i32 0, i32* %1
store i32 1, i32* %10
%18 = load i32, i32* @INET6_ADDRSTRLEN
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %11
%21 = alloca i8, i64 %19
store i64 %19, i64* %12
%22 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 24)
%23 = load i32, i32* @AF_UNSPEC
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 4
store i32 %23, i32* %24
%25 = load i32, i32* @SOCK_STREAM
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 3
store i32 %25, i32* %26
%27 = load i32, i32* @AI_PASSIVE
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i32 0, i32 5
store i32 %27, i32* %28
%29 = call i32 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %4, %struct.addrinfo** %5)
%30 = load %struct.addrinfo*, %struct.addrinfo** %5
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %30, i32 0, i32 4
%32 = load i32, i32* %31
%33 = load %struct.addrinfo*, %struct.addrinfo** %5
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %33, i32 0, i32 3
%35 = load i32, i32* %34
%36 = load %struct.addrinfo*, %struct.addrinfo** %5
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i32 0, i32 2
%38 = load i32, i32* %37
%39 = call i32 @socket(i32 %32, i32 %35, i32 %38)
store i32 %39, i32* %2
%40 = load i32, i32* %2
%41 = load i32, i32* @SOL_SOCKET
%42 = load i32, i32* @SO_REUSEADDR
%43 = call i32 @setsockopt(i32 %40, i32 %41, i32 %42, i32* %10, i32 4)
%44 = load i32, i32* %2
%45 = load %struct.addrinfo*, %struct.addrinfo** %5
%46 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %45, i32 0, i32 1
%47 = load i32, i32* %46
%48 = load %struct.addrinfo*, %struct.addrinfo** %5
%49 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %48, i32 0, i32 0
%50 = load i32, i32* %49
%51 = call i32 @bind(i32 %44, i32 %47, i32 %50)
%52 = load %struct.addrinfo*, %struct.addrinfo** %5
%53 = call i32 @freeaddrinfo(%struct.addrinfo* %52)
%54 = load i32, i32* %2
%55 = call i32 @listen(i32 %54, i32 10)
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %57
57: ; preds = %130, %0
br label %58
58: ; preds = %57
store i32 4, i32* %8
%59 = load i32, i32* %2
%60 = bitcast %struct.sockaddr_storage* %7 to %struct.sockaddr*
%61 = call i32 @accept(i32 %59, %struct.sockaddr* %60, i32* %8)
store i32 %61, i32* %3
%62 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %7, i32 0, i32 0
%63 = load i32, i32* %62
%64 = bitcast %struct.sockaddr_storage* %7 to %struct.sockaddr*
%65 = call i32 @get_in_addr(%struct.sockaddr* %64)
%66 = trunc i64 %19 to i32
%67 = call i32 @inet_ntop(i32 %63, i32 %65, i8* %21, i32 %66)
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%69 = call i64 @malloc(i32 1001)
%70 = inttoptr i64 %69 to i8*
store i8* %70, i8** %17
%71 = call i32 (...) @fork()
%72 = icmp ne i32 %71, 0
br i1 %72, label %130, label %73
73: ; preds = %58
%74 = load i32, i32* %2
%75 = call i32 @close(i32 %74)
%76 = load i32, i32* %3
%77 = call i32 @send(i32 %76, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 13, i32 0)
%78 = load i32, i32* %3
%79 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%80 = call i32 @recv(i32 %78, i8* %79, i32 99, i32 0)
store i32 %80, i32* %15
%81 = load i32, i32* %15
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 %82
store i8 0, i8* %83
%84 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %84)
%86 = getelementptr inbounds [100 x i8], [100 x i8]* %16, i64 0, i64 0
%87 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%88 = call i32 @strcpy(i8* %86, i8* %87)
br label %89
89: ; preds = %124, %73
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%91 = load i32, i32* %3
%92 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%93 = call i32 @recv(i32 %91, i8* %92, i32 99, i32 0)
store i32 %93, i32* %15
%94 = load i32, i32* %15
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 %95
store i8 0, i8* %96
%97 = getelementptr inbounds [100 x i8], [100 x i8]* %16, i64 0, i64 0
%98 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* %97, i8* %98)
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%101 = load i8*, i8** %17
%102 = load i32, i32* @stdin
%103 = call i32 @fgets(i8* %101, i32 1001, i32 %102)
%104 = load i8*, i8** %17
%105 = call i32 @strlen(i8* %104)
%106 = icmp sgt i32 %105, 0
br i1 %106, label %107, label %124
107: ; preds = %89
%108 = load i8*, i8** %17
%109 = load i8*, i8** %17
%110 = call i32 @strlen(i8* %109)
%111 = sub nsw i32 %110, 1
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds i8, i8* %108, i64 %112
%114 = load i8, i8* %113
%115 = sext i8 %114 to i32
%116 = icmp eq i32 %115, 10
br i1 %116, label %117, label %124
117: ; preds = %107
%118 = load i8*, i8** %17
%119 = load i8*, i8** %17
%120 = call i32 @strlen(i8* %119)
%121 = sub nsw i32 %120, 1
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds i8, i8* %118, i64 %122
store i8 0, i8* %123
br label %124
124: ; preds = %117, %107, %89
%125 = load i32, i32* %3
%126 = load i8*, i8** %17
%127 = load i8*, i8** %17
%128 = call i32 @strlen(i8* %127)
%129 = call i32 @send(i32 %125, i8* %126, i32 %128, i32 0)
br label %89
130: ; preds = %58
%131 = load i32, i32* %3
%132 = call i32 @close(i32 %131)
br label %57
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str = [5 x i8] c"3491\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [32 x i8] c"server: got connection from %s\0A\00"
@.str.3 = [14 x i8] c"hello, world!\00"
@.str.4 = [22 x i8] c"client %s registered\0A\00"
@.str.6 = [8 x i8] c"%s: %s\0A\00"
@.str.7 = [3 x i8] c"> \00"
@stdin = global i32 0
@str = [35 x i8] c"server: waiting for connections...\00"
@str.8 = [21 x i8] c"waiting for reply...\00"
define i32 @main() {
%1 = alloca %struct.addrinfo
%2 = alloca %struct.addrinfo*
%3 = alloca %struct.sockaddr_storage
%4 = alloca i32
%5 = alloca i32
%6 = alloca [100 x i8]
%7 = alloca [100 x i8]
%8 = bitcast %struct.addrinfo* %1 to i8*
%9 = bitcast %struct.addrinfo** %2 to i8*
%10 = bitcast %struct.sockaddr_storage* %3 to i8*
%11 = bitcast i32* %4 to i8*
%12 = bitcast i32* %5 to i8*
store i32 1, i32* %5
%13 = load i32, i32* @INET6_ADDRSTRLEN
%14 = zext i32 %13 to i64
%15 = alloca i8, i64 %14
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%17 = call i32 @memset(%struct.addrinfo* %1, i32 0, i32 24)
%18 = load i32, i32* @AF_UNSPEC
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 4
store i32 %18, i32* %19
%20 = load i32, i32* @SOCK_STREAM
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 3
store i32 %20, i32* %21
%22 = load i32, i32* @AI_PASSIVE
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 5
store i32 %22, i32* %23
%24 = call i32 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %1, %struct.addrinfo** %2)
%25 = load %struct.addrinfo*, %struct.addrinfo** %2
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %25, i64 0, i32 4
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %25, i64 0, i32 3
%29 = load i32, i32* %28
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %25, i64 0, i32 2
%31 = load i32, i32* %30
%32 = call i32 @socket(i32 %27, i32 %29, i32 %31)
%33 = load i32, i32* @SOL_SOCKET
%34 = load i32, i32* @SO_REUSEADDR
%35 = call i32 @setsockopt(i32 %32, i32 %33, i32 %34, i32* %5, i32 4)
%36 = load %struct.addrinfo*, %struct.addrinfo** %2
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i64 0, i32 1
%38 = load i32, i32* %37
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i64 0, i32 0
%40 = load i32, i32* %39
%41 = call i32 @bind(i32 %32, i32 %38, i32 %40)
%42 = load %struct.addrinfo*, %struct.addrinfo** %2
%43 = call i32 @freeaddrinfo(%struct.addrinfo* %42)
%44 = call i32 @listen(i32 %32, i32 10)
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%46 = bitcast %struct.sockaddr_storage* %3 to %struct.sockaddr*
%47 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %3, i64 0, i32 0
%48 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
br label %49
49: ; preds = %93, %0
store i32 4, i32* %4
%50 = call i32 @accept(i32 %32, %struct.sockaddr* %46, i32* %4)
%51 = load i32, i32* %47
%52 = call i32 @get_in_addr(%struct.sockaddr* %46)
%53 = call i32 @inet_ntop(i32 %51, i32 %52, i8* %15, i32 %13)
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%55 = call i64 @malloc(i32 1001)
%56 = call i32 (...) @fork()
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %93
58: ; preds = %49
%59 = inttoptr i64 %55 to i8*
%60 = call i32 @close(i32 %32)
%61 = call i32 @send(i32 %50, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 13, i32 0)
%62 = call i32 @recv(i32 %50, i8* %16, i32 99, i32 0)
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %63
store i8 0, i8* %64
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %16)
%66 = call i32 @strcpy(i8* %48, i8* %16)
br label %67
67: ; preds = %90, %58
%68 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.8, i64 0, i64 0))
%69 = call i32 @recv(i32 %50, i8* %16, i32 99, i32 0)
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %70
store i8 0, i8* %71
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* %48, i8* %16)
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%74 = load i32, i32* @stdin
%75 = call i32 @fgets(i8* %59, i32 1001, i32 %74)
%76 = call i32 @strlen(i8* %59)
%77 = icmp sgt i32 %76, 0
br i1 %77, label %78, label %90
78: ; preds = %67
%79 = call i32 @strlen(i8* %59)
%80 = add nsw i32 %79, -1
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i8, i8* %59, i64 %81
%83 = load i8, i8* %82
%84 = icmp eq i8 %83, 10
br i1 %84, label %85, label %90
85: ; preds = %78
%86 = call i32 @strlen(i8* %59)
%87 = add nsw i32 %86, -1
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i8, i8* %59, i64 %88
store i8 0, i8* %89
br label %90
90: ; preds = %85, %78, %67
%91 = call i32 @strlen(i8* %59)
%92 = call i32 @send(i32 %50, i8* %59, i32 %91, i32 0)
br label %67
93: ; preds = %49
%94 = call i32 @close(i32 %50)
br label %49
}