#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 socklen_t;

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ sendto(int, char *, scalar_t__, int /*<<< orphan*/,
                          struct sockaddr const *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ strlen(char *);
extern void reply_to_sender(int sock_fd, char *msg, struct sockaddr_in *saddrp,
                            socklen_t len) {
  char reply[BUFSIZ + BUFSIZ];
  sprintf(reply, "Thanks for your %d char message\n", (socklen_t)strlen(msg));
  sendto(sock_fd, reply, strlen(reply), 0, (const struct sockaddr *)saddrp,
         len);
}


x86 assembly (clang, -O0):
<reply_to_sender>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    0x2e93(%rip),%rax
mov    (%rax),%eax
add    %eax,%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%edx
lea    0xe76(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x4(%rbp),%eax
mov    %eax,-0x3c(%rbp)
call   1030 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
mov    -0x18(%rbp),%r8
mov    -0x1c(%rbp),%r9d
xor    %ecx,%ecx
call   1040 <sendto@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reply_to_sender>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %edi,%r12d
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
add    %eax,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsi,%rdi
call   1030 <strlen@plt>
lea    0xe91(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r14d,%r9d
call   1040 <sendto@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@BUFSIZ = global i32 0
@.str = [33 x i8] c"Thanks for your %d char message\0A\00"
define void @reply_to_sender(i32 %0, i8* %1, %struct.sockaddr_in* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.sockaddr_in*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
store i32 %0, i32* %5
store i8* %1, i8** %6
store %struct.sockaddr_in* %2, %struct.sockaddr_in** %7
store i32 %3, i32* %8
%11 = load i32, i32* @BUFSIZ
%12 = load i32, i32* @BUFSIZ
%13 = add nsw i32 %11, %12
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %9
%16 = alloca i8, i64 %14
store i64 %14, i64* %10
%17 = load i8*, i8** %6
%18 = call i64 @strlen(i8* %17)
%19 = trunc i64 %18 to i32
%20 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %5
%22 = call i64 @strlen(i8* %16)
%23 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%24 = bitcast %struct.sockaddr_in* %23 to %struct.sockaddr*
%25 = load i32, i32* %8
%26 = call i32 @sendto(i32 %21, i8* %16, i64 %22, i32 0, %struct.sockaddr* %24, i32 %25)
%27 = load i8*, i8** %9
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@BUFSIZ = global i32 0
@.str = [33 x i8] c"Thanks for your %d char message\0A\00"
define void @reply_to_sender(i32 %0, i8* nocapture %1, %struct.sockaddr_in* %2, i32 %3) {
%5 = load i32, i32* @BUFSIZ
%6 = shl nsw i32 %5, 1
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%10 = trunc i64 %9 to i32
%11 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = call i64 @strlen(i8* %8)
%13 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%14 = call i32 @sendto(i32 %0, i8* %8, i64 %12, i32 0, %struct.sockaddr* %13, i32 %3)
ret void
}