#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 */

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, unsigned int, char const *);
scalar_t__ strlen(char const *);
size_t write(int, char *, scalar_t__);
size_t send_data(int fd, const char *data) {
  static char buffer[256];
  sprintf(buffer, "$%02x %s", (unsigned int)strlen(data), data);
  return write(fd, buffer, strlen(buffer));
}


x86 assembly (clang, -O0):
<send_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rcx
lea    0x2efb(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    0x2ee2(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
lea    0x2ed0(%rip),%rsi
call   1030 <write@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_data>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsi,%rdi
call   1040 <strlen@plt>
lea    0x2f07(%rip),%rbp
lea    0xeb0(%rip),%rsi
mov    %rbp,%rdi
mov    %eax,%edx
mov    %rbx,%rcx
call   1050 <sprintf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %rax,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <write@plt>

LLVM IR (-O0):
@send_data.buffer = internal global [256 x i8] zeroinitializer
@.str = [9 x i8] c"$%02x %s\00"
define i64 @send_data(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i8*, i8** %4
%6 = call i64 @strlen(i8* %5)
%7 = trunc i64 %6 to i32
%8 = load i8*, i8** %4
%9 = call i32 @sprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @send_data.buffer, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %7, i8* %8)
%10 = load i32, i32* %3
%11 = call i64 @strlen(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @send_data.buffer, i64 0, i64 0))
%12 = call i64 @write(i32 %10, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @send_data.buffer, i64 0, i64 0), i64 %11)
ret i64 %12
}

LLVM IR (-O2):
@send_data.buffer = internal global [256 x i8] zeroinitializer
@.str = [9 x i8] c"$%02x %s\00"
define i64 @send_data(i32 %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = trunc i64 %3 to i32
%5 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([256 x i8], [256 x i8]* @send_data.buffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %4, i8* %1)
%6 = tail call i64 @strlen(i8* dereferenceable(1) getelementptr inbounds ([256 x i8], [256 x i8]* @send_data.buffer, i64 0, i64 0))
%7 = tail call i64 @write(i32 %0, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @send_data.buffer, i64 0, i64 0), i64 %6)
ret i64 %7
}