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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ MSG_WAITALL;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ close(int const);
int connect(int const, struct sockaddr *, int);
int /*<<< orphan*/ error();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, char, int);
int /*<<< orphan*/ message(int const, char *);
int /*<<< orphan*/ newGame(int const, int const);
int /*<<< orphan*/ printf(char *);
int recv(int const, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc < 3) {
    fprintf(stderr, "Usage: %s ip_address port\n", argv[0]);
    exit(1);
  }
  char buff[256];
  struct sockaddr_in server;
  server.sin_family = AF_INET;
  server.sin_port = htons(atoi(argv[2]));
  server.sin_addr.s_addr = inet_addr(argv[1]);
  memset(&(server.sin_zero), '\0', 8);
  const int socketDescriptor = socket(AF_INET, SOCK_STREAM, 0);
  if (connect(socketDescriptor, (struct sockaddr *)&server, sizeof(server)) ==
      -1) {
    error();
  }
  int n = recv(socketDescriptor, buff, 256, MSG_WAITALL);
  const int id = atoi(buff);
  if (id == 4) {
    printf("You are Player ONE\n");
    printf("Waiting for Player TWO to connect\n");
    message(socketDescriptor, "ok");
  } else {
    printf("You are Player TWO\n");
    message(socketDescriptor, "ok");
  }
  if (n <= 0) {
    error();
  }
  newGame(socketDescriptor, id);
  close(socketDescriptor);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1229 <main+0x49>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xde6(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x114(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,-0x118(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x11c(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
mov    0x2d48(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x124(%rbp)
mov    -0x124(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x10,%edx
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
jne    12be <main+0xde>
mov    $0x0,%al
call   10b0 <error@plt>
mov    -0x124(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    0x2cee(%rip),%rax
mov    (%rax),%ecx
mov    $0x100,%edx
call   1030 <recv@plt>
mov    %eax,-0x128(%rbp)
lea    -0x110(%rbp),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x12c(%rbp)
cmpl   $0x4,-0x12c(%rbp)
jne    1332 <main+0x152>
lea    0xd11(%rip),%rdi
call   1060 <printf@plt>
lea    0xd19(%rip),%rdi
call   1060 <printf@plt>
mov    -0x124(%rbp),%edi
lea    0xd2a(%rip),%rsi
call   1040 <message@plt>
jmp    1350 <main+0x170>
lea    0xd1c(%rip),%rdi
call   1060 <printf@plt>
mov    -0x124(%rbp),%edi
lea    0xd07(%rip),%rsi
call   1040 <message@plt>
cmpl   $0x0,-0x128(%rbp)
jg     1364 <main+0x184>
mov    $0x0,%al
call   10b0 <error@plt>
mov    -0x124(%rbp),%edi
mov    -0x12c(%rbp),%esi
call   10f0 <newGame@plt>
mov    -0x124(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x110,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jle    12f0 <main+0x110>
mov    0x2dea(%rip),%r14
mov    (%r14),%eax
mov    %eax,0xc(%rsp)
mov    0x10(%rbx),%rdi
call   10c0 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,0x8(%rsp)
mov    0x8(%rbx),%rdi
call   1090 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
mov    (%r14),%edi
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    %rbp,%rsi
mov    $0x10,%edx
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
jne    1268 <main+0x88>
xor    %eax,%eax
call   10b0 <error@plt>
mov    0x2d51(%rip),%rax
mov    (%rax),%ecx
lea    0x10(%rsp),%rbp
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x100,%edx
call   1030 <recv@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   10c0 <atoi@plt>
mov    %eax,%ebp
cmp    $0x4,%eax
jne    12ac <main+0xcc>
lea    0xd93(%rip),%rdi
call   1050 <puts@plt>
lea    0xd9a(%rip),%rdi
jmp    12b3 <main+0xd3>
lea    0xd6b(%rip),%rdi
call   1050 <puts@plt>
lea    0xd5c(%rip),%rsi
mov    %ebx,%edi
call   1040 <message@plt>
test   %r14d,%r14d
jg     12d2 <main+0xf2>
xor    %eax,%eax
call   10b0 <error@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   10f0 <newGame@plt>
mov    %ebx,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xcfd(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [27 x i8] c"Usage: %s ip_address port\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@MSG_WAITALL = global i32 0
@.str.1 = [20 x i8] c"You are Player ONE\0A\00"
@.str.2 = [35 x i8] c"Waiting for Player TWO to connect\0A\00"
@.str.3 = [3 x i8] c"ok\00"
@.str.4 = [20 x i8] c"You are Player TWO\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 3
store i32 %21, i32* %22
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
%27 = call i32 @htons(i32 %26)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %27, i32* %28
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @inet_addr(i8* %31)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%34 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %33, i32 0, i32 0
store i32 %32, i32* %34
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%36 = call i32 @memset(i32* %35, i8 signext 0, i32 8)
%37 = load i32, i32* @AF_INET
%38 = load i32, i32* @SOCK_STREAM
%39 = call i32 @socket(i32 %37, i32 %38, i32 0)
store i32 %39, i32* %8
%40 = load i32, i32* %8
%41 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%42 = call i32 @connect(i32 %40, %struct.sockaddr* %41, i32 16)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %20
%45 = call i32 (...) @error()
br label %46
46: ; preds = %44, %20
%47 = load i32, i32* %8
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%49 = load i32, i32* @MSG_WAITALL
%50 = call i32 @recv(i32 %47, i8* %48, i32 256, i32 %49)
store i32 %50, i32* %9
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%52 = call i32 @atoi(i8* %51)
store i32 %52, i32* %10
%53 = load i32, i32* %10
%54 = icmp eq i32 %53, 4
br i1 %54, label %55, label %60
55: ; preds = %46
%56 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%57 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%58 = load i32, i32* %8
%59 = call i32 @message(i32 %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %64
60: ; preds = %46
%61 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%62 = load i32, i32* %8
%63 = call i32 @message(i32 %62, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %64
64: ; preds = %60, %55
%65 = load i32, i32* %9
%66 = icmp sle i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %64
%68 = call i32 (...) @error()
br label %69
69: ; preds = %67, %64
%70 = load i32, i32* %8
%71 = load i32, i32* %10
%72 = call i32 @newGame(i32 %70, i32 %71)
%73 = load i32, i32* %8
%74 = call i32 @close(i32 %73)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [27 x i8] c"Usage: %s ip_address port\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@MSG_WAITALL = global i32 0
@.str.3 = [3 x i8] c"ok\00"
@str = [19 x i8] c"You are Player TWO\00"
@str.5 = [19 x i8] c"You are Player ONE\00"
@str.6 = [34 x i8] c"Waiting for Player TWO to connect\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca %struct.sockaddr_in
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%13 = bitcast %struct.sockaddr_in* %4 to i8*
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 3
store i32 %14, i32* %15
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
%19 = tail call i32 @htons(i32 %18)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %19, i32* %20
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = tail call i32 @inet_addr(i8* %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%26 = call i32 @memset(i32* %25, i8 signext 0, i32 8)
%27 = load i32, i32* @AF_INET
%28 = load i32, i32* @SOCK_STREAM
%29 = call i32 @socket(i32 %27, i32 %28, i32 0)
%30 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%31 = call i32 @connect(i32 %29, %struct.sockaddr* %30, i32 16)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %11
%34 = call i32 (...) @error()
br label %35
35: ; preds = %33, %11
%36 = load i32, i32* @MSG_WAITALL
%37 = call i32 @recv(i32 %29, i8* %12, i32 256, i32 %36)
%38 = call i32 @atoi(i8* %12)
%39 = icmp eq i32 %38, 4
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.5, i64 0, i64 0))
br label %42
42: ; preds = %35, %40
%43 = phi i8* [ getelementptr inbounds ([34 x i8], [34 x i8]* @str.6, i64 0, i64 0), %40 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0), %35 ]
%44 = call i32 @puts(i8* dereferenceable(1) %43)
%45 = call i32 @message(i32 %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%46 = icmp slt i32 %37, 1
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = call i32 (...) @error()
br label %49
49: ; preds = %47, %42
%50 = call i32 @newGame(i32 %29, i32 %38)
%51 = call i32 @close(i32 %29)
ret i32 0
}