#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 ssize_t;
typedef int /*<<< orphan*/ serv_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int noly_udp_sender(char *addr, int port, char *payload, int len) {
  int sock;
  struct sockaddr_in serv_addr;
  sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  if (sock < 0) {
    return -1;
  }
  if (payload == NULL) {
    return -1;
  }
  bzero(&serv_addr, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = inet_addr(addr);
  serv_addr.sin_port = htons(port);
  ssize_t n = sendto(sock, payload, len, 0, (struct sockaddr *)&serv_addr,
                     sizeof(serv_addr));
  close(sock);
  return n;
}


x86 assembly (clang, -O0):
<noly_udp_sender>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
call   1080 <socket@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    11af <noly_udp_sender+0x4f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1223 <noly_udp_sender+0xc3>
cmpq   $0x0,-0x20(%rbp)
jne    11c6 <noly_udp_sender+0x66>
movl   $0xffffffff,-0x4(%rbp)
jmp    1223 <noly_udp_sender+0xc3>
lea    -0x38(%rbp),%rdi
mov    $0xc,%esi
call   1070 <bzero@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    -0x38(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1040 <sendto@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<noly_udp_sender>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,0x4(%rsp)
mov    %rdx,%r13
mov    %esi,%r15d
mov    %rdi,%r12
mov    0x2e66(%rip),%r14
mov    (%r14),%edi
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
mov    0x2e33(%rip),%rax
mov    (%rax),%edx
call   1080 <socket@plt>
mov    $0xffffffff,%ebx
test   %r13,%r13
je     11ff <noly_udp_sender+0x9f>
mov    %eax,%ebp
test   %eax,%eax
js     11ff <noly_udp_sender+0x9f>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   1070 <bzero@plt>
mov    (%r14),%eax
mov    %eax,0x10(%rsp)
mov    %r12,%rdi
call   1060 <inet_addr@plt>
mov    %eax,0xc(%rsp)
mov    %r15d,%edi
call   1030 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
mov    %r13,%rsi
mov    0x4(%rsp),%edx
xor    %ecx,%ecx
mov    %rbx,%r8
mov    $0xc,%r9d
call   1040 <sendto@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1050 <close@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
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_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
define i32 @noly_udp_sender(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.sockaddr_in
%12 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_DGRAM
%15 = load i32, i32* @IPPROTO_UDP
%16 = call i32 @socket(i32 %13, i32 %14, i32 %15)
store i32 %16, i32* %10
%17 = load i32, i32* %10
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %4
store i32 -1, i32* %5
br label %43
20: ; preds = %4
%21 = load i8*, i8** %8
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 -1, i32* %5
br label %43
24: ; preds = %20
%25 = call i32 @bzero(%struct.sockaddr_in* %11, i32 12)
%26 = load i32, i32* @AF_INET
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %26, i32* %27
%28 = load i8*, i8** %6
%29 = call i32 @inet_addr(i8* %28)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%31 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %30, i32 0, i32 0
store i32 %29, i32* %31
%32 = load i32, i32* %7
%33 = call i32 @htons(i32 %32)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
store i32 %33, i32* %34
%35 = load i32, i32* %10
%36 = load i8*, i8** %8
%37 = load i32, i32* %9
%38 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%39 = call i32 @sendto(i32 %35, i8* %36, i32 %37, i32 0, %struct.sockaddr* %38, i32 12)
store i32 %39, i32* %12
%40 = load i32, i32* %10
%41 = call i32 @close(i32 %40)
%42 = load i32, i32* %12
store i32 %42, i32* %5
br label %43
43: ; preds = %24, %23, %19
%44 = load i32, i32* %5
ret i32 %44
}

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_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
define i32 @noly_udp_sender(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca %struct.sockaddr_in
%6 = bitcast %struct.sockaddr_in* %5 to i8*
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = load i32, i32* @IPPROTO_UDP
%10 = tail call i32 @socket(i32 %7, i32 %8, i32 %9)
%11 = icmp slt i32 %10, 0
%12 = icmp eq i8* %2, null
%13 = or i1 %12, %11
br i1 %13, label %25, label %14
14: ; preds = %4
%15 = call i32 @bzero(%struct.sockaddr_in* %5, i32 12)
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %16, i32* %17
%18 = tail call i32 @inet_addr(i8* %0)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
store i32 %18, i32* %19
%20 = tail call i32 @htons(i32 %1)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i32 %20, i32* %21
%22 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%23 = call i32 @sendto(i32 %10, i8* %2, i32 %3, i32 0, %struct.sockaddr* %22, i32 12)
%24 = call i32 @close(i32 %10)
br label %25
25: ; preds = %4, %14
%26 = phi i32 [ %23, %14 ], [ -1, %4 ]
ret i32 %26
}