#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*/ serializer_write_char(char *, int *, char);
int /*<<< orphan*/ serializer_write_short(char *, int *, short);
short strlen(char *);
void serializer_write_string(char *dest, int *pointer, char *value) {
  short length = strlen(value);
  serializer_write_short(dest, pointer, length);
  short i;
  for (i = 0; i < length; i++) {
    serializer_write_char(dest, pointer, value[i]);
  }
  serializer_write_char(dest, pointer, '\0');
}


x86 assembly (clang, -O0):
<serializer_write_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %ax,-0x1a(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movswl -0x1a(%rbp),%edx
call   1030 <serializer_write_short@plt>
movw   $0x0,-0x1c(%rbp)
movswl -0x1c(%rbp),%eax
movswl -0x1a(%rbp),%ecx
cmp    %ecx,%eax
jge    11a3 <serializer_write_string+0x73>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
movswq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
call   1050 <serializer_write_char@plt>
mov    -0x1c(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x1c(%rbp)
jmp    1168 <serializer_write_string+0x38>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1050 <serializer_write_char@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serializer_write_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r13
mov    %rdx,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
movswl %ax,%ebp
mov    %r13,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <serializer_write_short@plt>
test   %bp,%bp
jle    1189 <serializer_write_string+0x59>
movzwl %r12w,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsbl (%r15,%rbx,1),%edx
mov    %r13,%rdi
mov    %r14,%rsi
call   1050 <serializer_write_char@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <serializer_write_string+0x40>
mov    %r13,%rdi
mov    %r14,%rsi
xor    %edx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <serializer_write_char@plt>

LLVM IR (-O0):
define void @serializer_write_string(i8* %0, i32* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i16
%8 = alloca i16
store i8* %0, i8** %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
%10 = call signext i16 @strlen(i8* %9)
store i16 %10, i16* %7
%11 = load i8*, i8** %4
%12 = load i32*, i32** %5
%13 = load i16, i16* %7
%14 = call i32 @serializer_write_short(i8* %11, i32* %12, i16 signext %13)
store i16 0, i16* %8
br label %15
15: ; preds = %30, %3
%16 = load i16, i16* %8
%17 = sext i16 %16 to i32
%18 = load i16, i16* %7
%19 = sext i16 %18 to i32
%20 = icmp slt i32 %17, %19
br i1 %20, label %21, label %33
21: ; preds = %15
%22 = load i8*, i8** %4
%23 = load i32*, i32** %5
%24 = load i8*, i8** %6
%25 = load i16, i16* %8
%26 = sext i16 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = call i32 @serializer_write_char(i8* %22, i32* %23, i8 signext %28)
br label %30
30: ; preds = %21
%31 = load i16, i16* %8
%32 = add i16 %31, 1
store i16 %32, i16* %8
br label %15
33: ; preds = %15
%34 = load i8*, i8** %4
%35 = load i32*, i32** %5
%36 = call i32 @serializer_write_char(i8* %34, i32* %35, i8 signext 0)
ret void
}

LLVM IR (-O2):
define void @serializer_write_string(i8* %0, i32* %1, i8* %2) {
%4 = tail call signext i16 @strlen(i8* %2)
%5 = tail call i32 @serializer_write_short(i8* %0, i32* %1, i16 signext %4)
%6 = icmp sgt i16 %4, 0
br i1 %6, label %7, label %16
7: ; preds = %3
%8 = zext i16 %4 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %14, %9 ]
%11 = getelementptr inbounds i8, i8* %2, i64 %10
%12 = load i8, i8* %11
%13 = tail call i32 @serializer_write_char(i8* %0, i32* %1, i8 signext %12)
%14 = add nuw nsw i64 %10, 1
%15 = icmp eq i64 %14, %8
br i1 %15, label %16, label %9
16: ; preds = %9, %3
%17 = tail call i32 @serializer_write_char(i8* %0, i32* %1, i8 signext 0)
ret void
}