#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 {
  int dummy;
};
typedef int ssize_t;
typedef int socklen_t;

/* Variables and functions */
int /*<<< orphan*/ eprintf(char *);
int /*<<< orphan*/ iptoaddr(struct sockaddr *, unsigned char *, int);
int sendto(int, void *, size_t, int /*<<< orphan*/, struct sockaddr *, int);
ssize_t udpsend(unsigned char ip[4], int fd, void *data, size_t n) {
  struct sockaddr addr;
  socklen_t addrlen = sizeof addr;
  ssize_t sent;
  iptoaddr(&addr, ip, 67);
  if ((sent = sendto(fd, data, n, 0, &addr, addrlen)) == -1)
    eprintf("sendto:");
  return sent;
}


x86 assembly (clang, -O0):
<udpsend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x4,-0x2c(%rbp)
mov    -0x8(%rbp),%rsi
lea    -0x28(%rbp),%rdi
mov    $0x43,%edx
call   1040 <iptoaddr@plt>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x2c(%rbp),%r9d
xor    %ecx,%ecx
lea    -0x28(%rbp),%r8
call   1030 <sendto@plt>
mov    %eax,-0x30(%rbp)
cmp    $0xffffffff,%eax
jne    1192 <udpsend+0x62>
lea    0xe73(%rip),%rdi
call   1050 <eprintf@plt>
mov    -0x30(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udpsend>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x43,%edx
call   1040 <iptoaddr@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0x4,%r9d
call   1030 <sendto@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    117d <udpsend+0x4d>
lea    0xe88(%rip),%rdi
call   1050 <eprintf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@.str = [8 x i8] c"sendto:\00"
define i32 @udpsend(i8* %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca %struct.sockaddr
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
store i32 4, i32* %10
%12 = load i8*, i8** %5
%13 = call i32 @iptoaddr(%struct.sockaddr* %9, i8* %12, i32 67)
%14 = load i32, i32* %6
%15 = load i8*, i8** %7
%16 = load i64, i64* %8
%17 = load i32, i32* %10
%18 = call i32 @sendto(i32 %14, i8* %15, i64 %16, i32 0, %struct.sockaddr* %9, i32 %17)
store i32 %18, i32* %11
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %4
%21 = call i32 @eprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %4
%23 = load i32, i32* %11
ret i32 %23
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [8 x i8] c"sendto:\00"
define i32 @udpsend(i8* %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca %struct.sockaddr
%6 = bitcast %struct.sockaddr* %5 to i8*
%7 = call i32 @iptoaddr(%struct.sockaddr* %5, i8* %0, i32 67)
%8 = call i32 @sendto(i32 %1, i8* %2, i64 %3, i32 0, %struct.sockaddr* %5, i32 4)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = call i32 @eprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %4
ret i32 %8
}