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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ assert(int);
int atoi(char *);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char const *,
                             int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char const *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char const *);
int main(int argc, char **arg) {
  assert(argc > 3);
  const char *ip = arg[1];
  int port = atoi(arg[2]);
  const char *sendbuf = arg[3];
  int sockfd = socket(AF_INET, SOCK_STREAM, 0);
  assert(sockfd > 0);
  struct sockaddr_in addr;
  bzero(&addr, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_port = htons(port);
  inet_pton(AF_INET, ip, &addr.sin_addr);
  int ret = connect(sockfd, (struct sockaddr *)&addr, sizeof(addr));
  ret = send(sockfd, sendbuf, strlen(sendbuf), 0);
  printf("send:%d    %s \n", sockfd, sendbuf);
  char buff[1024];
  ret = recv(sockfd, buff, 1024, 0);
  buff[ret] = '\0';
  printf("recv:%s \n", buff);
  close(sockfd);
  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)
cmpl   $0x3,-0x8(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    0x2db6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
lea    -0x38(%rbp),%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x34(%rbp)
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   10a0 <inet_pton@plt>
mov    -0x2c(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x44c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x448(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x44c(%rbp),%edi
mov    -0x448(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%rdx
lea    0xd2e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x2c(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x3c(%rbp)
movslq -0x3c(%rbp),%rax
movb   $0x0,-0x440(%rbp,%rax,1)
lea    -0x440(%rbp),%rsi
lea    0xd04(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x2c(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%rbx
xor    %eax,%eax
cmp    $0x4,%edi
setge  %al
mov    %eax,%edi
call   1090 <assert@plt>
mov    0x8(%rbx),%r15
mov    0x10(%rbx),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r12d
mov    0x18(%rbx),%r14
mov    0x2dea(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2dcf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebx
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1090 <assert@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    0x0(%r13),%eax
mov    %eax,0x8(%rsp)
mov    %r12d,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x0(%r13),%edi
mov    %r15,%rsi
mov    %rbp,%rdx
call   10a0 <inet_pton@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
lea    0xd80(%rip),%rdi
mov    %ebx,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x10(%rsp),%rbp
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cltq
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xd60(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebx,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [16 x i8] c"send:%d %s \0A\00"
@.str.1 = [10 x i8] c"recv:%s \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
%12 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 3
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %6
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %7
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 3
%26 = load i8*, i8** %25
store i8* %26, i8** %8
%27 = load i32, i32* @AF_INET
%28 = load i32, i32* @SOCK_STREAM
%29 = call i32 @socket(i32 %27, i32 %28, i32 0)
store i32 %29, i32* %9
%30 = load i32, i32* %9
%31 = icmp sgt i32 %30, 0
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = call i32 @bzero(%struct.sockaddr_in* %10, i32 12)
%35 = load i32, i32* @AF_INET
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %35, i32* %36
%37 = load i32, i32* %7
%38 = call i32 @htons(i32 %37)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i32 %38, i32* %39
%40 = load i32, i32* @AF_INET
%41 = load i8*, i8** %6
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%43 = call i32 @inet_pton(i32 %40, i8* %41, i32* %42)
%44 = load i32, i32* %9
%45 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%46 = call i32 @connect(i32 %44, %struct.sockaddr* %45, i32 12)
store i32 %46, i32* %11
%47 = load i32, i32* %9
%48 = load i8*, i8** %8
%49 = load i8*, i8** %8
%50 = call i32 @strlen(i8* %49)
%51 = call i32 @send(i32 %47, i8* %48, i32 %50, i32 0)
store i32 %51, i32* %11
%52 = load i32, i32* %9
%53 = load i8*, i8** %8
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %52, i8* %53)
%55 = load i32, i32* %9
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%57 = call i32 @recv(i32 %55, i8* %56, i32 1024, i32 0)
store i32 %57, i32* %11
%58 = load i32, i32* %11
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 %59
store i8 0, i8* %60
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %61)
%63 = load i32, i32* %9
%64 = call i32 @close(i32 %63)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [16 x i8] c"send:%d %s \0A\00"
@.str.1 = [10 x i8] c"recv:%s \0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1024 x i8]
%5 = icmp sgt i32 %0, 3
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 3
%14 = load i8*, i8** %13
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = tail call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp sgt i32 %17, 0
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = bitcast %struct.sockaddr_in* %3 to i8*
%22 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %23, i32* %24
%25 = tail call i32 @htons(i32 %12)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %25, i32* %26
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%29 = call i32 @inet_pton(i32 %27, i8* %9, i32* %28)
%30 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%31 = call i32 @connect(i32 %17, %struct.sockaddr* %30, i32 12)
%32 = call i32 @strlen(i8* %14)
%33 = call i32 @send(i32 %17, i8* %14, i32 %32, i32 0)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %17, i8* %14)
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%36 = call i32 @recv(i32 %17, i8* %35, i32 1024, i32 0)
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %37
store i8 0, i8* %38
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%40 = call i32 @close(i32 %17)
ret i32 0
}