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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ printf(char *, char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, int /*<<< orphan*/ *,
             int /*<<< orphan*/ *);
int /*<<< orphan*/ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  int sockfd, n;
  struct sockaddr_in servaddr;
  char banner[] = "Hello TCP server! This is TCP client";
  char buffer[1000];
  if (argc != 2) {
    printf("usage:  ./%s <IP address>\n", argv[0]);
    return -1;
  }
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = inet_addr(argv[1]);
  servaddr.sin_port = htons(32000);
  connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  sendto(sockfd, banner, strlen(banner), 0, (struct sockaddr *)&servaddr,
         sizeof(servaddr));
  n = recvfrom(sockfd, buffer, 10000, 0, NULL, NULL);
  buffer[n] = 0;
  printf("Received:%s\n", buffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe4c(%rip),%rsi
mov    $0x25,%edx
call   1080 <memcpy@plt>
cmpl   $0x2,-0x8(%rbp)
je     11e7 <main+0x57>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe4f(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c1 <main+0x131>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <inet_addr@plt>
mov    %eax,-0x24(%rbp)
mov    $0x7d00,%edi
call   1040 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x44c(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x448(%rbp)
lea    -0x50(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x44c(%rbp),%edi
mov    -0x448(%rbp),%rsi
mov    %eax,%edx
lea    -0x28(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
mov    -0x14(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    $0x2710,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   1090 <recvfrom@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
movb   $0x0,-0x440(%rbp,%rax,1)
lea    -0x440(%rbp),%rsi
lea    0xd8b(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x428,%rsp
mov    %rsi,%rbx
movaps 0xe79(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe5d(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movabs $0x746e65696c6320,%rax
mov    %rax,0x2d(%rsp)
cmp    $0x2,%edi
jne    126a <main+0xea>
mov    0x2e21(%rip),%r15
mov    (%r15),%edi
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
xor    %r14d,%r14d
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%ebp
mov    (%r15),%eax
mov    %eax,0x8(%rsp)
mov    0x8(%rbx),%rdi
call   1070 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0x7d00,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
mov    %rsp,%r15
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0xc,%r9d
call   1060 <sendto@plt>
lea    0x40(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x2710,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1080 <recvfrom@plt>
cltq
movb   $0x0,0x40(%rsp,%rax,1)
lea    0xde0(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
jmp    127f <main+0xff>
mov    (%rbx),%rsi
lea    0xdb1(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.banner = [37 x i8] c"Hello TCP server! This is TCP client\00"
@.str = [27 x i8] c"usage: ./%s <IP address>\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [13 x i8] c"Received:%s\0A\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 %struct.sockaddr_in
%9 = alloca [37 x i8]
%10 = alloca [1000 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [37 x i8]* %9 to i8*
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 -1, i32* %3
br label %50
19: ; preds = %2
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %6
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %23, i32* %24
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @inet_addr(i8* %27)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%30 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %29, i32 0, i32 0
store i32 %28, i32* %30
%31 = call i32 @htons(i32 32000)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %31, i32* %32
%33 = load i32, i32* %6
%34 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%35 = call i32 @connect(i32 %33, %struct.sockaddr* %34, i32 12)
%36 = load i32, i32* %6
%37 = getelementptr inbounds [37 x i8], [37 x i8]* %9, i64 0, i64 0
%38 = getelementptr inbounds [37 x i8], [37 x i8]* %9, i64 0, i64 0
%39 = call i32 @strlen(i8* %38)
%40 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%41 = call i32 @sendto(i32 %36, i8* %37, i32 %39, i32 0, %struct.sockaddr* %40, i32 12)
%42 = load i32, i32* %6
%43 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%44 = call i32 @recvfrom(i32 %42, i8* %43, i32 10000, i32 0, i32* null, i32* null)
store i32 %44, i32* %7
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 %46
store i8 0, i8* %47
%48 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%49 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %48)
store i32 0, i32* %3
br label %50
50: ; preds = %19, %14
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.banner = [37 x i8] c"Hello TCP server! This is TCP client\00"
@.str = [27 x i8] c"usage: ./%s <IP address>\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [13 x i8] c"Received:%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [37 x i8]
%5 = alloca [1000 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = getelementptr inbounds [37 x i8], [37 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%9 = icmp eq i32 %0, 2
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %33
13: ; preds = %2
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = tail call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %17, i32* %18
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = tail call i32 @inet_addr(i8* %20)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %21, i32* %22
%23 = tail call i32 @htons(i32 32000)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %23, i32* %24
%25 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%26 = call i32 @connect(i32 %16, %struct.sockaddr* %25, i32 12)
%27 = call i32 @strlen(i8* %7)
%28 = call i32 @sendto(i32 %16, i8* %7, i32 %27, i32 0, %struct.sockaddr* %25, i32 12)
%29 = call i32 @recvfrom(i32 %16, i8* %8, i32 10000, i32 0, i32* null, i32* null)
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 %30
store i8 0, i8* %31
%32 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %33
33: ; preds = %13, %10
%34 = phi i32 [ -1, %10 ], [ 0, %13 ]
ret i32 %34
}