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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ atoi(char *);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int server_fd;
  static char buf_send[4096], buf_recv[4096];
  int nsend, nrecv;
  struct sockaddr_in remote_addr;
  remote_addr.sin_family = AF_INET;
  remote_addr.sin_addr.s_addr = inet_addr(argv[1]);
  remote_addr.sin_port = htons(atoi(argv[2]));
  memset(&remote_addr.sin_zero, 0, sizeof(remote_addr.sin_zero));
  if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("socket");
    return -1;
  }
  if (connect(server_fd, (struct sockaddr *)&remote_addr,
              sizeof(struct sockaddr)) < 0) {
    perror("connect");
    return -1;
  }
  snprintf(buf_send, 4096, "hello");
  nsend = send(server_fd, buf_send, strlen(buf_send), 0);
  if (nsend == -1) {
    perror("send");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,-0x2c(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    0x2dcf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1236 <main+0x96>
lea    0xddb(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c6 <main+0x126>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x4,%edx
call   10b0 <connect@plt>
cmp    $0x0,%rax
jge    1269 <main+0xc9>
lea    0xdaf(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c6 <main+0x126>
lea    0x2e10(%rip),%rdi
mov    $0x1000,%esi
lea    0xd93(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
lea    0x2df2(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    %eax,%edx
lea    0x2de1(%rip),%rsi
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    12bf <main+0x11f>
lea    0xd5b(%rip),%rdi
call   1090 <perror@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    0x2e36(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsi),%rdi
call   1080 <inet_addr@plt>
mov    %eax,0x8(%rsp)
mov    0x10(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
mov    0x0(%rbp),%edi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
js     1261 <main+0xc1>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   10b0 <connect@plt>
test   %rax,%rax
js     126a <main+0xca>
lea    0x2e5d(%rip),%rbx
lea    0xde5(%rip),%rdx
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1060 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
xor    %r14d,%r14d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
cmp    $0xffffffff,%eax
je     1273 <main+0xd3>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd98(%rip),%rdi
jmp    127a <main+0xda>
lea    0xd96(%rip),%rdi
jmp    127a <main+0xda>
lea    0xd9b(%rip),%rdi
call   1090 <perror@plt>
jmp    1255 <main+0xb5>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@main.buf_send = internal global [4096 x i8] zeroinitializer
@main.buf_recv = internal global [4096 x i8] zeroinitializer
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [8 x i8] c"connect\00"
@.str.2 = [6 x i8] c"hello\00"
@.str.3 = [5 x i8] c"send\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 i32
%9 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 3
store i32 %10, i32* %11
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @inet_addr(i8* %14)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
%17 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %16, i32 0, i32 0
store i32 %15, i32* %17
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
%22 = call i32 @htons(i32 %21)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %22, i32* %23
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%25 = call i32 @memset(i32* %24, i32 0, i32 4)
%26 = load i32, i32* @AF_INET
%27 = load i32, i32* @SOCK_STREAM
%28 = call i32 @socket(i32 %26, i32 %27, i32 0)
store i32 %28, i32* %6
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %2
%31 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %49
32: ; preds = %2
%33 = load i32, i32* %6
%34 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%35 = call i64 @connect(i32 %33, %struct.sockaddr* %34, i32 4)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %49
39: ; preds = %32
%40 = call i32 @snprintf(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.buf_send, i64 0, i64 0), i32 4096, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%41 = load i32, i32* %6
%42 = call i32 @strlen(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.buf_send, i64 0, i64 0))
%43 = call i32 @send(i32 %41, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.buf_send, i64 0, i64 0), i32 %42, i32 0)
store i32 %43, i32* %7
%44 = load i32, i32* %7
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %48
46: ; preds = %39
%47 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %48
48: ; preds = %46, %39
store i32 0, i32* %3
br label %49
49: ; preds = %48, %37, %30
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@main.buf_send = internal global [4096 x i8] zeroinitializer
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [8 x i8] c"connect\00"
@.str.2 = [6 x i8] c"hello\00"
@.str.3 = [5 x i8] c"send\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = load i32, i32* @AF_INET
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 3
store i32 %5, i32* %6
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @inet_addr(i8* %8)
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2, i32 0
store i32 %9, i32* %10
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = tail call i32 @htons(i32 %13)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%17 = call i32 @memset(i32* %16, i32 0, i32 4)
%18 = load i32, i32* @AF_INET
%19 = load i32, i32* @SOCK_STREAM
%20 = call i32 @socket(i32 %18, i32 %19, i32 0)
%21 = icmp slt i32 %20, 0
br i1 %21, label %31, label %22
22: ; preds = %2
%23 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%24 = call i64 @connect(i32 %20, %struct.sockaddr* %23, i32 4)
%25 = icmp slt i64 %24, 0
br i1 %25, label %31, label %26
26: ; preds = %22
%27 = call i32 @snprintf(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.buf_send, i64 0, i64 0), i32 4096, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @strlen(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.buf_send, i64 0, i64 0))
%29 = call i32 @send(i32 %20, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.buf_send, i64 0, i64 0), i32 %28, i32 0)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %35
31: ; preds = %26, %22, %2
%32 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %22 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %26 ]
%33 = phi i32 [ -1, %2 ], [ -1, %22 ], [ 0, %26 ]
%34 = call i32 @perror(i8* %32)
br label %35
35: ; preds = %31, %26
%36 = phi i32 [ 0, %26 ], [ %33, %31 ]
ret i32 %36
}