#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 dummy;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int sendto(int, char *, unsigned int, int /*<<< orphan*/, struct sockaddr *,
           int /*<<< orphan*/);
void socket_put_packet(int fd, struct sockaddr_in *sa, socklen_t salen,
                       char *buf, unsigned int buflen) {
  if (sendto(fd, buf, buflen, 0, (struct sockaddr *)sa, salen) == -1) {
    perror("sendto");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<socket_put_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)
mov    %r8d,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x10(%rbp),%r8
mov    -0x14(%rbp),%r9d
xor    %ecx,%ecx
call   1030 <sendto@plt>
cmp    $0xffffffff,%eax
jne    1182 <socket_put_packet+0x52>
lea    0xe8d(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_put_packet>:
push   %rax
mov    %edx,%r9d
mov    %rsi,%rax
mov    %rcx,%rsi
mov    %r8d,%edx
xor    %ecx,%ecx
mov    %rax,%r8
call   1030 <sendto@plt>
cmp    $0xffffffff,%eax
je     114e <socket_put_packet+0x1e>
pop    %rax
ret
lea    0xeab(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

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