#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 in_addr {
  int dummy;
};
struct sockaddr_in {
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(unsigned char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int sendto(int, unsigned char *, size_t, int /*<<< orphan*/, struct sockaddr *,
           int);
void send_ip_frame(int sockfd, struct in_addr daddr, unsigned char *buffer,
                   size_t len) {
  struct sockaddr_in servaddr;
  bzero(&servaddr, sizeof(struct sockaddr_in));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr = daddr;
  int bytes_sent = sendto(sockfd, buffer, len, 0, (struct sockaddr *)&servaddr,
                          sizeof(struct sockaddr_in));
  if (bytes_sent < 0) {
    perror("sendto()");
    exit(EXIT_FAILURE);
  }
  FILE *fp;
  fp = fopen("deeebg", "wb");
  fwrite(buffer, sizeof(char), len, fp);
}


x86 assembly (clang, -O0):
<send_ip_frame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %esi,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
mov    $0x8,%esi
call   1060 <bzero@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%r8
xor    %ecx,%ecx
mov    $0x8,%r9d
call   1030 <sendto@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    11d9 <send_ip_frame+0x79>
lea    0xe3a(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0xe29(%rip),%rdi
lea    0xe29(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
call   1080 <fwrite@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_ip_frame>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%ebp
mov    %edi,%ebx
lea    0x8(%rsp),%r12
mov    %r12,%rdi
mov    $0x8,%esi
call   1060 <bzero@plt>
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    %ebp,0x8(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
mov    %r12,%r8
mov    $0x8,%r9d
call   1030 <sendto@plt>
test   %eax,%eax
js     11e8 <send_ip_frame+0x88>
lea    0xe4d(%rip),%rdi
lea    0xe4d(%rip),%rsi
call   1040 <fopen@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %rax,%rcx
call   1080 <fwrite@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe11(%rip),%rdi
call   1050 <perror@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
%struct.sockaddr_in = type { %struct.in_addr, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str = [9 x i8] c"sendto()\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [7 x i8] c"deeebg\00"
@.str.2 = [3 x i8] c"wb\00"
define void @send_ip_frame(i32 %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca %struct.in_addr
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca i32*
%12 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %5, i32 0, i32 0
store i32 %1, i32* %12
store i32 %0, i32* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%13 = call i32 @bzero(%struct.sockaddr_in* %9, i32 8)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%17 = bitcast %struct.in_addr* %16 to i8*
%18 = bitcast %struct.in_addr* %5 to i8*
%19 = load i32, i32* %6
%20 = load i8*, i8** %7
%21 = load i64, i64* %8
%22 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%23 = call i32 @sendto(i32 %19, i8* %20, i64 %21, i32 0, %struct.sockaddr* %22, i32 8)
store i32 %23, i32* %10
%24 = load i32, i32* %10
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %4
%27 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %4
%31 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %31, i32** %11
%32 = load i8*, i8** %7
%33 = load i64, i64* %8
%34 = load i32*, i32** %11
%35 = call i32 @fwrite(i8* %32, i32 1, i64 %33, i32* %34)
ret void
}

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