#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_family;
  int /*<<< orphan*/ sin_port;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ str2;
typedef int /*<<< orphan*/ str;
typedef int /*<<< orphan*/ cliaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ scanf(char *, char **);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int strcmp(char *, char *);
scalar_t__ write(int, char *, int);
int main(int count, char *arg[]) {
  int a, clisock;
  char str[20], str2[20];
  struct sockaddr_in cliaddr;
  cliaddr.sin_port = htons(1200);
  cliaddr.sin_family = AF_INET;
  cliaddr.sin_addr.s_addr = inet_addr(arg[1]);
  clisock = socket(AF_INET, SOCK_STREAM, 0);
  if (clisock < 0) {
    perror("\n SOCKET");
    exit(0);
  }
  if (connect(clisock, (struct sockaddr *)&cliaddr, sizeof(cliaddr)) < 0) {
    perror("\n CONNECT");
    exit(0);
  }
  printf("\nclient connected to %s", arg[1]);
  printf("\nCLIENT");
  scanf("%s", &str);
  if (write(clisock, str, sizeof(str)) < 0) {
    printf("\n data could not be sent");
  }
  do {
    listen(clisock, 1);
    read(clisock, str2, sizeof(str2));
    printf("\nserver msg:%s", str2);
    printf("\nclient msg:");
    scanf("%s", &str);
    a = strcmp(str2, "BYE");
    write(clisock, str2, sizeof(str2));
  } while (a != 0);
  close(clisock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x4b0,%edi
call   1040 <htons@plt>
mov    %eax,-0x58(%rbp)
mov    0x2dee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x60(%rbp)
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1248 <main+0x78>
lea    0xdc4(%rip),%rdi
call   10c0 <perror@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
cmp    $0x0,%rax
jge    1276 <main+0xa6>
lea    0xd9f(%rip),%rdi
call   10c0 <perror@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xd83(%rip),%rdi
call   10b0 <scanf@plt>
mov    -0x18(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x14,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    12d3 <main+0x103>
lea    0xd67(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12d8 <main+0x108>
mov    -0x18(%rbp),%edi
mov    $0x1,%esi
call   10a0 <listen@plt>
mov    -0x18(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x14,%edx
call   1070 <read@plt>
lea    -0x50(%rbp),%rsi
lea    0xd4b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd4c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xd07(%rip),%rdi
call   10b0 <scanf@plt>
lea    -0x50(%rbp),%rdi
lea    0xd37(%rip),%rsi
call   1090 <strcmp@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x14,%edx
call   1030 <write@plt>
cmpl   $0x0,-0x14(%rbp)
jne    12d8 <main+0x108>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r14
mov    $0x4b0,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
mov    0x2e02(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x4(%rsp)
mov    0x8(%r14),%rdi
call   1080 <inet_addr@plt>
mov    %eax,(%rsp)
mov    (%rbx),%edi
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
test   %eax,%eax
js     1316 <main+0x156>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   10d0 <connect@plt>
test   %rax,%rax
js     131f <main+0x15f>
mov    0x8(%r14),%rsi
lea    0xddc(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xde6(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdd5(%rip),%rdi
lea    0x30(%rsp),%rbp
mov    %rbp,%rsi
call   10a0 <scanf@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x14,%edx
call   1030 <write@plt>
test   %rax,%rax
jns    1282 <main+0xc2>
lea    0xdb8(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x10(%rsp),%r14
lea    0xdcd(%rip),%r12
lea    0xd93(%rip),%r13
lea    0x30(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    $0x1,%esi
call   1090 <listen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x14,%edx
call   1070 <read@plt>
lea    0xd8a(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   10a0 <scanf@plt>
mov    0x10(%rsp),%r15d
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x14,%edx
call   1030 <write@plt>
cmp    $0x455942,%r15d
jne    12a0 <main+0xe0>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xce3(%rip),%rdi
jmp    1326 <main+0x166>
lea    0xce3(%rip),%rdi
call   10b0 <perror@plt>
xor    %edi,%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 = [9 x i8] c"\0A SOCKET\00"
@.str.1 = [10 x i8] c"\0A CONNECT\00"
@.str.2 = [24 x i8] c"\0Aclient connected to %s\00"
@.str.3 = [8 x i8] c"\0ACLIENT\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [25 x i8] c"\0A data could not be sent\00"
@.str.6 = [15 x i8] c"\0Aserver msg:%s\00"
@.str.7 = [13 x i8] c"\0Aclient msg:\00"
@.str.8 = [4 x i8] c"BYE\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 [20 x i8]
%9 = alloca [20 x i8]
%10 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 @htons(i32 1200)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %11, i32* %12
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i32 %13, i32* %14
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @inet_addr(i8* %17)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
store i32 %18, i32* %20
%21 = load i32, i32* @AF_INET
%22 = load i32, i32* @SOCK_STREAM
%23 = call i32 @socket(i32 %21, i32 %22, i32 0)
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %2
%27 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%28 = call i32 @exit(i32 0)
unreachable
29: ; preds = %2
%30 = load i32, i32* %7
%31 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%32 = call i64 @connect(i32 %30, %struct.sockaddr* %31, i32 12)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 @exit(i32 0)
unreachable
37: ; preds = %29
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%43 = bitcast [20 x i8]* %8 to i8**
%44 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %43)
%45 = load i32, i32* %7
%46 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%47 = call i64 @write(i32 %45, i8* %46, i32 20)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %37
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
br label %51
51: ; preds = %49, %37
br label %52
52: ; preds = %68, %51
%53 = load i32, i32* %7
%54 = call i32 @listen(i32 %53, i32 1)
%55 = load i32, i32* %7
%56 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%57 = call i32 @read(i32 %55, i8* %56, i32 20)
%58 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%61 = bitcast [20 x i8]* %8 to i8**
%62 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %61)
%63 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%64 = call i32 @strcmp(i8* %63, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
store i32 %64, i32* %6
%65 = load i32, i32* %7
%66 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%67 = call i64 @write(i32 %65, i8* %66, i32 20)
br label %68
68: ; preds = %52
%69 = load i32, i32* %6
%70 = icmp ne i32 %69, 0
br i1 %70, label %52, label %71
71: ; preds = %68
%72 = load i32, i32* %7
%73 = call i32 @close(i32 %72)
ret i32 0
}

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 = [9 x i8] c"\0A SOCKET\00"
@.str.1 = [10 x i8] c"\0A CONNECT\00"
@.str.2 = [24 x i8] c"\0Aclient connected to %s\00"
@.str.3 = [8 x i8] c"\0ACLIENT\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [25 x i8] c"\0A data could not be sent\00"
@.str.6 = [15 x i8] c"\0Aserver msg:%s\00"
@.str.7 = [13 x i8] c"\0Aclient msg:\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [20 x i8]
%4 = alloca [20 x i8]
%5 = alloca %struct.sockaddr_in
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%8 = bitcast %struct.sockaddr_in* %5 to i8*
%9 = tail call i32 @htons(i32 1200)
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %9, i32* %10
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %11, i32* %12
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @inet_addr(i8* %14)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
store i32 %15, i32* %16
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = tail call i32 @socket(i32 %17, i32 %18, i32 0)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%23 = tail call i32 @exit(i32 0)
unreachable
24: ; preds = %2
%25 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%26 = call i64 @connect(i32 %19, %struct.sockaddr* %25, i32 12)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 0)
unreachable
31: ; preds = %24
%32 = load i8*, i8** %13
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%35 = bitcast [20 x i8]* %3 to i8**
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %35)
%37 = call i64 @write(i32 %19, i8* %6, i32 20)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %31
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
br label %41
41: ; preds = %39, %31
%42 = bitcast [20 x i8]* %4 to i32*
br label %43
43: ; preds = %43, %41
%44 = call i32 @listen(i32 %19, i32 1)
%45 = call i32 @read(i32 %19, i8* %7, i32 20)
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %7)
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%48 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %35)
%49 = load i32, i32* %42
%50 = icmp eq i32 %49, 4544834
%51 = call i64 @write(i32 %19, i8* %7, i32 20)
br i1 %50, label %52, label %43
52: ; preds = %43
%53 = call i32 @close(i32 %19)
ret i32 0
}