#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*/ dest;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EXIT_SUCCESS;
int /*<<< orphan*/ INADDR_LOOPBACK;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
int sendMessage(char *msg) {
  int len, mysocket;
  struct sockaddr_in dest;
  if ((mysocket = socket(AF_INET, SOCK_STREAM, 0)) < 0)
    return 6;
  memset(&dest, 0, sizeof(dest));
  dest.sin_family = AF_INET;
  dest.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  dest.sin_port = htons(31887);
  int r = connect(mysocket, (struct sockaddr *)&dest, sizeof(struct sockaddr));
  if (r < 0)
    return 7;
  if (write(mysocket, msg, strlen(msg)) < 0)
    return 8;
  close(mysocket);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<sendMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    11bd <sendMessage+0x3d>
movl   $0x6,-0x4(%rbp)
jmp    1270 <sendMessage+0xf0>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x24(%rbp)
mov    $0x7c8f,%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1090 <connect@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1221 <sendMessage+0xa1>
movl   $0x7,-0x4(%rbp)
jmp    1270 <sendMessage+0xf0>
mov    -0x18(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    125c <sendMessage+0xdc>
movl   $0x8,-0x4(%rbp)
jmp    1270 <sendMessage+0xf0>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
mov    0x2d5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendMessage>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r15
mov    0x2e54(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
test   %eax,%eax
js     1224 <sendMessage+0xa4>
mov    %eax,%ebp
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x10(%rsp)
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,0xc(%rsp)
mov    $0x7c8f,%edi
call   1050 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1090 <connect@plt>
test   %eax,%eax
js     122b <sendMessage+0xab>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %rax,%rax
js     1232 <sendMessage+0xb2>
mov    %ebp,%edi
call   1080 <close@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%eax
jmp    1237 <sendMessage+0xb7>
mov    $0x6,%eax
jmp    1237 <sendMessage+0xb7>
mov    $0x7,%eax
jmp    1237 <sendMessage+0xb7>
mov    $0x8,%eax
add    $0x18,%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 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_LOOPBACK = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @sendMessage(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %5
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 6, i32* %2
br label %41
13: ; preds = %1
%14 = call i32 @memset(%struct.sockaddr_in* %6, i32 0, i32 12)
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
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* %6, i32 0, i32 1
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
store i32 %18, i32* %20
%21 = call i32 @htons(i32 31887)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %21, i32* %22
%23 = load i32, i32* %5
%24 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%25 = call i32 @connect(i32 %23, %struct.sockaddr* %24, i32 4)
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %13
store i32 7, i32* %2
br label %41
29: ; preds = %13
%30 = load i32, i32* %5
%31 = load i8*, i8** %3
%32 = load i8*, i8** %3
%33 = call i32 @strlen(i8* %32)
%34 = call i64 @write(i32 %30, i8* %31, i32 %33)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %29
store i32 8, i32* %2
br label %41
37: ; preds = %29
%38 = load i32, i32* %5
%39 = call i32 @close(i32 %38)
%40 = load i32, i32* @EXIT_SUCCESS
store i32 %40, i32* %2
br label %41
41: ; preds = %37, %36, %28, %12
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_LOOPBACK = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @sendMessage(i8* %0) {
%2 = alloca %struct.sockaddr_in
%3 = bitcast %struct.sockaddr_in* %2 to i8*
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_STREAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %27, label %8
8: ; preds = %1
%9 = call i32 @memset(%struct.sockaddr_in* %2, i32 0, i32 12)
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %10, i32* %11
%12 = load i32, i32* @INADDR_LOOPBACK
%13 = call i32 @htonl(i32 %12)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
store i32 %13, i32* %14
%15 = call i32 @htons(i32 31887)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i32 %15, i32* %16
%17 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%18 = call i32 @connect(i32 %6, %struct.sockaddr* %17, i32 4)
%19 = icmp slt i32 %18, 0
br i1 %19, label %27, label %20
20: ; preds = %8
%21 = call i32 @strlen(i8* %0)
%22 = call i64 @write(i32 %6, i8* %0, i32 %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %20
%25 = call i32 @close(i32 %6)
%26 = load i32, i32* @EXIT_SUCCESS
br label %27
27: ; preds = %24, %8, %20, %1
%28 = phi i32 [ 6, %1 ], [ %26, %24 ], [ 7, %8 ], [ 8, %20 ]
ret i32 %28
}