#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 {
  void *sin_port;
  TYPE_1__ sin_addr;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};
typedef int /*<<< orphan*/ server;

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bcopy(int /*<<< orphan*/, char *, int /*<<< orphan*/);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct hostent *gethostbyname(char *);
void *htons(int);
int /*<<< orphan*/ perror(char *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void sentom(char *data, char *monitor_ip) {
  struct sockaddr_in client, server;
  struct hostent *hp;
  char buf[256];
  int len, ret, n;
  int s, new_s;
  bzero((char *)&server, sizeof(server));
  server.sin_family = AF_INET;
  server.sin_addr.s_addr = INADDR_ANY;
  server.sin_port = htons(0);
  s = socket(AF_INET, SOCK_DGRAM, 0);
  if (s < 0) {
    perror("simplex-talk: UDP_socket error");
    exit(1);
  }
  if ((bind(s, (struct sockaddr *)&server, sizeof(server))) < 0) {
    perror("simplex-talk: UDP_bind error");
    exit(1);
  }
  hp = gethostbyname(monitor_ip);
  if (!hp) {
    fprintf(stderr, "Unknown host %s\n", "localhost");
    exit(1);
  }
  bzero((char *)&server, sizeof(server));
  server.sin_family = AF_INET;
  bcopy(hp->h_addr, (char *)&server.sin_addr, hp->h_length);
  server.sin_port = htons(23456);
  ret = sendto(s, data, 256, 0, (struct sockaddr *)&server, sizeof(server));
  if (ret <= 0) {
    fprintf(stderr, "Datagram Send error %d\n", ret);
  }
}


x86 assembly (clang, -O0):
<sentom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0x18,%esi
call   10a0 <bzero@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
xor    %edi,%edi
call   1030 <htons@plt>
mov    %rax,-0x40(%rbp)
mov    0x2dfb(%rip),%rax
mov    (%rax),%rdi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x160(%rbp)
cmpl   $0x0,-0x160(%rbp)
jge    1229 <sentom+0x89>
lea    0xde6(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x160(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x18,%edx
call   1080 <bind@plt>
cmp    $0x0,%rax
jge    125d <sentom+0xbd>
lea    0xdd1(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    129d <sentom+0xfd>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
lea    0xdb7(%rip),%rsi
lea    0xdc1(%rip),%rdx
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x40(%rbp),%rdi
mov    $0x18,%esi
call   10a0 <bzero@plt>
mov    0x2d36(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x48(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x40(%rbp),%rsi
add    $0x8,%rsi
mov    -0x48(%rbp),%rax
mov    (%rax),%edx
call   1070 <bcopy@plt>
mov    $0x5ba0,%edi
call   1030 <htons@plt>
mov    %rax,-0x40(%rbp)
mov    -0x160(%rbp),%edi
mov    -0x8(%rbp),%rsi
lea    -0x40(%rbp),%r8
mov    $0x100,%edx
xor    %ecx,%ecx
mov    $0x18,%r9d
call   1040 <sendto@plt>
mov    %eax,-0x158(%rbp)
cmpl   $0x0,-0x158(%rbp)
jg     1331 <sentom+0x191>
mov    0x2cad(%rip),%rax
mov    (%rax),%edi
mov    -0x158(%rbp),%edx
lea    0xd2d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sentom>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x18,%esi
call   10a0 <bzero@plt>
mov    0x2e20(%rip),%r13
mov    0x0(%r13),%rax
mov    %rax,0x10(%rsp)
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
xor    %edi,%edi
call   1030 <htons@plt>
mov    %rax,(%rsp)
mov    0x0(%r13),%rdi
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
test   %eax,%eax
js     12b2 <sentom+0x112>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x18,%edx
call   1080 <bind@plt>
test   %rax,%rax
js     12bb <sentom+0x11b>
mov    %rbx,%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     12d1 <sentom+0x131>
mov    %rax,%rbx
lea    0x8(%rsp),%r15
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x18,%esi
call   10a0 <bzero@plt>
mov    0x0(%r13),%rax
mov    %rax,0x10(%rsp)
mov    (%rbx),%edx
mov    0x4(%rbx),%edi
mov    %r15,%rsi
call   1070 <bcopy@plt>
mov    $0x5ba0,%edi
call   1030 <htons@plt>
mov    %rax,(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    $0x18,%r9d
call   1040 <sendto@plt>
test   %eax,%eax
jg     12a3 <sentom+0x103>
mov    0x2d37(%rip),%rcx
mov    (%rcx),%edi
lea    0xdbd(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd47(%rip),%rdi
jmp    12c2 <sentom+0x122>
lea    0xd5d(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
lea    0xd5b(%rip),%rsi
lea    0xd65(%rip),%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i8* null
@INADDR_ANY = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [31 x i8] c"simplex-talk: UDP_socket error\00"
@.str.1 = [29 x i8] c"simplex-talk: UDP_bind error\00"
@stderr = global i32 0
@.str.2 = [17 x i8] c"Unknown host %s\0A\00"
@.str.3 = [10 x i8] c"localhost\00"
@.str.4 = [24 x i8] c"Datagram Send error %d\0A\00"
define void @sentom(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.hostent*
%8 = alloca [256 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%14 = bitcast %struct.sockaddr_in* %6 to i8*
%15 = call i32 @bzero(i8* %14, i32 24)
%16 = load i8*, i8** @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i8* %16, i8** %17
%18 = load i32, i32* @INADDR_ANY
%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 i8* @htons(i32 0)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i8* %21, i8** %22
%23 = load i8*, i8** @AF_INET
%24 = load i32, i32* @SOCK_DGRAM
%25 = call i32 @socket(i8* %23, i32 %24, i32 0)
store i32 %25, i32* %12
%26 = load i32, i32* %12
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %2
%29 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %2
%32 = load i32, i32* %12
%33 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%34 = call i64 @bind(i32 %32, %struct.sockaddr* %33, i32 24)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %31
%40 = load i8*, i8** %4
%41 = call %struct.hostent* @gethostbyname(i8* %40)
store %struct.hostent* %41, %struct.hostent** %7
%42 = load %struct.hostent*, %struct.hostent** %7
%43 = icmp ne %struct.hostent* %42, null
br i1 %43, label %48, label %44
44: ; preds = %39
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %39
%49 = bitcast %struct.sockaddr_in* %6 to i8*
%50 = call i32 @bzero(i8* %49, i32 24)
%51 = load i8*, i8** @AF_INET
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i8* %51, i8** %52
%53 = load %struct.hostent*, %struct.hostent** %7
%54 = getelementptr inbounds %struct.hostent, %struct.hostent* %53, i32 0, i32 1
%55 = load i32, i32* %54
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%57 = bitcast %struct.TYPE_2__* %56 to i8*
%58 = load %struct.hostent*, %struct.hostent** %7
%59 = getelementptr inbounds %struct.hostent, %struct.hostent* %58, i32 0, i32 0
%60 = load i32, i32* %59
%61 = call i32 @bcopy(i32 %55, i8* %57, i32 %60)
%62 = call i8* @htons(i32 23456)
%63 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i8* %62, i8** %63
%64 = load i32, i32* %12
%65 = load i8*, i8** %3
%66 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%67 = call i32 @sendto(i32 %64, i8* %65, i32 256, i32 0, %struct.sockaddr* %66, i32 24)
store i32 %67, i32* %10
%68 = load i32, i32* %10
%69 = icmp sle i32 %68, 0
br i1 %69, label %70, label %74
70: ; preds = %48
%71 = load i32, i32* @stderr
%72 = load i32, i32* %10
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %72)
br label %74
74: ; preds = %70, %48
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
%struct.hostent = type { i32, i32 }
@AF_INET = global i8* null
@INADDR_ANY = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [31 x i8] c"simplex-talk: UDP_socket error\00"
@.str.1 = [29 x i8] c"simplex-talk: UDP_bind error\00"
@stderr = global i32 0
@.str.2 = [17 x i8] c"Unknown host %s\0A\00"
@.str.3 = [10 x i8] c"localhost\00"
@.str.4 = [24 x i8] c"Datagram Send error %d\0A\00"
define void @sentom(i8* %0, i8* %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = call i32 @bzero(i8* %4, i32 24)
%6 = load i8*, i8** @AF_INET
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i8* %6, i8** %7
%8 = load i32, i32* @INADDR_ANY
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%10 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %9, i64 0, i32 0
store i32 %8, i32* %10
%11 = tail call i8* @htons(i32 0)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i8* %11, i8** %12
%13 = load i8*, i8** @AF_INET
%14 = load i32, i32* @SOCK_DGRAM
%15 = tail call i32 @socket(i8* %13, i32 %14, i32 0)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%22 = call i64 @bind(i32 %15, %struct.sockaddr* %21, i32 24)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %20
%28 = call %struct.hostent* @gethostbyname(i8* %1)
%29 = icmp eq %struct.hostent* %28, null
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %27
%35 = call i32 @bzero(i8* %4, i32 24)
%36 = load i8*, i8** @AF_INET
store i8* %36, i8** %7
%37 = getelementptr inbounds %struct.hostent, %struct.hostent* %28, i64 0, i32 1
%38 = load i32, i32* %37
%39 = bitcast %struct.TYPE_2__* %9 to i8*
%40 = getelementptr inbounds %struct.hostent, %struct.hostent* %28, i64 0, i32 0
%41 = load i32, i32* %40
%42 = call i32 @bcopy(i32 %38, i8* %39, i32 %41)
%43 = call i8* @htons(i32 23456)
store i8* %43, i8** %12
%44 = call i32 @sendto(i32 %15, i8* %0, i32 256, i32 0, %struct.sockaddr* %21, i32 24)
%45 = icmp slt i32 %44, 1
br i1 %45, label %46, label %49
46: ; preds = %34
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %44)
br label %49
49: ; preds = %46, %34
ret void
}