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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
scalar_t__ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, char *);
scalar_t__ send(int, char *, scalar_t__, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strlen(char *);
int loop(void) {
  int sock;
  struct sockaddr_in server;
  char message[1000], server_reply[2000];
  printf("Press any key to continue...");
  getchar();
  printf("\n");
  sock = socket(AF_INET, SOCK_STREAM, 0);
  if (sock == -1) {
    perror("socket creation failed");
    return 1;
  }
  puts("Socket created\n");
  server.sin_addr.s_addr = inet_addr("192.168.1.173");
  server.sin_family = AF_INET;
  server.sin_port = htons(8888);
  if (connect(sock, (struct sockaddr *)&server, sizeof(server)) < 0) {
    perror("connect failed");
    close(sock);
    return 1;
  }
  puts("Connected\n");
  while (1) {
    printf("Enter message : ");
    scanf("%s", message);
    if (send(sock, message, strlen(message) + 1, 0) < 0) {
      perror("Send failed");
      close(sock);
      return 1;
    }
    if (recv(sock, server_reply, 2000, 0) < 0) {
      perror("recv failed");
      break;
    }
    puts("Server reply :");
    puts(server_reply);
  }
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0xbe0,%rsp
lea    0xe1e(%rip),%rdi
call   1080 <printf@plt>
mov    $0x0,%al
call   10b0 <getchar@plt>
lea    0xe4d(%rip),%rdi
call   1080 <printf@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1238 <loop+0x68>
lea    0xdf6(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1397 <loop+0x1c7>
lea    0xdf5(%rip),%rdi
call   1040 <puts@plt>
lea    0xdf9(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x10(%rbp)
mov    0x2d8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    $0x22b8,%edi
call   1060 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
cmp    $0x0,%rax
jge    12a7 <loop+0xd7>
lea    0xdc4(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1397 <loop+0x1c7>
lea    0xdb3(%rip),%rdi
call   1040 <puts@plt>
lea    0xdb2(%rip),%rdi
call   1080 <printf@plt>
lea    -0x400(%rbp),%rsi
lea    0xdb0(%rip),%rdi
call   10c0 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0xbdc(%rbp)
lea    -0x400(%rbp),%rax
mov    %rax,-0xbd8(%rbp)
lea    -0x400(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xbdc(%rbp),%edi
mov    -0xbd8(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    $0x0,%rax
jge    133a <loop+0x16a>
lea    0xd5f(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1397 <loop+0x1c7>
mov    -0x8(%rbp),%edi
lea    -0xbd0(%rbp),%rsi
mov    $0x7d0,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x0,%rax
jge    136b <loop+0x19b>
lea    0xd2b(%rip),%rdi
call   10d0 <perror@plt>
jmp    1388 <loop+0x1b8>
lea    0xd26(%rip),%rdi
call   1040 <puts@plt>
lea    -0xbd0(%rbp),%rdi
call   1040 <puts@plt>
jmp    12b3 <loop+0xe3>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xbe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loop>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xbd8,%rsp
lea    0xe08(%rip),%rdi
call   1090 <printf@plt>
xor    %eax,%eax
call   10c0 <getchar@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    0x2dd3(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dba(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
cmp    $0xffffffff,%eax
jne    123d <loop+0x5d>
lea    0xdea(%rip),%rdi
call   10e0 <perror@plt>
jmp    136c <loop+0x18c>
mov    %eax,%r13d
lea    0xded(%rip),%rdi
call   1050 <puts@plt>
lea    0xdf1(%rip),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,0x8(%rsp)
mov    (%rbx),%eax
mov    %eax,0x4(%rsp)
mov    $0x22b8,%edi
call   1070 <htons@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %r13d,%edi
mov    $0xc,%edx
call   10f0 <connect@plt>
test   %rax,%rax
jns    1290 <loop+0xb0>
lea    0xdc7(%rip),%rdi
jmp    135f <loop+0x17f>
lea    0xdca(%rip),%rdi
call   1050 <puts@plt>
lea    0xdc9(%rip),%rdi
call   1090 <printf@plt>
lea    0xdce(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   10d0 <scanf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r13d,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1080 <send@plt>
test   %rax,%rax
js     1358 <loop+0x178>
lea    0x400(%rsp),%rbx
lea    0xdab(%rip),%r14
lea    0xd78(%rip),%r15
lea    0xd82(%rip),%r12
lea    0x10(%rsp),%rbp
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x7d0,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
js     1383 <loop+0x1a3>
mov    %r14,%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
mov    %r15,%rdi
call   1090 <printf@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
call   10d0 <scanf@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r13d,%edi
mov    %rbp,%rsi
xor    %ecx,%ecx
call   1080 <send@plt>
test   %rax,%rax
jns    1300 <loop+0x120>
lea    0xd21(%rip),%rdi
call   10e0 <perror@plt>
mov    %r13d,%edi
call   10a0 <close@plt>
mov    $0x1,%eax
add    $0xbd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd02(%rip),%rdi
call   10e0 <perror@plt>
mov    %r13d,%edi
call   10a0 <close@plt>
xor    %eax,%eax
jmp    1371 <loop+0x191>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [29 x i8] c"Press any key to continue...\00"
@.str.1 = [2 x i8] c"\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [23 x i8] c"socket creation failed\00"
@.str.3 = [16 x i8] c"Socket created\0A\00"
@.str.4 = [14 x i8] c"192.168.1.173\00"
@.str.5 = [15 x i8] c"connect failed\00"
@.str.6 = [11 x i8] c"Connected\0A\00"
@.str.7 = [17 x i8] c"Enter message : \00"
@.str.8 = [3 x i8] c"%s\00"
@.str.9 = [12 x i8] c"Send failed\00"
@.str.10 = [12 x i8] c"recv failed\00"
@.str.11 = [15 x i8] c"Server reply :\00"
define i32 @loop() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca [1000 x i8]
%5 = alloca [2000 x i8]
%6 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (...) @getchar()
%8 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %64
16: ; preds = %0
%17 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
%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 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %21, i32* %22
%23 = call i32 @htons(i32 8888)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %23, i32* %24
%25 = load i32, i32* %2
%26 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%27 = call i64 @connect(i32 %25, %struct.sockaddr* %26, i32 12)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %16
%30 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%31 = load i32, i32* %2
%32 = call i32 @close(i32 %31)
store i32 1, i32* %1
br label %64
33: ; preds = %16
%34 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
br label %35
35: ; preds = %33, %57
%36 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%37 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%38 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %37)
%39 = load i32, i32* %2
%40 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%41 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%42 = call i64 @strlen(i8* %41)
%43 = add nsw i64 %42, 1
%44 = call i64 @send(i32 %39, i8* %40, i64 %43, i32 0)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %35
%47 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0))
%48 = load i32, i32* %2
%49 = call i32 @close(i32 %48)
store i32 1, i32* %1
br label %64
50: ; preds = %35
%51 = load i32, i32* %2
%52 = getelementptr inbounds [2000 x i8], [2000 x i8]* %5, i64 0, i64 0
%53 = call i64 @recv(i32 %51, i8* %52, i32 2000, i32 0)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %50
%56 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
br label %61
57: ; preds = %50
%58 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
%59 = getelementptr inbounds [2000 x i8], [2000 x i8]* %5, i64 0, i64 0
%60 = call i32 @puts(i8* %59)
br label %35
61: ; preds = %55
%62 = load i32, i32* %2
%63 = call i32 @close(i32 %62)
store i32 0, i32* %1
br label %64
64: ; preds = %61, %46, %29, %14
%65 = load i32, i32* %1
ret i32 %65
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [29 x i8] c"Press any key to continue...\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [23 x i8] c"socket creation failed\00"
@.str.3 = [16 x i8] c"Socket created\0A\00"
@.str.4 = [14 x i8] c"192.168.1.173\00"
@.str.5 = [15 x i8] c"connect failed\00"
@.str.6 = [11 x i8] c"Connected\0A\00"
@.str.7 = [17 x i8] c"Enter message : \00"
@.str.8 = [3 x i8] c"%s\00"
@.str.9 = [12 x i8] c"Send failed\00"
@.str.10 = [12 x i8] c"recv failed\00"
@.str.11 = [15 x i8] c"Server reply :\00"
define i32 @loop() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [1000 x i8]
%3 = alloca [2000 x i8]
%4 = bitcast %struct.sockaddr_in* %1 to i8*
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [2000 x i8], [2000 x i8]* %3, i64 0, i64 0
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 (...) @getchar()
%9 = tail call i32 @putchar(i32 10)
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %56
16: ; preds = %0
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%18 = tail call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2, i32 0
store i32 %18, i32* %19
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %20, i32* %21
%22 = tail call i32 @htons(i32 8888)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %22, i32* %23
%24 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%25 = call i64 @connect(i32 %12, %struct.sockaddr* %24, i32 12)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %16
%28 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%29 = call i32 @close(i32 %12)
br label %56
30: ; preds = %16
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%32 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%33 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %5)
%34 = call i64 @strlen(i8* %5)
%35 = add nsw i64 %34, 1
%36 = call i64 @send(i32 %12, i8* %5, i64 %35, i32 0)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %47, %30
%39 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0))
%40 = call i32 @close(i32 %12)
br label %56
41: ; preds = %30, %47
%42 = call i64 @recv(i32 %12, i8* %6, i32 2000, i32 0)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
%46 = call i32 @close(i32 %12)
br label %56
47: ; preds = %41
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
%49 = call i32 @puts(i8* %6)
%50 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%51 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %5)
%52 = call i64 @strlen(i8* %5)
%53 = add nsw i64 %52, 1
%54 = call i64 @send(i32 %12, i8* %5, i64 %53, i32 0)
%55 = icmp slt i64 %54, 0
br i1 %55, label %38, label %41
56: ; preds = %44, %38, %27, %14
%57 = phi i32 [ 1, %14 ], [ 1, %27 ], [ 1, %38 ], [ 0, %44 ]
ret i32 %57
}