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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, scalar_t__, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strlen(char *);
int main(int argc, char *argv[]) {
  int socket_fd;
  struct sockaddr_in dest;
  char buffer[1024];
  int ret_val = 0;
  socket_fd = socket(AF_INET, SOCK_STREAM, 0);
  if (socket_fd < 0) {
    perror("socket");
    exit(errno);
  }
  memset(&dest, 0, sizeof(dest));
  dest.sin_family = AF_INET;
  dest.sin_port = htons(60000);
  ret_val = inet_aton(argv[1], &dest.sin_addr.s_addr);
  if (ret_val == 0) {
    perror(argv[1]);
    return errno;
  }
  ret_val = connect(socket_fd, (struct sockaddr *)&dest, sizeof(dest));
  if (ret_val != 0) {
    perror("connect");
    return errno;
  }
  ret_val = send(socket_fd, argv[2], strlen(argv[2]) + 1, 0);
  printf("send %d bytes\n", ret_val);
  ret_val = recv(socket_fd, buffer, 1024, 0);
  printf("recv %d bytes : %s\n", ret_val, buffer);
  close(socket_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x424(%rbp)
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1223 <main+0x63>
lea    0xdf0(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0xea60,%edi
call   1050 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
call   10a0 <inet_aton@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0x0,-0x424(%rbp)
jne    128e <main+0xce>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <perror@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    136f <main+0x1af>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0x0,-0x424(%rbp)
je     12cf <main+0x10f>
lea    0xd4e(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    136f <main+0x1af>
mov    -0x14(%rbp),%eax
mov    %eax,-0x434(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x430(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <strlen@plt>
mov    -0x434(%rbp),%edi
mov    -0x430(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x424(%rbp)
mov    -0x424(%rbp),%esi
lea    0xced(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x424(%rbp)
mov    -0x424(%rbp),%esi
lea    -0x420(%rbp),%rdx
lea    0xcc5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%r14
mov    0x2e11(%rip),%r15
mov    (%r15),%edi
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
test   %eax,%eax
js     12d0 <main+0x110>
mov    %eax,%ebx
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x8(%rsp)
mov    $0xea60,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x8(%r14),%rdi
mov    %rbp,%rsi
call   10a0 <inet_aton@plt>
test   %eax,%eax
je     12b2 <main+0xf2>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10d0 <connect@plt>
test   %eax,%eax
jne    12b8 <main+0xf8>
mov    0x10(%r14),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
xor    %r14d,%r14d
mov    %ebx,%edi
mov    %rbp,%rsi
xor    %ecx,%ecx
call   1060 <send@plt>
lea    0xda7(%rip),%rdi
mov    %eax,%esi
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>
lea    0xd90(%rip),%rdi
mov    %eax,%esi
mov    %rbp,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebx,%edi
call   1090 <close@plt>
mov    %r14d,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%r14),%rdi
jmp    12bf <main+0xff>
lea    0xd48(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d05(%rip),%rax
mov    (%rax),%r14d
jmp    12a1 <main+0xe1>
lea    0xd29(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2ced(%rip),%rax
mov    (%rax),%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 = [7 x i8] c"socket\00"
@errno = global i32 0
@.str.1 = [8 x i8] c"connect\00"
@.str.2 = [15 x i8] c"send %d bytes\0A\00"
@.str.3 = [20 x i8] c"recv %d bytes : %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca [1024 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @errno
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %21, i32* %22
%23 = call i32 @htons(i32 60000)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %23, i32* %24
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i32 0, i32 0
%30 = call i32 @inet_aton(i8* %27, i32* %29)
store i32 %30, i32* %9
%31 = load i32, i32* %9
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %19
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @perror(i8* %36)
%38 = load i32, i32* @errno
store i32 %38, i32* %3
br label %69
39: ; preds = %19
%40 = load i32, i32* %6
%41 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%42 = call i32 @connect(i32 %40, %struct.sockaddr* %41, i32 12)
store i32 %42, i32* %9
%43 = load i32, i32* %9
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %39
%46 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%47 = load i32, i32* @errno
store i32 %47, i32* %3
br label %69
48: ; preds = %39
%49 = load i32, i32* %6
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 2
%52 = load i8*, i8** %51
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 2
%55 = load i8*, i8** %54
%56 = call i64 @strlen(i8* %55)
%57 = add nsw i64 %56, 1
%58 = call i32 @send(i32 %49, i8* %52, i64 %57, i32 0)
store i32 %58, i32* %9
%59 = load i32, i32* %9
%60 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %59)
%61 = load i32, i32* %6
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%63 = call i32 @recv(i32 %61, i8* %62, i32 1024, i32 0)
store i32 %63, i32* %9
%64 = load i32, i32* %9
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%66 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %64, i8* %65)
%67 = load i32, i32* %6
%68 = call i32 @close(i32 %67)
store i32 0, i32* %3
br label %69
69: ; preds = %48, %45, %33
%70 = load i32, i32* %3
ret i32 %70
}

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 = [7 x i8] c"socket\00"
@errno = global i32 0
@.str.1 = [8 x i8] c"connect\00"
@.str.2 = [15 x i8] c"send %d bytes\0A\00"
@.str.3 = [20 x i8] c"recv %d bytes : %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1024 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @errno
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%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 = call i32 @htons(i32 60000)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %19, i32* %20
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
%24 = call i32 @inet_aton(i8* %22, i32* %23)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %15
%27 = load i8*, i8** %21
%28 = call i32 @perror(i8* %27)
%29 = load i32, i32* @errno
br label %47
30: ; preds = %15
%31 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%32 = call i32 @connect(i32 %9, %struct.sockaddr* %31, i32 12)
%33 = icmp eq i32 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %30
%35 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%36 = load i32, i32* @errno
br label %47
37: ; preds = %30
%38 = getelementptr inbounds i8*, i8** %1, i64 2
%39 = load i8*, i8** %38
%40 = call i64 @strlen(i8* dereferenceable(1) %39)
%41 = add nsw i64 %40, 1
%42 = call i32 @send(i32 %9, i8* %39, i64 %41, i32 0)
%43 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = call i32 @recv(i32 %9, i8* %6, i32 1024, i32 0)
%45 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %44, i8* %6)
%46 = call i32 @close(i32 %9)
br label %47
47: ; preds = %37, %34, %26
%48 = phi i32 [ %29, %26 ], [ %36, %34 ], [ 0, %37 ]
ret i32 %48
}