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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ send(int, char const *, size_t, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
void notify(const char *msg, size_t len) {
  int sock = socket(AF_INET, SOCK_STREAM, 0);
  if (sock < 0) {
    return;
  }
  struct sockaddr_in serv_addr;
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons(9001);
  inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr);
  if (!connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr))) {
    send(sock, msg, len, 0);
  }
  close(sock);
}


x86 assembly (clang, -O0):
<notify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    119b <notify+0x3b>
jmp    1201 <notify+0xa1>
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x2329,%edi
call   1030 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rdx
lea    0xe38(%rip),%rsi
call   1060 <inet_pton@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1070 <connect@plt>
cmp    $0x0,%eax
jne    11f9 <notify+0x99>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<notify>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e71(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
test   %eax,%eax
js     11e2 <notify+0x82>
mov    %eax,%ebp
mov    (%rbx),%eax
mov    %eax,0x10(%rsp)
mov    $0x2329,%edi
call   1030 <htons@plt>
mov    %eax,0xc(%rsp)
mov    (%rbx),%edi
lea    0xe54(%rip),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdx
call   1060 <inet_pton@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1070 <connect@plt>
test   %eax,%eax
jne    11db <notify+0x7b>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %ebp,%edi
call   1050 <close@plt>
add    $0x18,%rsp
pop    %rbx
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 = [10 x i8] c"127.0.0.1\00"
define void @notify(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
br label %33
13: ; preds = %2
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %14, i32* %15
%16 = call i32 @htons(i32 9001)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %16, i32* %17
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%20 = call i32 @inet_pton(i32 %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %19)
%21 = load i32, i32* %5
%22 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%23 = call i32 @connect(i32 %21, %struct.sockaddr* %22, i32 12)
%24 = icmp ne i32 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %13
%26 = load i32, i32* %5
%27 = load i8*, i8** %3
%28 = load i64, i64* %4
%29 = call i32 @send(i32 %26, i8* %27, i64 %28, i32 0)
br label %30
30: ; preds = %25, %13
%31 = load i32, i32* %5
%32 = call i32 @close(i32 %31)
br label %33
33: ; preds = %30, %12
ret void
}

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 = [10 x i8] c"127.0.0.1\00"
define void @notify(i8* %0, i64 %1) {
%3 = alloca %struct.sockaddr_in
%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 %24, label %8
8: ; preds = %2
%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 9001)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %12, i32* %13
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%16 = call i32 @inet_pton(i32 %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %15)
%17 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%18 = call i32 @connect(i32 %6, %struct.sockaddr* %17, i32 12)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %8
%21 = call i32 @send(i32 %6, i8* %0, i64 %1, i32 0)
br label %22
22: ; preds = %20, %8
%23 = call i32 @close(i32 %6)
br label %24
24: ; preds = %2, %22
ret void
}