#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*/ sockAddr;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_LOOPBACK;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ MSG_NOSIGNAL;
int /*<<< orphan*/ SHUT_RDWR;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  struct sockaddr_in sockAddr;
  sockAddr.sin_family = AF_INET;
  sockAddr.sin_port = htons(12345);
  sockAddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  connect(sock, (struct sockaddr *)&sockAddr, sizeof(sockAddr));
  char buffer[] = "PING";
  send(sock, buffer, sizeof(buffer) - 1, MSG_NOSIGNAL);
  recv(sock, buffer, sizeof(buffer) - 1, MSG_NOSIGNAL);
  shutdown(sock, SHUT_RDWR);
  close(sock);
  printf("%s\n", buffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
mov    0x2e19(%rip),%rax
mov    (%rax),%edx
call   10b0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x3039,%edi
call   1050 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
mov    0xdf6(%rip),%eax
mov    %eax,-0x25(%rbp)
mov    0xdf1(%rip),%al
mov    %al,-0x21(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x25(%rbp),%rsi
mov    0x2d94(%rip),%rax
mov    (%rax),%ecx
mov    $0x4,%edx
call   1060 <send@plt>
mov    -0x14(%rbp),%edi
lea    -0x25(%rbp),%rsi
mov    0x2d7a(%rip),%rax
mov    (%rax),%ecx
mov    $0x4,%edx
call   1030 <recv@plt>
mov    -0x14(%rbp),%edi
mov    0x2d9c(%rip),%rax
mov    (%rax),%esi
call   1040 <shutdown@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
lea    -0x25(%rbp),%rsi
lea    0xd97(%rip),%rdi
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2e40(%rip),%r14
mov    (%r14),%edi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
mov    0x2e25(%rip),%rax
mov    (%rax),%edx
call   10b0 <socket@plt>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    $0x3039,%edi
call   1050 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10a0 <connect@plt>
movb   $0x0,0xc(%rsp)
movl   $0x474e4950,0x8(%rsp)
mov    0x2db0(%rip),%r15
mov    (%r15),%ecx
lea    0x8(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1060 <send@plt>
mov    (%r15),%ecx
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <recv@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <shutdown@plt>
mov    %ebx,%edi
call   1090 <close@plt>
lea    0xdb6(%rip),%rdi
mov    %r14,%rsi
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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
@IPPROTO_TCP = global i32 0
@INADDR_LOOPBACK = global i32 0
@__const.main.buffer = [5 x i8] c"PING\00"
@MSG_NOSIGNAL = global i32 0
@SHUT_RDWR = global i32 0
@.str = [4 x i8] c"%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 [5 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = load i32, i32* @IPPROTO_TCP
%12 = call i32 @socket(i32 %9, i32 %10, i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %13, i32* %14
%15 = call i32 @htons(i32 12345)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %15, i32* %16
%17 = load i32, i32* @INADDR_LOOPBACK
%18 = call i32 @htonl(i32 %17)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
store i32 %18, i32* %20
%21 = load i32, i32* %6
%22 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%23 = call i32 @connect(i32 %21, %struct.sockaddr* %22, i32 12)
%24 = bitcast [5 x i8]* %8 to i8*
%25 = load i32, i32* %6
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%27 = load i32, i32* @MSG_NOSIGNAL
%28 = call i32 @send(i32 %25, i8* %26, i32 4, i32 %27)
%29 = load i32, i32* %6
%30 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%31 = load i32, i32* @MSG_NOSIGNAL
%32 = call i32 @recv(i32 %29, i8* %30, i32 4, i32 %31)
%33 = load i32, i32* %6
%34 = load i32, i32* @SHUT_RDWR
%35 = call i32 @shutdown(i32 %33, i32 %34)
%36 = load i32, i32* %6
%37 = call i32 @close(i32 %36)
%38 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%39 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %38)
ret i32 0
}

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
@IPPROTO_TCP = global i32 0
@INADDR_LOOPBACK = global i32 0
@__const.main.buffer = [5 x i8] c"PING\00"
@MSG_NOSIGNAL = global i32 0
@SHUT_RDWR = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [5 x i8]
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = load i32, i32* @IPPROTO_TCP
%8 = tail call i32 @socket(i32 %5, i32 %6, i32 %7)
%9 = bitcast %struct.sockaddr_in* %3 to i8*
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %10, i32* %11
%12 = tail call i32 @htons(i32 12345)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %12, i32* %13
%14 = load i32, i32* @INADDR_LOOPBACK
%15 = tail call i32 @htonl(i32 %14)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %15, i32* %16
%17 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%18 = call i32 @connect(i32 %8, %struct.sockaddr* %17, i32 12)
%19 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%20 = load i32, i32* @MSG_NOSIGNAL
%21 = call i32 @send(i32 %8, i8* %19, i32 4, i32 %20)
%22 = load i32, i32* @MSG_NOSIGNAL
%23 = call i32 @recv(i32 %8, i8* %19, i32 4, i32 %22)
%24 = load i32, i32* @SHUT_RDWR
%25 = call i32 @shutdown(i32 %8, i32 %24)
%26 = call i32 @close(i32 %8)
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %19)
ret i32 0
}