#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 BUFSIZ;
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int strlen(char *);
void reply_to_sender(int sock, char *msg, struct sockaddr_in *addrp,
                     socklen_t len) {
  char reply[BUFSIZ + BUFSIZ];
  sprintf(reply, "Thanks for your %d char message\n", strlen(msg));
  sendto(sock, reply, strlen(reply), 0, (struct sockaddr *)addrp, 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    %eax,%edx
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    %eax,%edx
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 i32 @strlen(i8* %17)
%19 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %5
%21 = call i32 @strlen(i8* %16)
%22 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%23 = bitcast %struct.sockaddr_in* %22 to %struct.sockaddr*
%24 = load i32, i32* %8
%25 = call i32 @sendto(i32 %20, i8* %16, i32 %21, i32 0, %struct.sockaddr* %23, i32 %24)
%26 = 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* %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 i32 @strlen(i8* %1)
%10 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32 @strlen(i8* %8)
%12 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%13 = call i32 @sendto(i32 %0, i8* %8, i32 %11, i32 0, %struct.sockaddr* %12, i32 %3)
ret void
}