#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_ll {
  int dummy;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
void write_packet(int fd, char *buf, int len, struct sockaddr_ll *daddr) {
  int ret = -1;
  ret = sendto(fd, buf, len, 0, (struct sockaddr *)daddr, sizeof(*daddr));
  if (ret == -1)
    error(1, errno, "sendto failure");
  if (ret != len)
    error(1, errno, "sendto wrong length");
}


x86 assembly (clang, -O0):
<write_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%r8
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1030 <sendto@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    117f <write_packet+0x5f>
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe86(%rip),%rdx
call   1040 <error@plt>
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     11a5 <write_packet+0x85>
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe6f(%rip),%rdx
call   1040 <error@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_packet>:
push   %rbp
push   %rbx
push   %rax
mov    %rcx,%r8
mov    %edx,%ebx
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1030 <sendto@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     1147 <write_packet+0x27>
cmp    %ebx,%ebp
jne    1165 <write_packet+0x45>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
lea    0xea9(%rip),%rdx
mov    $0x1,%edi
call   1040 <error@plt>
cmp    %ebx,%ebp
je     1140 <write_packet+0x20>
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
lea    0xe9a(%rip),%rdx
mov    $0x1,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <error@plt>

LLVM IR (-O0):
%struct.sockaddr_ll = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i32 0
@.str = [15 x i8] c"sendto failure\00"
@.str.1 = [20 x i8] c"sendto wrong length\00"
define void @write_packet(i32 %0, i8* %1, i32 %2, %struct.sockaddr_ll* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.sockaddr_ll*
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store %struct.sockaddr_ll* %3, %struct.sockaddr_ll** %8
store i32 -1, i32* %9
%10 = load i32, i32* %5
%11 = load i8*, i8** %6
%12 = load i32, i32* %7
%13 = load %struct.sockaddr_ll*, %struct.sockaddr_ll** %8
%14 = bitcast %struct.sockaddr_ll* %13 to %struct.sockaddr*
%15 = call i32 @sendto(i32 %10, i8* %11, i32 %12, i32 0, %struct.sockaddr* %14, i32 4)
store i32 %15, i32* %9
%16 = load i32, i32* %9
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %4
%19 = load i32, i32* @errno
%20 = call i32 @error(i32 1, i32 %19, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %18, %4
%22 = load i32, i32* %9
%23 = load i32, i32* %7
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32, i32* @errno
%27 = call i32 @error(i32 1, i32 %26, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %25, %21
ret void
}

LLVM IR (-O2):
%struct.sockaddr_ll = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i32 0
@.str = [15 x i8] c"sendto failure\00"
@.str.1 = [20 x i8] c"sendto wrong length\00"
define void @write_packet(i32 %0, i8* %1, i32 %2, %struct.sockaddr_ll* %3) {
%5 = bitcast %struct.sockaddr_ll* %3 to %struct.sockaddr*
%6 = tail call i32 @sendto(i32 %0, i8* %1, i32 %2, i32 0, %struct.sockaddr* %5, i32 4)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = load i32, i32* @errno
%10 = tail call i32 @error(i32 1, i32 %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %8, %4
%12 = icmp eq i32 %6, %2
br i1 %12, label %16, label %13
13: ; preds = %11
%14 = load i32, i32* @errno
%15 = tail call i32 @error(i32 1, i32 %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %13, %11
ret void
}