#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_in {
  char *member_3;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ member_2;
  int /*<<< orphan*/ member_1;
  int /*<<< orphan*/ member_0;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_addr(char *);
char *inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ listen(int, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, ...);
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 strlen(char *);
int main(int argc, char *argv[]) {
  if (argc < 4) {
    printf("USAGE: %s %s %s %s\n", argv[0], "[bind IP]", "[Listen port]",
           "[CX response to send]");
    exit(0);
  }
  int fd, cx_fd;
  socklen_t s_size;
  int y = 1;
  struct sockaddr_in h_addr = {AF_INET, htons(atoi(argv[2])),
                               inet_addr(argv[1]), "00000000"},
                     c_addr;
  fd = socket(PF_INET, SOCK_STREAM, 0);
  setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &y, sizeof(int));
  bind(fd, (struct sockaddr *)&h_addr, sizeof(struct sockaddr));
  listen(fd, 5);
  while (1) {
    s_size = sizeof(struct sockaddr_in);
    cx_fd = accept(fd, (struct sockaddr *)&c_addr, &s_size);
    printf("Server: Inbound CX From: %s:%d\n", inet_ntoa(c_addr.sin_addr),
           ntohs(c_addr.sin_port));
    send(cx_fd, argv[3], strlen(argv[3]), 0);
    send(cx_fd, "\n", 1, 0);
    close(cx_fd);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    1244 <main+0x54>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xddf(%rip),%rdi
lea    0xdec(%rip),%rdx
lea    0xdef(%rip),%rcx
lea    0xdf6(%rip),%r8
mov    $0x0,%al
call   1080 <printf@plt>
xor    %edi,%edi
call   1100 <exit@plt>
movl   $0x1,-0x20(%rbp)
mov    0x2d8e(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x34(%rbp)
lea    0xdbb(%rip),%rax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x28(%rbp)
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
mov    0x2d28(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d2a(%rip),%rax
mov    (%rax),%esi
mov    0x2cf9(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x4,%edx
call   10d0 <bind@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
movl   $0x20,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x18(%rbp)
mov    -0x54(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,-0x78(%rbp)
mov    -0x58(%rbp),%edi
call   10c0 <ntohs@plt>
mov    -0x78(%rbp),%rsi
mov    %eax,%edx
lea    0xd1a(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1050 <strlen@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    -0x18(%rbp),%edi
lea    0xcf8(%rip),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
jmp    12f6 <main+0x106>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r12
cmp    $0x3,%edi
jle    133c <main+0x14c>
movl   $0x1,(%rsp)
mov    0x2dc8(%rip),%rax
movslq (%rax),%rax
mov    %rax,0x8(%rsp)
mov    0x10(%r12),%rdi
call   10f0 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x8(%r12),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x14(%rsp)
lea    0xdf8(%rip),%rax
mov    %eax,0x18(%rsp)
movq   $0x0,0x1c(%rsp)
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
mov    0x2d69(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,%ebp
mov    0x2d6f(%rip),%rax
mov    (%rax),%esi
mov    0x2d3e(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   10d0 <bind@plt>
mov    %ebp,%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
lea    0xdb1(%rip),%r13
nopl   0x0(%rax,%rax,1)
movl   $0x20,0x4(%rsp)
mov    %ebp,%edi
lea    0x28(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   10e0 <accept@plt>
mov    %eax,%r14d
mov    0x34(%rsp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%r15
mov    0x30(%rsp),%edi
call   10c0 <ntohs@plt>
lea    0xd53(%rip),%rdi
mov    %r15,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x18(%r12),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %r14d,%edi
mov    %r13,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %r14d,%edi
call   1090 <close@plt>
jmp    12c0 <main+0xd0>
mov    (%r12),%rsi
lea    0xcb9(%rip),%rdi
lea    0xcc6(%rip),%rdx
lea    0xcc9(%rip),%rcx
lea    0xcd0(%rip),%r8
xor    %eax,%eax
call   1080 <printf@plt>
xor    %edi,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i8*, i32, i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [20 x i8] c"USAGE: %s %s %s %s\0A\00"
@.str.1 = [10 x i8] c"[bind IP]\00"
@.str.2 = [14 x i8] c"[Listen port]\00"
@.str.3 = [22 x i8] c"[CX response to send]\00"
@AF_INET = global i32 0
@.str.4 = [9 x i8] c"00000000\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.5 = [32 x i8] c"Server: Inbound CX From: %s:%d\0A\00"
@.str.6 = [2 x i8] c"\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 %struct.sockaddr_in
%11 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 4
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %2
store i32 1, i32* %9
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%22 = load i32, i32* @AF_INET
%23 = sext i32 %22 to i64
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %21
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
%30 = call i32 @htons(i32 %29)
store i32 %30, i32* %25
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @inet_addr(i8* %34)
store i32 %35, i32* %31
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 3
store i32 ptrtoint ([9 x i8]* @.str.4 to i32), i32* %36
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 4
store i32 0, i32* %37
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 5
store i32 0, i32* %38
%39 = load i32, i32* @PF_INET
%40 = load i32, i32* @SOCK_STREAM
%41 = call i32 @socket(i32 %39, i32 %40, i32 0)
store i32 %41, i32* %6
%42 = load i32, i32* %6
%43 = load i32, i32* @SOL_SOCKET
%44 = load i32, i32* @SO_REUSEADDR
%45 = call i32 @setsockopt(i32 %42, i32 %43, i32 %44, i32* %9, i32 4)
%46 = load i32, i32* %6
%47 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%48 = call i32 @bind(i32 %46, %struct.sockaddr* %47, i32 4)
%49 = load i32, i32* %6
%50 = call i32 @listen(i32 %49, i32 5)
br label %51
51: ; preds = %20, %51
store i32 32, i32* %8
%52 = load i32, i32* %6
%53 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%54 = call i32 @accept(i32 %52, %struct.sockaddr* %53, i32* %8)
store i32 %54, i32* %7
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
%56 = load i32, i32* %55
%57 = call i8* @inet_ntoa(i32 %56)
%58 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%59 = load i32, i32* %58
%60 = call i32 @ntohs(i32 %59)
%61 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %57, i32 %60)
%62 = load i32, i32* %7
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 3
%65 = load i8*, i8** %64
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 3
%68 = load i8*, i8** %67
%69 = call i32 @strlen(i8* %68)
%70 = call i32 @send(i32 %62, i8* %65, i32 %69, i32 0)
%71 = load i32, i32* %7
%72 = call i32 @send(i32 %71, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 1, i32 0)
%73 = load i32, i32* %7
%74 = call i32 @close(i32 %73)
br label %51
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8*, i32, i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [20 x i8] c"USAGE: %s %s %s %s\0A\00"
@.str.1 = [10 x i8] c"[bind IP]\00"
@.str.2 = [14 x i8] c"[Listen port]\00"
@.str.3 = [22 x i8] c"[CX response to send]\00"
@AF_INET = global i32 0
@.str.4 = [9 x i8] c"00000000\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.5 = [32 x i8] c"Server: Inbound CX From: %s:%d\0A\00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = icmp slt i32 %0, 4
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%11 = tail call i32 @exit(i32 0)
unreachable
12: ; preds = %2
%13 = bitcast i32* %3 to i8*
%14 = bitcast i32* %4 to i8*
store i32 1, i32* %4
%15 = bitcast %struct.sockaddr_in* %5 to i8*
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
%17 = load i32, i32* @AF_INET
%18 = sext i32 %17 to i64
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %16
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = tail call i32 @atoi(i8* %22)
%24 = tail call i32 @htons(i32 %23)
store i32 %24, i32* %20
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = tail call i32 @inet_addr(i8* %27)
store i32 %28, i32* %25
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 3
store i32 ptrtoint ([9 x i8]* @.str.4 to i32), i32* %29
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 4
store i32 0, i32* %30
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 5
store i32 0, i32* %31
%32 = bitcast %struct.sockaddr_in* %6 to i8*
%33 = load i32, i32* @PF_INET
%34 = load i32, i32* @SOCK_STREAM
%35 = tail call i32 @socket(i32 %33, i32 %34, i32 0)
%36 = load i32, i32* @SOL_SOCKET
%37 = load i32, i32* @SO_REUSEADDR
%38 = call i32 @setsockopt(i32 %35, i32 %36, i32 %37, i32* %4, i32 4)
%39 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%40 = call i32 @bind(i32 %35, %struct.sockaddr* %39, i32 4)
%41 = call i32 @listen(i32 %35, i32 5)
%42 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 2
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1
%45 = getelementptr inbounds i8*, i8** %1, i64 3
br label %46
46: ; preds = %46, %12
store i32 32, i32* %3
%47 = call i32 @accept(i32 %35, %struct.sockaddr* %42, i32* %3)
%48 = load i32, i32* %43
%49 = call i8* @inet_ntoa(i32 %48)
%50 = load i32, i32* %44
%51 = call i32 @ntohs(i32 %50)
%52 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %49, i32 %51)
%53 = load i8*, i8** %45
%54 = call i32 @strlen(i8* %53)
%55 = call i32 @send(i32 %47, i8* %53, i32 %54, i32 0)
%56 = call i32 @send(i32 %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 1, i32 0)
%57 = call i32 @close(i32 %47)
br label %46
}