#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 dummy;
};
struct sockaddr {
  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 /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                               struct addrinfo **);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("Usage: %s message\n", argv[0]);
    return 1;
  }
  struct sockaddr_storage their_addr;
  socklen_t addr_size;
  struct addrinfo hints, *res;
  int sockfd, new_fd;
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = AI_PASSIVE;
  getaddrinfo(NULL, "17", &hints, &res);
  sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
  if (bind(sockfd, res->ai_addr, res->ai_addrlen) != 0) {
    perror("Bind failed");
    exit(1);
  }
  if (listen(sockfd, 10) != 0) {
    perror("Listen failed");
    exit(1);
  }
  addr_size = sizeof their_addr;
  while ((new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &addr_size)) >
         -1) {
    send(new_fd, argv[1], strlen(argv[1]), 0);
    send(new_fd, "\n", strlen("\n"), 0);
    close(new_fd);
  }
}


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   $0x2,-0x8(%rbp)
je     11ff <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe12(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    134e <main+0x18e>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2dba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdd5(%rip),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   10d0 <getaddrinfo@plt>
mov    -0x40(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x40(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%edx
call   10e0 <socket@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x40(%rbp),%rax
mov    (%rax),%edx
call   1090 <bind@plt>
cmp    $0x0,%rax
je     129d <main+0xdd>
lea    0xd88(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x44(%rbp),%edi
mov    $0xa,%esi
call   1080 <listen@plt>
cmp    $0x0,%rax
je     12ca <main+0x10a>
lea    0xd67(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
movl   $0x4,-0x1c(%rbp)
mov    -0x44(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   10b0 <accept@plt>
mov    %eax,-0x48(%rbp)
cmp    $0xffffffff,%eax
jle    134e <main+0x18e>
mov    -0x48(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    -0x48(%rbp),%eax
mov    %eax,-0x4c(%rbp)
lea    0xce8(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    %eax,%edx
lea    0xcd7(%rip),%rsi
xor    %ecx,%ecx
call   1040 <send@plt>
mov    -0x48(%rbp),%edi
call   1070 <close@plt>
jmp    12d1 <main+0x111>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    12f1 <main+0x131>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
mov    0x2dce(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x2c(%rsp)
mov    0x2dd9(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x34(%rsp)
lea    0xdf7(%rip),%rsi
lea    0x18(%rsp),%rcx
xor    %edi,%edi
mov    %rbp,%rdx
call   10d0 <getaddrinfo@plt>
mov    0x18(%rsp),%rax
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   10e0 <socket@plt>
mov    %eax,%r13d
mov    0x18(%rsp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %r13d,%edi
call   1090 <bind@plt>
test   %rax,%rax
jne    1314 <main+0x154>
mov    %r13d,%edi
mov    $0xa,%esi
call   1080 <listen@plt>
test   %rax,%rax
jne    131d <main+0x15d>
movl   $0x4,0xc(%rsp)
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r13d,%edi
call   10b0 <accept@plt>
test   %eax,%eax
js     12ed <main+0x12d>
mov    %eax,%ebp
lea    0xd78(%rip),%r15
lea    0xc(%rsp),%r12
xchg   %ax,%ax
mov    0x8(%rbx),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    %r13d,%edi
lea    0x10(%rsp),%rsi
mov    %r12,%rdx
call   10b0 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    12a0 <main+0xe0>
xor    %eax,%eax
jmp    1305 <main+0x145>
mov    (%rbx),%rsi
lea    0xd05(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcfb(%rip),%rdi
jmp    1324 <main+0x164>
lea    0xcfe(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.addrinfo = type { i32, i32, i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [19 x i8] c"Usage: %s message\0A\00"
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str.1 = [3 x i8] c"17\00"
@.str.2 = [12 x i8] c"Bind failed\00"
@.str.3 = [14 x i8] c"Listen failed\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_storage
%7 = alloca i32
%8 = alloca %struct.addrinfo
%9 = alloca %struct.addrinfo*
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 1, i32* %3
br label %78
19: ; preds = %2
%20 = call i32 @memset(%struct.addrinfo* %8, i32 0, i32 24)
%21 = load i32, i32* @AF_UNSPEC
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 4
store i32 %21, i32* %22
%23 = load i32, i32* @SOCK_STREAM
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 3
store i32 %23, i32* %24
%25 = load i32, i32* @AI_PASSIVE
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 5
store i32 %25, i32* %26
%27 = call i32 @getaddrinfo(i32* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %8, %struct.addrinfo** %9)
%28 = load %struct.addrinfo*, %struct.addrinfo** %9
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %28, i32 0, i32 4
%30 = load i32, i32* %29
%31 = load %struct.addrinfo*, %struct.addrinfo** %9
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i32 0, i32 3
%33 = load i32, i32* %32
%34 = load %struct.addrinfo*, %struct.addrinfo** %9
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i32 0, i32 2
%36 = load i32, i32* %35
%37 = call i32 @socket(i32 %30, i32 %33, i32 %36)
store i32 %37, i32* %10
%38 = load i32, i32* %10
%39 = load %struct.addrinfo*, %struct.addrinfo** %9
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %39, i32 0, i32 1
%41 = load i32, i32* %40
%42 = load %struct.addrinfo*, %struct.addrinfo** %9
%43 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %42, i32 0, i32 0
%44 = load i32, i32* %43
%45 = call i64 @bind(i32 %38, i32 %41, i32 %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %19
%48 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %19
%51 = load i32, i32* %10
%52 = call i64 @listen(i32 %51, i32 10)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %50
%55 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %50
store i32 4, i32* %7
br label %58
58: ; preds = %63, %57
%59 = load i32, i32* %10
%60 = bitcast %struct.sockaddr_storage* %6 to %struct.sockaddr*
%61 = call i32 @accept(i32 %59, %struct.sockaddr* %60, i32* %7)
store i32 %61, i32* %11
%62 = icmp sgt i32 %61, -1
br i1 %62, label %63, label %78
63: ; preds = %58
%64 = load i32, i32* %11
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 1
%67 = load i8*, i8** %66
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 1
%70 = load i8*, i8** %69
%71 = call i32 @strlen(i8* %70)
%72 = call i32 @send(i32 %64, i8* %67, i32 %71, i32 0)
%73 = load i32, i32* %11
%74 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%75 = call i32 @send(i32 %73, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 %74, i32 0)
%76 = load i32, i32* %11
%77 = call i32 @close(i32 %76)
br label %58
78: ; preds = %14, %58
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
%struct.addrinfo = type { i32, i32, i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [19 x i8] c"Usage: %s message\0A\00"
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str.1 = [3 x i8] c"17\00"
@.str.2 = [12 x i8] c"Bind failed\00"
@.str.3 = [14 x i8] c"Listen failed\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_storage
%4 = alloca i32
%5 = alloca %struct.addrinfo
%6 = alloca %struct.addrinfo*
%7 = icmp eq i32 %0, 2
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %65
11: ; preds = %2
%12 = bitcast %struct.sockaddr_storage* %3 to i8*
%13 = bitcast i32* %4 to i8*
%14 = bitcast %struct.addrinfo* %5 to i8*
%15 = bitcast %struct.addrinfo** %6 to i8*
%16 = call i32 @memset(%struct.addrinfo* %5, i32 0, i32 24)
%17 = load i32, i32* @AF_UNSPEC
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 4
store i32 %17, i32* %18
%19 = load i32, i32* @SOCK_STREAM
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 3
store i32 %19, i32* %20
%21 = load i32, i32* @AI_PASSIVE
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 5
store i32 %21, i32* %22
%23 = call i32 @getaddrinfo(i32* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %5, %struct.addrinfo** %6)
%24 = load %struct.addrinfo*, %struct.addrinfo** %6
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %24, i64 0, i32 4
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %24, i64 0, i32 3
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %24, i64 0, i32 2
%30 = load i32, i32* %29
%31 = call i32 @socket(i32 %26, i32 %28, i32 %30)
%32 = load %struct.addrinfo*, %struct.addrinfo** %6
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %32, i64 0, i32 1
%34 = load i32, i32* %33
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %32, i64 0, i32 0
%36 = load i32, i32* %35
%37 = call i64 @bind(i32 %31, i32 %34, i32 %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %11
%40 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %11
%43 = call i64 @listen(i32 %31, i32 10)
%44 = icmp eq i64 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %42
%46 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %42
store i32 4, i32* %4
%49 = bitcast %struct.sockaddr_storage* %3 to %struct.sockaddr*
%50 = call i32 @accept(i32 %31, %struct.sockaddr* %49, i32* %4)
%51 = icmp sgt i32 %50, -1
br i1 %51, label %52, label %64
52: ; preds = %48
%53 = getelementptr inbounds i8*, i8** %1, i64 1
br label %54
54: ; preds = %52, %54
%55 = phi i32 [ %50, %52 ], [ %62, %54 ]
%56 = load i8*, i8** %53
%57 = call i32 @strlen(i8* %56)
%58 = call i32 @send(i32 %55, i8* %56, i32 %57, i32 0)
%59 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%60 = call i32 @send(i32 %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 %59, i32 0)
%61 = call i32 @close(i32 %55)
%62 = call i32 @accept(i32 %31, %struct.sockaddr* %49, i32* %4)
%63 = icmp sgt i32 %62, -1
br i1 %63, label %54, label %64
64: ; preds = %54, %48
br label %65
65: ; preds = %64, %8
%66 = phi i32 [ 1, %8 ], [ 0, %64 ]
ret i32 %66
}