#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;
};
typedef scalar_t__ ssize_t;
typedef int socklen_t;
typedef int /*<<< orphan*/ servAddr;
typedef int /*<<< orphan*/ clntAddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ dieWithMessage(char *);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
scalar_t__ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char buffer[1024];
  int *sendFds = NULL;
  sendFds = (int *)malloc(sizeof(int) * 2);
  int servSock;
  if ((servSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
    dieWithMessage("socket() failed\n");
  struct sockaddr_in servAddr;
  memset(&servAddr, 0, sizeof(servAddr));
  servAddr.sin_family = AF_INET;
  servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
  servAddr.sin_port = htons(12345);
  if (bind(servSock, (struct sockaddr *)&servAddr, sizeof(servAddr)) < 0)
    dieWithMessage("bind() failed");
  if (listen(servSock, 2) < 0)
    dieWithMessage("listen() failed");
  for (int i = 0; i < 2; i++) {
    struct sockaddr_in clntAddr;
    socklen_t clntAddrLen = sizeof(clntAddr);
    sendFds[i] = accept(servSock, (struct sockaddr *)&clntAddr, &clntAddrLen);
    if (sendFds[i] < 0)
      dieWithMessage("accept() failed");
  }
  for (int i = 0; i < 2; i++) {
    ssize_t numBytesSent = send(sendFds[i], "Hello", 6, 0);
    if (numBytesSent < 0)
      dieWithMessage("send() failed");
  }
  free(sendFds);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x418(%rbp)
mov    $0x8,%edi
call   1090 <malloc@plt>
mov    %rax,-0x418(%rbp)
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
mov    0x2dd3(%rip),%rax
mov    (%rax),%esi
mov    0x2dda(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
mov    %eax,-0x41c(%rbp)
cmp    $0x0,%eax
jge    1220 <main+0x70>
lea    0xde5(%rip),%rdi
call   1060 <dieWithMessage@plt>
lea    -0x428(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x420(%rbp)
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,-0x424(%rbp)
mov    $0x3039,%edi
call   1040 <htons@plt>
mov    %eax,-0x428(%rbp)
mov    -0x41c(%rbp),%edi
lea    -0x428(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
cmp    $0x0,%rax
jge    1293 <main+0xe3>
lea    0xd83(%rip),%rdi
call   1060 <dieWithMessage@plt>
mov    -0x41c(%rbp),%edi
mov    $0x2,%esi
call   10a0 <listen@plt>
cmp    $0x0,%rax
jge    12b9 <main+0x109>
lea    0xd6b(%rip),%rdi
call   1060 <dieWithMessage@plt>
movl   $0x0,-0x42c(%rbp)
cmpl   $0x2,-0x42c(%rbp)
jge    1343 <main+0x193>
movl   $0xc,-0x43c(%rbp)
mov    -0x41c(%rbp),%edi
lea    -0x438(%rbp),%rsi
lea    -0x43c(%rbp),%rdx
call   10c0 <accept@plt>
mov    %eax,%edx
mov    -0x418(%rbp),%rax
movslq -0x42c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x418(%rbp),%rax
movslq -0x42c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jge    132a <main+0x17a>
lea    0xd0a(%rip),%rdi
call   1060 <dieWithMessage@plt>
jmp    132f <main+0x17f>
mov    -0x42c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x42c(%rbp)
jmp    12c3 <main+0x113>
movl   $0x0,-0x440(%rbp)
cmpl   $0x2,-0x440(%rbp)
jge    13b8 <main+0x208>
mov    -0x418(%rbp),%rax
movslq -0x440(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
lea    0xccd(%rip),%rsi
mov    $0x6,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %rax,-0x448(%rbp)
cmpq   $0x0,-0x448(%rbp)
jge    139f <main+0x1ef>
lea    0xcab(%rip),%rdi
call   1060 <dieWithMessage@plt>
jmp    13a4 <main+0x1f4>
mov    -0x440(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x440(%rbp)
jmp    134d <main+0x19d>
mov    -0x418(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    $0x8,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    0x2e1a(%rip),%r15
mov    (%r15),%edi
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
mov    0x2df7(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11fa <main+0x4a>
lea    0xe0b(%rip),%rdi
call   1060 <dieWithMessage@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,0xc(%rsp)
mov    $0x3039,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
test   %rax,%rax
jns    1255 <main+0xa5>
lea    0xdc1(%rip),%rdi
call   1060 <dieWithMessage@plt>
mov    %ebp,%edi
mov    $0x2,%esi
call   10a0 <listen@plt>
test   %rax,%rax
jns    1272 <main+0xc2>
lea    0xdb2(%rip),%rdi
call   1060 <dieWithMessage@plt>
movl   $0xc,0x4(%rsp)
lea    0x18(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %ebp,%edi
call   10c0 <accept@plt>
mov    %eax,(%rbx)
test   %eax,%eax
jns    129d <main+0xed>
lea    0xd97(%rip),%rdi
call   1060 <dieWithMessage@plt>
movl   $0xc,0x4(%rsp)
lea    0x18(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %ebp,%edi
call   10c0 <accept@plt>
mov    %eax,0x4(%rbx)
test   %eax,%eax
jns    12c9 <main+0x119>
lea    0xd6b(%rip),%rdi
call   1060 <dieWithMessage@plt>
mov    (%rbx),%edi
lea    0xd6d(%rip),%rsi
mov    $0x6,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
test   %rax,%rax
jns    12ef <main+0x13f>
lea    0xd5b(%rip),%rdi
call   1060 <dieWithMessage@plt>
mov    0x4(%rbx),%edi
lea    0xd46(%rip),%rsi
mov    $0x6,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
test   %rax,%rax
jns    1316 <main+0x166>
lea    0xd34(%rip),%rdi
call   1060 <dieWithMessage@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [17 x i8] c"socket() failed\0A\00"
@INADDR_ANY = global i32 0
@.str.1 = [14 x i8] c"bind() failed\00"
@.str.2 = [16 x i8] c"listen() failed\00"
@.str.3 = [16 x i8] c"accept() failed\00"
@.str.4 = [6 x i8] c"Hello\00"
@.str.5 = [14 x i8] c"send() failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i32*
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca %struct.sockaddr_in
%12 = alloca i32
%13 = alloca i32
%14 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %7
%15 = call i64 @malloc(i32 8)
%16 = inttoptr i64 %15 to i32*
store i32* %16, i32** %7
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = load i32, i32* @IPPROTO_TCP
%20 = call i32 @socket(i32 %17, i32 %18, i32 %19)
store i32 %20, i32* %8
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 @dieWithMessage(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %2
%25 = call i32 @memset(%struct.sockaddr_in* %9, i32 0, i32 12)
%26 = load i32, i32* @AF_INET
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %26, i32* %27
%28 = load i32, i32* @INADDR_ANY
%29 = call i32 @htonl(i32 %28)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%31 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %30, i32 0, i32 0
store i32 %29, i32* %31
%32 = call i32 @htons(i32 12345)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %32, i32* %33
%34 = load i32, i32* %8
%35 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%36 = call i64 @bind(i32 %34, %struct.sockaddr* %35, i32 12)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %24
%39 = call i32 @dieWithMessage(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %40
40: ; preds = %38, %24
%41 = load i32, i32* %8
%42 = call i64 @listen(i32 %41, i32 2)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 @dieWithMessage(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %46
46: ; preds = %44, %40
store i32 0, i32* %10
br label %47
47: ; preds = %67, %46
%48 = load i32, i32* %10
%49 = icmp slt i32 %48, 2
br i1 %49, label %50, label %70
50: ; preds = %47
store i32 12, i32* %12
%51 = load i32, i32* %8
%52 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%53 = call i32 @accept(i32 %51, %struct.sockaddr* %52, i32* %12)
%54 = load i32*, i32** %7
%55 = load i32, i32* %10
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %54, i64 %56
store i32 %53, i32* %57
%58 = load i32*, i32** %7
%59 = load i32, i32* %10
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i32, i32* %58, i64 %60
%62 = load i32, i32* %61
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %50
%65 = call i32 @dieWithMessage(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %66
66: ; preds = %64, %50
br label %67
67: ; preds = %66
%68 = load i32, i32* %10
%69 = add nsw i32 %68, 1
store i32 %69, i32* %10
br label %47
70: ; preds = %47
store i32 0, i32* %13
br label %71
71: ; preds = %86, %70
%72 = load i32, i32* %13
%73 = icmp slt i32 %72, 2
br i1 %73, label %74, label %89
74: ; preds = %71
%75 = load i32*, i32** %7
%76 = load i32, i32* %13
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i32, i32* %75, i64 %77
%79 = load i32, i32* %78
%80 = call i64 @send(i32 %79, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 6, i32 0)
store i64 %80, i64* %14
%81 = load i64, i64* %14
%82 = icmp slt i64 %81, 0
br i1 %82, label %83, label %85
83: ; preds = %74
%84 = call i32 @dieWithMessage(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %85
85: ; preds = %83, %74
br label %86
86: ; preds = %85
%87 = load i32, i32* %13
%88 = add nsw i32 %87, 1
store i32 %88, i32* %13
br label %71
89: ; preds = %71
%90 = load i32*, i32** %7
%91 = call i32 @free(i32* %90)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [17 x i8] c"socket() failed\0A\00"
@INADDR_ANY = global i32 0
@.str.1 = [14 x i8] c"bind() failed\00"
@.str.2 = [16 x i8] c"listen() failed\00"
@.str.3 = [16 x i8] c"accept() failed\00"
@.str.4 = [6 x i8] c"Hello\00"
@.str.5 = [14 x i8] c"send() failed\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = tail call i64 @malloc(i32 8)
%7 = inttoptr i64 %6 to i32*
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = load i32, i32* @IPPROTO_TCP
%11 = tail call i32 @socket(i32 %8, i32 %9, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = tail call i32 @dieWithMessage(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = bitcast %struct.sockaddr_in* %3 to i8*
%17 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %18, i32* %19
%20 = load i32, i32* @INADDR_ANY
%21 = call i32 @htonl(i32 %20)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %21, i32* %22
%23 = call i32 @htons(i32 12345)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %23, i32* %24
%25 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%26 = call i64 @bind(i32 %11, %struct.sockaddr* %25, i32 12)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %15
%29 = call i32 @dieWithMessage(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %15
%31 = call i64 @listen(i32 %11, i32 2)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 @dieWithMessage(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %33, %30
%36 = bitcast %struct.sockaddr_in* %4 to i8*
%37 = bitcast i32* %5 to i8*
%38 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
store i32 12, i32* %5
%39 = call i32 @accept(i32 %11, %struct.sockaddr* %38, i32* %5)
store i32 %39, i32* %7
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = call i32 @dieWithMessage(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %41, %35
store i32 12, i32* %5
%44 = call i32 @accept(i32 %11, %struct.sockaddr* %38, i32* %5)
%45 = getelementptr inbounds i32, i32* %7, i64 1
store i32 %44, i32* %45
%46 = icmp slt i32 %44, 0
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 @dieWithMessage(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %47, %43
%50 = load i32, i32* %7
%51 = call i64 @send(i32 %50, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 6, i32 0)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = call i32 @dieWithMessage(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %55
55: ; preds = %53, %49
%56 = load i32, i32* %45
%57 = call i64 @send(i32 %56, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 6, i32 0)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %55
%60 = call i32 @dieWithMessage(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %61
61: ; preds = %59, %55
%62 = call i32 @free(i32* %7)
ret i32 0
}