#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 */

/* Variables and functions */
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
unsigned short atoi(char *);
int check_winner(int, char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ connect_server(int, unsigned short, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ init_tril();
int /*<<< orphan*/ opp_play(int, char *);
int /*<<< orphan*/ play(int, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read_server(int, char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ send_server(int, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strncmp(char *, char *, int);
int main(int argc, char **argv) {
  int fd;
  unsigned short ServPort;
  char *servIP;
  int err;
  char buff[32], buff_r[32];
  char buff_win[32];
  char num[1], name[40];
  char pl[1];
  int i;
  if (argc != 3) {
    printf("Usage: %s  <Echo Port> <Server IP>\n", argv[0]);
    exit(1);
  }
  ServPort = atoi(argv[1]);
  servIP = argv[2];
  fd = socket(PF_INET, SOCK_STREAM, 0);
  if (fd < 0) {
    printf("socket() failed\n");
    exit(-1);
  }
  connect_server(fd, ServPort, servIP);
  printf("Please give your name: \n");
  scanf("%s", name);
  strcpy(buff, "HELLO ");
  strcat(buff, name);
  send_server(fd, buff);
  read_server(fd, buff_r);
  strcpy(num, buff_r + 8);
  printf("Welcome %s, you are player %s \n", name, num);
  strcpy(buff_win, "WINNER_NO");
  do {
    read_server(fd, buff_r);
  } while (strcmp(buff_r, "STARTING"));
  printf("\n%s\n", buff_r);
  do {
    read_server(fd, buff_r);
  } while (strncmp(buff_r, "BATTLE", 6));
  init_tril();
  strcpy(pl, buff_r + 7);
  if (strncmp(pl, num, 1) == 0) {
    printf("You are playing first\n");
    for (i = 0;; i++) {
      play(fd, buff, buff_r);
      err = check_winner(fd, buff_win);
      if (err == 1)
        break;
      strcpy(buff, "  ");
      strcpy(buff_r, "  ");
      opp_play(fd, buff_r);
      err = check_winner(fd, buff_win);
      if (err == 1)
        break;
    }
  } else {
    printf("Opponent is playing first\n");
    for (i = 0;; i++) {
      opp_play(fd, buff_r);
      err = check_winner(fd, buff_win);
      if (err == 1)
        break;
      strcpy(buff, "  ");
      strcpy(buff_r, "  ");
      play(fd, buff, buff_r);
      err = check_winner(fd, buff_win);
      if (err == 1)
        break;
    }
  }
  printf("\n");
  printf("\n");
  strcpy(pl, buff_win + 7);
  if (strncmp(pl, num, 1) == 0) {
    printf("YOU WON !!!!!!!\n\nGOODBYE\n");
  } else
    printf("YOU LOST !!\n\nGOODBYE\n");
  printf("\n");
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1252 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10e0 <atoi@plt>
mov    %ax,-0x16(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
mov    0x2d61(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12ad <main+0x9d>
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x16(%rbp),%ax
mov    -0x20(%rbp),%rdx
movzwl %ax,%esi
call   1080 <connect_server@plt>
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    -0xc0(%rbp),%rsi
lea    0xd72(%rip),%rdi
call   10d0 <scanf@plt>
lea    -0x50(%rbp),%rdi
lea    0xd65(%rip),%rsi
call   1060 <strcpy@plt>
lea    -0x50(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
call   10f0 <strcat@plt>
mov    -0x14(%rbp),%edi
lea    -0x50(%rbp),%rsi
call   1040 <send_server@plt>
mov    -0x14(%rbp),%edi
lea    -0x70(%rbp),%rsi
call   1030 <read_server@plt>
lea    -0x91(%rbp),%rdi
lea    -0x70(%rbp),%rsi
add    $0x8,%rsi
call   1060 <strcpy@plt>
lea    -0xc0(%rbp),%rsi
lea    -0x91(%rbp),%rdx
lea    0xd16(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    -0x90(%rbp),%rdi
lea    0xd21(%rip),%rsi
call   1060 <strcpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x70(%rbp),%rsi
call   1030 <read_server@plt>
lea    -0x70(%rbp),%rdi
lea    0xd0f(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
jne    135c <main+0x14c>
lea    -0x70(%rbp),%rsi
lea    0xcfe(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x70(%rbp),%rsi
call   1030 <read_server@plt>
lea    -0x70(%rbp),%rdi
lea    0xce5(%rip),%rsi
mov    $0x6,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    1394 <main+0x184>
mov    $0x0,%al
call   1120 <init_tril@plt>
lea    -0xc1(%rbp),%rdi
lea    -0x70(%rbp),%rsi
add    $0x7,%rsi
call   1060 <strcpy@plt>
lea    -0xc1(%rbp),%rdi
lea    -0x91(%rbp),%rsi
mov    $0x1,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    14b0 <main+0x2a0>
lea    0xc94(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
movl   $0x0,-0xc8(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x50(%rbp),%rsi
lea    -0x70(%rbp),%rdx
call   10c0 <play@plt>
mov    -0x14(%rbp),%edi
lea    -0x90(%rbp),%rsi
call   1100 <check_winner@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jne    1445 <main+0x235>
jmp    14ab <main+0x29b>
lea    -0x50(%rbp),%rdi
lea    0xc5e(%rip),%rsi
call   1060 <strcpy@plt>
lea    -0x70(%rbp),%rdi
lea    0xc4e(%rip),%rsi
call   1060 <strcpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x70(%rbp),%rsi
call   1070 <opp_play@plt>
mov    -0x14(%rbp),%edi
lea    -0x90(%rbp),%rsi
call   1100 <check_winner@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jne    1492 <main+0x282>
jmp    14ab <main+0x29b>
jmp    1497 <main+0x287>
mov    -0xc8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc8(%rbp)
jmp    1414 <main+0x204>
jmp    1564 <main+0x354>
lea    0xbfa(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
movl   $0x0,-0xc8(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x70(%rbp),%rsi
call   1070 <opp_play@plt>
mov    -0x14(%rbp),%edi
lea    -0x90(%rbp),%rsi
call   1100 <check_winner@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jne    14f5 <main+0x2e5>
jmp    155f <main+0x34f>
lea    -0x50(%rbp),%rdi
lea    0xbae(%rip),%rsi
call   1060 <strcpy@plt>
lea    -0x70(%rbp),%rdi
lea    0xb9e(%rip),%rsi
call   1060 <strcpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x50(%rbp),%rsi
lea    -0x70(%rbp),%rdx
call   10c0 <play@plt>
mov    -0x14(%rbp),%edi
lea    -0x90(%rbp),%rsi
call   1100 <check_winner@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jne    1546 <main+0x336>
jmp    155f <main+0x34f>
jmp    154b <main+0x33b>
mov    -0xc8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc8(%rbp)
jmp    14c8 <main+0x2b8>
jmp    1564 <main+0x354>
lea    0xae1(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0xad3(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    -0xc1(%rbp),%rdi
lea    -0x90(%rbp),%rsi
add    $0x7,%rsi
call   1060 <strcpy@plt>
lea    -0xc1(%rbp),%rdi
lea    -0x91(%rbp),%rsi
mov    $0x1,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    15cc <main+0x3bc>
lea    0xb0c(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
jmp    15da <main+0x3ca>
lea    0xb13(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0xa6b(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xa0,%rsp
mov    %rsi,%rbp
cmp    $0x3,%edi
jne    1520 <main+0x2f0>
mov    0x8(%rbp),%rdi
call   1100 <atoi@plt>
mov    %eax,%ebx
mov    0x10(%rbp),%r14
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
mov    0x2d76(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
test   %eax,%eax
js     153c <main+0x30c>
mov    %eax,%ebp
movzwl %bx,%esi
mov    %eax,%edi
mov    %r14,%rdx
call   10a0 <connect_server@plt>
lea    0xddf(%rip),%rdi
call   1080 <puts@plt>
lea    0xd87(%rip),%rdi
lea    0x70(%rsp),%r14
mov    %r14,%rsi
call   10f0 <scanf@plt>
lea    0xd76(%rip),%rsi
lea    0x50(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1110 <strcat@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <send_server@plt>
lea    0x10(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <read_server@plt>
lea    0x18(%rsp),%rsi
lea    0xe(%rsp),%r15
mov    %r15,%rdi
call   1070 <strcpy@plt>
lea    0xd33(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   10b0 <printf@plt>
lea    0xd3f(%rip),%rsi
lea    0x30(%rsp),%rdi
call   1070 <strcpy@plt>
lea    0xd38(%rip),%r14
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <read_server@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10d0 <strcmp@plt>
test   %rax,%rax
jne    1320 <main+0xf0>
lea    0xd20(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   10b0 <printf@plt>
lea    0xd0f(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <read_server@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x6,%edx
call   1060 <strncmp@plt>
test   %rax,%rax
jne    1360 <main+0x130>
xor    %eax,%eax
call   1140 <init_tril@plt>
lea    0x17(%rsp),%rsi
lea    0xf(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <strcpy@plt>
lea    0xe(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1060 <strncmp@plt>
test   %rax,%rax
je     1431 <main+0x201>
lea    0xcce(%rip),%rdi
call   1080 <puts@plt>
lea    0x10(%rsp),%rbx
lea    0x30(%rsp),%r14
lea    0xc9d(%rip),%r15
lea    0x50(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
mov    %rbx,%rsi
call   1090 <opp_play@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1120 <check_winner@plt>
cmp    $0x1,%eax
je     14ab <main+0x27b>
mov    %r12,%rdi
mov    %r15,%rsi
call   1070 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcpy@plt>
mov    %ebp,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
call   10e0 <play@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1120 <check_winner@plt>
cmp    $0x1,%eax
jne    13e0 <main+0x1b0>
jmp    14ab <main+0x27b>
lea    0xc98(%rip),%rdi
call   1080 <puts@plt>
lea    0x50(%rsp),%r14
lea    0x10(%rsp),%rbx
lea    0x30(%rsp),%r15
lea    0xc1a(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   10e0 <play@plt>
mov    %ebp,%edi
mov    %r15,%rsi
call   1120 <check_winner@plt>
cmp    $0x1,%eax
je     14ab <main+0x27b>
mov    %r14,%rdi
mov    %r12,%rsi
call   1070 <strcpy@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1070 <strcpy@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1090 <opp_play@plt>
mov    %ebp,%edi
mov    %r15,%rsi
call   1120 <check_winner@plt>
cmp    $0x1,%eax
jne    1460 <main+0x230>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0x37(%rsp),%rsi
lea    0xf(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <strcpy@plt>
lea    0xe(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1060 <strncmp@plt>
test   %rax,%rax
lea    0xbca(%rip),%rax
lea    0xbae(%rip),%rdi
cmove  %rax,%rdi
call   1080 <puts@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %ebp,%edi
call   10c0 <close@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x0(%rbp),%rsi
lea    0xad5(%rip),%rdi
xor    %eax,%eax
call   10b0 <printf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
lea    0xba3(%rip),%rdi
call   1080 <puts@plt>
mov    $0xffffffff,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"Usage: %s <Echo Port> <Server IP>\0A\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [17 x i8] c"socket() failed\0A\00"
@.str.2 = [25 x i8] c"Please give your name: \0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [7 x i8] c"HELLO \00"
@.str.5 = [32 x i8] c"Welcome %s, you are player %s \0A\00"
@.str.6 = [10 x i8] c"WINNER_NO\00"
@.str.7 = [9 x i8] c"STARTING\00"
@.str.8 = [5 x i8] c"\0A%s\0A\00"
@.str.9 = [7 x i8] c"BATTLE\00"
@.str.10 = [23 x i8] c"You are playing first\0A\00"
@.str.11 = [3 x i8] c" \00"
@.str.12 = [27 x i8] c"Opponent is playing first\0A\00"
@.str.13 = [2 x i8] c"\0A\00"
@.str.14 = [26 x i8] c"YOU WON !!!!!!!\0A\0AGOODBYE\0A\00"
@.str.15 = [22 x i8] c"YOU LOST !!\0A\0AGOODBYE\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i16
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [32 x i8]
%11 = alloca [32 x i8]
%12 = alloca [32 x i8]
%13 = alloca [1 x i8]
%14 = alloca [40 x i8]
%15 = alloca [1 x i8]
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 3
br i1 %18, label %19, label %25
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call zeroext i16 @atoi(i8* %28)
store i16 %29, i16* %7
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
store i8* %32, i8** %8
%33 = load i32, i32* @PF_INET
%34 = load i32, i32* @SOCK_STREAM
%35 = call i32 @socket(i32 %33, i32 %34, i32 0)
store i32 %35, i32* %6
%36 = load i32, i32* %6
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %25
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%40 = call i32 @exit(i32 -1)
unreachable
41: ; preds = %25
%42 = load i32, i32* %6
%43 = load i16, i16* %7
%44 = load i8*, i8** %8
%45 = call i32 @connect_server(i32 %42, i16 zeroext %43, i8* %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%47 = getelementptr inbounds [40 x i8], [40 x i8]* %14, i64 0, i64 0
%48 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %47)
%49 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%50 = call i32 @strcpy(i8* %49, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%51 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%52 = getelementptr inbounds [40 x i8], [40 x i8]* %14, i64 0, i64 0
%53 = call i32 @strcat(i8* %51, i8* %52)
%54 = load i32, i32* %6
%55 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%56 = call i32 @send_server(i32 %54, i8* %55)
%57 = load i32, i32* %6
%58 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%59 = call i32 @read_server(i32 %57, i8* %58)
%60 = getelementptr inbounds [1 x i8], [1 x i8]* %13, i64 0, i64 0
%61 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%62 = getelementptr inbounds i8, i8* %61, i64 8
%63 = call i32 @strcpy(i8* %60, i8* %62)
%64 = getelementptr inbounds [40 x i8], [40 x i8]* %14, i64 0, i64 0
%65 = getelementptr inbounds [1 x i8], [1 x i8]* %13, i64 0, i64 0
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %64, i8* %65)
%67 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%68 = call i32 @strcpy(i8* %67, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %69
69: ; preds = %73, %41
%70 = load i32, i32* %6
%71 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%72 = call i32 @read_server(i32 %70, i8* %71)
br label %73
73: ; preds = %69
%74 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%75 = call i64 @strcmp(i8* %74, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%76 = icmp ne i64 %75, 0
br i1 %76, label %69, label %77
77: ; preds = %73
%78 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* %78)
br label %80
80: ; preds = %84, %77
%81 = load i32, i32* %6
%82 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%83 = call i32 @read_server(i32 %81, i8* %82)
br label %84
84: ; preds = %80
%85 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%86 = call i64 @strncmp(i8* %85, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i32 6)
%87 = icmp ne i64 %86, 0
br i1 %87, label %80, label %88
88: ; preds = %84
%89 = call i32 (...) @init_tril()
%90 = getelementptr inbounds [1 x i8], [1 x i8]* %15, i64 0, i64 0
%91 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%92 = getelementptr inbounds i8, i8* %91, i64 7
%93 = call i32 @strcpy(i8* %90, i8* %92)
%94 = getelementptr inbounds [1 x i8], [1 x i8]* %15, i64 0, i64 0
%95 = getelementptr inbounds [1 x i8], [1 x i8]* %13, i64 0, i64 0
%96 = call i64 @strncmp(i8* %94, i8* %95, i32 1)
%97 = icmp eq i64 %96, 0
br i1 %97, label %98, label %130
98: ; preds = %88
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0))
store i32 0, i32* %16
br label %100
100: ; preds = %126, %98
%101 = load i32, i32* %6
%102 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%103 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%104 = call i32 @play(i32 %101, i8* %102, i8* %103)
%105 = load i32, i32* %6
%106 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%107 = call i32 @check_winner(i32 %105, i8* %106)
store i32 %107, i32* %9
%108 = load i32, i32* %9
%109 = icmp eq i32 %108, 1
br i1 %109, label %110, label %111
110: ; preds = %100
br label %129
111: ; preds = %100
%112 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%113 = call i32 @strcpy(i8* %112, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%114 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%115 = call i32 @strcpy(i8* %114, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%116 = load i32, i32* %6
%117 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%118 = call i32 @opp_play(i32 %116, i8* %117)
%119 = load i32, i32* %6
%120 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%121 = call i32 @check_winner(i32 %119, i8* %120)
store i32 %121, i32* %9
%122 = load i32, i32* %9
%123 = icmp eq i32 %122, 1
br i1 %123, label %124, label %125
124: ; preds = %111
br label %129
125: ; preds = %111
br label %126
126: ; preds = %125
%127 = load i32, i32* %16
%128 = add nsw i32 %127, 1
store i32 %128, i32* %16
br label %100
129: ; preds = %124, %110
br label %162
130: ; preds = %88
%131 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.12, i64 0, i64 0))
store i32 0, i32* %16
br label %132
132: ; preds = %158, %130
%133 = load i32, i32* %6
%134 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%135 = call i32 @opp_play(i32 %133, i8* %134)
%136 = load i32, i32* %6
%137 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%138 = call i32 @check_winner(i32 %136, i8* %137)
store i32 %138, i32* %9
%139 = load i32, i32* %9
%140 = icmp eq i32 %139, 1
br i1 %140, label %141, label %142
141: ; preds = %132
br label %161
142: ; preds = %132
%143 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%144 = call i32 @strcpy(i8* %143, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%145 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%146 = call i32 @strcpy(i8* %145, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%147 = load i32, i32* %6
%148 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%149 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%150 = call i32 @play(i32 %147, i8* %148, i8* %149)
%151 = load i32, i32* %6
%152 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%153 = call i32 @check_winner(i32 %151, i8* %152)
store i32 %153, i32* %9
%154 = load i32, i32* %9
%155 = icmp eq i32 %154, 1
br i1 %155, label %156, label %157
156: ; preds = %142
br label %161
157: ; preds = %142
br label %158
158: ; preds = %157
%159 = load i32, i32* %16
%160 = add nsw i32 %159, 1
store i32 %160, i32* %16
br label %132
161: ; preds = %156, %141
br label %162
162: ; preds = %161, %129
%163 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
%164 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
%165 = getelementptr inbounds [1 x i8], [1 x i8]* %15, i64 0, i64 0
%166 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%167 = getelementptr inbounds i8, i8* %166, i64 7
%168 = call i32 @strcpy(i8* %165, i8* %167)
%169 = getelementptr inbounds [1 x i8], [1 x i8]* %15, i64 0, i64 0
%170 = getelementptr inbounds [1 x i8], [1 x i8]* %13, i64 0, i64 0
%171 = call i64 @strncmp(i8* %169, i8* %170, i32 1)
%172 = icmp eq i64 %171, 0
br i1 %172, label %173, label %175
173: ; preds = %162
%174 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.14, i64 0, i64 0))
br label %177
175: ; preds = %162
%176 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.15, i64 0, i64 0))
br label %177
177: ; preds = %175, %173
%178 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
%179 = load i32, i32* %6
%180 = call i32 @close(i32 %179)
ret i32 0
}

LLVM IR (-O2):
@.str = [36 x i8] c"Usage: %s <Echo Port> <Server IP>\0A\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [7 x i8] c"HELLO \00"
@.str.5 = [32 x i8] c"Welcome %s, you are player %s \0A\00"
@.str.6 = [10 x i8] c"WINNER_NO\00"
@.str.7 = [9 x i8] c"STARTING\00"
@.str.8 = [5 x i8] c"\0A%s\0A\00"
@.str.9 = [7 x i8] c"BATTLE\00"
@.str.11 = [3 x i8] c" \00"
@str = [24 x i8] c"Please give your name: \00"
@str.16 = [26 x i8] c"Opponent is playing first\00"
@str.17 = [21 x i8] c"YOU LOST !!\0A\0AGOODBYE\00"
@str.18 = [25 x i8] c"YOU WON !!!!!!!\0A\0AGOODBYE\00"
@str.19 = [22 x i8] c"You are playing first\00"
@str.20 = [16 x i8] c"socket() failed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [32 x i8]
%4 = alloca [32 x i8]
%5 = alloca [32 x i8]
%6 = alloca [1 x i8]
%7 = alloca [40 x i8]
%8 = alloca [1 x i8]
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 0
%13 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%14 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%15 = icmp eq i32 %0, 3
br i1 %15, label %20, label %16
16: ; preds = %2
%17 = load i8*, i8** %1
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = tail call zeroext i16 @atoi(i8* %22)
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = load i32, i32* @PF_INET
%27 = load i32, i32* @SOCK_STREAM
%28 = tail call i32 @socket(i32 %26, i32 %27, i32 0)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %20
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.20, i64 0, i64 0))
%32 = tail call i32 @exit(i32 -1)
unreachable
33: ; preds = %20
%34 = tail call i32 @connect_server(i32 %28, i16 zeroext %23, i8* %25)
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%37 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%38 = call i32 @strcat(i8* %9, i8* %13)
%39 = call i32 @send_server(i32 %28, i8* %9)
%40 = call i32 @read_server(i32 %28, i8* %10)
%41 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 8
%42 = call i32 @strcpy(i8* %12, i8* %41)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %13, i8* %12)
%44 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %45
45: ; preds = %45, %33
%46 = call i32 @read_server(i32 %28, i8* %10)
%47 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %45
49: ; preds = %45
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* %10)
br label %51
51: ; preds = %51, %49
%52 = call i32 @read_server(i32 %28, i8* %10)
%53 = call i64 @strncmp(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i32 6)
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %51
55: ; preds = %51
%56 = call i32 (...) @init_tril()
%57 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 7
%58 = call i32 @strcpy(i8* %14, i8* %57)
%59 = call i64 @strncmp(i8* %14, i8* %12, i32 1)
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %73
61: ; preds = %55
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.19, i64 0, i64 0))
br label %63
63: ; preds = %67, %61
%64 = call i32 @play(i32 %28, i8* %9, i8* %10)
%65 = call i32 @check_winner(i32 %28, i8* %11)
%66 = icmp eq i32 %65, 1
br i1 %66, label %85, label %67
67: ; preds = %63
%68 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%69 = call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%70 = call i32 @opp_play(i32 %28, i8* %10)
%71 = call i32 @check_winner(i32 %28, i8* %11)
%72 = icmp eq i32 %71, 1
br i1 %72, label %85, label %63
73: ; preds = %55
%74 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.16, i64 0, i64 0))
br label %75
75: ; preds = %79, %73
%76 = call i32 @opp_play(i32 %28, i8* %10)
%77 = call i32 @check_winner(i32 %28, i8* %11)
%78 = icmp eq i32 %77, 1
br i1 %78, label %85, label %79
79: ; preds = %75
%80 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%81 = call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%82 = call i32 @play(i32 %28, i8* %9, i8* %10)
%83 = call i32 @check_winner(i32 %28, i8* %11)
%84 = icmp eq i32 %83, 1
br i1 %84, label %85, label %75
85: ; preds = %75, %79, %63, %67
%86 = call i32 @putchar(i32 10)
%87 = call i32 @putchar(i32 10)
%88 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 7
%89 = call i32 @strcpy(i8* %14, i8* %88)
%90 = call i64 @strncmp(i8* %14, i8* %12, i32 1)
%91 = icmp eq i64 %90, 0
%92 = select i1 %91, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @str.18, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @str.17, i64 0, i64 0)
%93 = call i32 @puts(i8* dereferenceable(1) %92)
%94 = call i32 @putchar(i32 10)
%95 = call i32 @close(i32 %28)
ret i32 0
}