#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 /*<<< orphan*/ packet;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ printf(char *, char *);
int sendto_(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int /*<<< orphan*/);
void send_ack(int lfread, int sd, struct sockaddr *cliAddr, int addr_size) {
  int nbytes;
  char packet[9], last_frame_received[9];
  sprintf(last_frame_received, "%08x", lfread);
  strcpy(packet, last_frame_received);
  if ((nbytes = sendto_(sd, packet, sizeof(packet), 0, cliAddr, addr_size)) ==
      0) {
    printf("error sending packet %s\n", strerror(errno));
  }
}


x86 assembly (clang, -O0):
<send_ack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
lea    -0x2a(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe8d(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x21(%rbp),%rdi
lea    -0x2a(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    -0x10(%rbp),%r8
mov    -0x14(%rbp),%r9d
mov    $0x9,%edx
xor    %ecx,%ecx
call   1050 <sendto_@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jne    11c9 <send_ack+0x79>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %rax,%rsi
lea    0xe41(%rip),%rdi
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_ack>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %esi,%ebp
mov    %edi,%edx
lea    0xe93(%rip),%rsi
lea    0xe(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
lea    0x17(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x9,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r14d,%r9d
call   1050 <sendto_@plt>
test   %eax,%eax
jne    11c2 <send_ack+0x72>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe4b(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"%08x\00"
@.str.1 = [25 x i8] c"error sending packet %s\0A\00"
@errno = global i32 0
define void @send_ack(i32 %0, i32 %1, %struct.sockaddr* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.sockaddr*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [9 x i8]
%11 = alloca [9 x i8]
store i32 %0, i32* %5
store i32 %1, i32* %6
store %struct.sockaddr* %2, %struct.sockaddr** %7
store i32 %3, i32* %8
%12 = getelementptr inbounds [9 x i8], [9 x i8]* %11, i64 0, i64 0
%13 = load i32, i32* %5
%14 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [9 x i8], [9 x i8]* %10, i64 0, i64 0
%16 = getelementptr inbounds [9 x i8], [9 x i8]* %11, i64 0, i64 0
%17 = call i32 @strcpy(i8* %15, i8* %16)
%18 = load i32, i32* %6
%19 = getelementptr inbounds [9 x i8], [9 x i8]* %10, i64 0, i64 0
%20 = load %struct.sockaddr*, %struct.sockaddr** %7
%21 = load i32, i32* %8
%22 = call i32 @sendto_(i32 %18, i8* %19, i32 9, i32 0, %struct.sockaddr* %20, i32 %21)
store i32 %22, i32* %9
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %4
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
%27 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %24, %4
ret void
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"%08x\00"
@.str.1 = [25 x i8] c"error sending packet %s\0A\00"
@errno = global i32 0
define void @send_ack(i32 %0, i32 %1, %struct.sockaddr* %2, i32 %3) {
%5 = alloca [9 x i8]
%6 = alloca [9 x i8]
%7 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 0
%9 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %0)
%10 = call i32 @strcpy(i8* %7, i8* %8)
%11 = call i32 @sendto_(i32 %1, i8* %7, i32 9, i32 0, %struct.sockaddr* %2, i32 %3)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %4
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %13, %4
ret void
}