#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 {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ bind(int, struct sockaddr *, int);
int *calloc(int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ peasant(int, int, int *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  int listener;
  struct sockaddr_in addr;
  char word_buf_2[1024];
  char word_buf_1[1024];
  int offset = 0;
  int *used_words;
  int soc1, soc2;
  used_words = calloc(1024, sizeof(int));
  used_words[0] = 228;
  listener = socket(AF_INET, SOCK_STREAM, 0);
  if (listener < 0) {
    perror("socket");
    exit(1);
  }
  addr.sin_family = AF_INET;
  addr.sin_port = htons(3426);
  addr.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(listener, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
    perror("bind");
    exit(2);
  }
  listen(listener, 2);
  while (1) {
    soc1 = accept(listener, NULL, NULL);
    soc2 = accept(listener, NULL, NULL);
    if ((soc1 < 0) || (soc2 < 0)) {
      perror("accept");
      exit(3);
    }
    send(soc1, "1", 1, 0);
    send(soc2, "2", 1, 0);
    char last_l;
    last_l = 'a';
    while (1) {
      peasant(soc1, soc2, used_words, &last_l);
      peasant(soc2, soc1, used_words, &last_l);
    }
  }
  close(soc1);
  close(soc2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x824(%rbp)
mov    $0x400,%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,-0x830(%rbp)
mov    -0x830(%rbp),%rax
movl   $0xe4,(%rax)
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    122b <main+0x7b>
lea    0xde4(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0xd62,%edi
call   1030 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
cmp    $0x0,%rax
jge    1286 <main+0xd6>
lea    0xd90(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x2,%edi
call   10c0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    $0x2,%esi
call   1070 <listen@plt>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   10b0 <accept@plt>
mov    %eax,-0x834(%rbp)
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   10b0 <accept@plt>
mov    %eax,-0x838(%rbp)
cmpl   $0x0,-0x834(%rbp)
jl     12d7 <main+0x127>
cmpl   $0x0,-0x838(%rbp)
jge    12ed <main+0x13d>
lea    0xd2e(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x3,%edi
call   10c0 <exit@plt>
mov    -0x834(%rbp),%edi
lea    0xd19(%rip),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    -0x838(%rbp),%edi
lea    0xd02(%rip),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
movb   $0x61,-0x839(%rbp)
mov    -0x834(%rbp),%edi
mov    -0x838(%rbp),%esi
mov    -0x830(%rbp),%rdx
lea    -0x839(%rbp),%rcx
call   1090 <peasant@plt>
mov    -0x838(%rbp),%edi
mov    -0x834(%rbp),%esi
mov    -0x830(%rbp),%rdx
lea    -0x839(%rbp),%rcx
call   1090 <peasant@plt>
jmp    1326 <main+0x176>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    $0x400,%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,%r15
movl   $0xe4,(%rax)
mov    0x2e0f(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
js     12d0 <main+0x120>
mov    %eax,%r14d
mov    (%rbx),%eax
mov    %eax,0x10(%rsp)
mov    $0xd62,%edi
call   1030 <htons@plt>
mov    %eax,0xc(%rsp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   1080 <bind@plt>
test   %rax,%rax
js     12e6 <main+0x136>
mov    %r14d,%edi
mov    $0x2,%esi
call   1070 <listen@plt>
mov    %r14d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10b0 <accept@plt>
mov    %eax,%ebp
mov    %r14d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10b0 <accept@plt>
test   %ebp,%ebp
js     12fc <main+0x14c>
mov    %eax,%ebx
test   %eax,%eax
js     12fc <main+0x14c>
lea    0xd9c(%rip),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
lea    0xd89(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
movb   $0x61,0x7(%rsp)
lea    0x7(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r15,%rdx
mov    %r14,%rcx
call   1090 <peasant@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r15,%rdx
mov    %r14,%rcx
call   1090 <peasant@plt>
jmp    12b0 <main+0x100>
lea    0xd29(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0xd1a(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x2,%edi
call   10c0 <exit@plt>
lea    0xd09(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x3,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@INADDR_ANY = global i32 0
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [7 x i8] c"accept\00"
@.str.3 = [2 x i8] c"1\00"
@.str.4 = [2 x i8] c"2\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %6
%11 = call i32* @calloc(i32 1024, i32 4)
store i32* %11, i32** %7
%12 = load i32*, i32** %7
%13 = getelementptr inbounds i32, i32* %12, i64 0
store i32 228, i32* %13
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %2
%17 = load i32, i32* %2
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %0
%20 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %0
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %23, i32* %24
%25 = call i32 @htons(i32 3426)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %25, i32* %26
%27 = load i32, i32* @INADDR_ANY
%28 = call i32 @htonl(i32 %27)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%30 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %29, i32 0, i32 0
store i32 %28, i32* %30
%31 = load i32, i32* %2
%32 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%33 = call i64 @bind(i32 %31, %struct.sockaddr* %32, i32 12)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %22
%36 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%37 = call i32 @exit(i32 2)
unreachable
38: ; preds = %22
%39 = load i32, i32* %2
%40 = call i32 @listen(i32 %39, i32 2)
br label %41
41: ; preds = %38
%42 = load i32, i32* %2
%43 = call i32 @accept(i32 %42, i32* null, i32* null)
store i32 %43, i32* %8
%44 = load i32, i32* %2
%45 = call i32 @accept(i32 %44, i32* null, i32* null)
store i32 %45, i32* %9
%46 = load i32, i32* %8
%47 = icmp slt i32 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %41
%49 = load i32, i32* %9
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %48, %41
%52 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%53 = call i32 @exit(i32 3)
unreachable
54: ; preds = %48
%55 = load i32, i32* %8
%56 = call i32 @send(i32 %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 0)
%57 = load i32, i32* %9
%58 = call i32 @send(i32 %57, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1, i32 0)
store i8 97, i8* %10
br label %59
59: ; preds = %54, %59
%60 = load i32, i32* %8
%61 = load i32, i32* %9
%62 = load i32*, i32** %7
%63 = call i32 @peasant(i32 %60, i32 %61, i32* %62, i8* %10)
%64 = load i32, i32* %9
%65 = load i32, i32* %8
%66 = load i32*, i32** %7
%67 = call i32 @peasant(i32 %64, i32 %65, i32* %66, i8* %10)
br label %59
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@INADDR_ANY = global i32 0
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [7 x i8] c"accept\00"
@.str.3 = [2 x i8] c"1\00"
@.str.4 = [2 x i8] c"2\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i8
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = tail call i32* @calloc(i32 1024, i32 4)
store i32 228, i32* %4
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %13, i32* %14
%15 = tail call i32 @htons(i32 3426)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %15, i32* %16
%17 = load i32, i32* @INADDR_ANY
%18 = tail call i32 @htonl(i32 %17)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %18, i32* %19
%20 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%21 = call i64 @bind(i32 %7, %struct.sockaddr* %20, i32 12)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %12
%24 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 2)
unreachable
26: ; preds = %12
%27 = call i32 @listen(i32 %7, i32 2)
%28 = call i32 @accept(i32 %7, i32* null, i32* null)
%29 = call i32 @accept(i32 %7, i32* null, i32* null)
%30 = icmp slt i32 %28, 0
%31 = icmp slt i32 %29, 0
%32 = select i1 %30, i1 true, i1 %31
br i1 %32, label %33, label %36
33: ; preds = %26
%34 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 @exit(i32 3)
unreachable
36: ; preds = %26
%37 = call i32 @send(i32 %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 0)
%38 = call i32 @send(i32 %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1, i32 0)
store i8 97, i8* %2
br label %39
39: ; preds = %39, %36
%40 = call i32 @peasant(i32 %28, i32 %29, i32* %4, i8* %2)
%41 = call i32 @peasant(i32 %29, i32 %28, i32* %4, i8* %2)
br label %39
}