#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 binary_writer_7bit_len(int);
int /*<<< orphan*/ binary_writer_write_7bit_int(char *, int, int *);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int strlen(char const *);
int binary_writer_write_string(char *dest, const char *src) {
  int len, pos = 0;
  len = strlen(src);
  binary_writer_write_7bit_int(dest, len, &pos);
  memcpy(dest + pos, src, len);
  return len + binary_writer_7bit_len(len);
}


x86 assembly (clang, -O0):
<binary_writer_write_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x18(%rbp),%rdx
call   1030 <binary_writer_write_7bit_int@plt>
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <binary_writer_7bit_len@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binary_writer_write_string>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movl   $0x0,0xc(%rsp)
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <binary_writer_write_7bit_int@plt>
movslq 0xc(%rsp),%rdi
add    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
mov    %ebp,%edi
call   1060 <binary_writer_7bit_len@plt>
add    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @binary_writer_write_string(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %6
%7 = load i8*, i8** %4
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %5
%9 = load i8*, i8** %3
%10 = load i32, i32* %5
%11 = call i32 @binary_writer_write_7bit_int(i8* %9, i32 %10, i32* %6)
%12 = load i8*, i8** %3
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8*, i8** %4
%17 = load i32, i32* %5
%18 = call i32 @memcpy(i8* %15, i8* %16, i32 %17)
%19 = load i32, i32* %5
%20 = load i32, i32* %5
%21 = call i32 @binary_writer_7bit_len(i32 %20)
%22 = add nsw i32 %19, %21
ret i32 %22
}

LLVM IR (-O2):
define i32 @binary_writer_write_string(i8* %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = tail call i32 @strlen(i8* %1)
%6 = call i32 @binary_writer_write_7bit_int(i8* %0, i32 %5, i32* %3)
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = call i32 @memcpy(i8* %9, i8* %1, i32 %5)
%11 = call i32 @binary_writer_7bit_len(i32 %5)
%12 = add nsw i32 %11, %5
ret i32 %12
}