#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fwrite_check(char const *, int, int, int /*<<< orphan*/ *,
                                char const *);
int /*<<< orphan*/ serialize_int(int /*<<< orphan*/ *, int, long long *,
                                 char const *);
int strlen(char const *);
void serialize_string(FILE *out, const char *s, long long *fpos,
                      const char *fname) {
  int len = strlen(s);
  serialize_int(out, len + 1, fpos, fname);
  fwrite_check(s, sizeof(char), len, out, fname);
  fwrite_check("", sizeof(char), 1, out, fname);
  *fpos += len + 1;
}


x86 assembly (clang, -O0):
<serialize_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
add    $0x1,%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1050 <serialize_int@plt>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    $0x1,%esi
call   1040 <fwrite_check@plt>
mov    -0x8(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xe6d(%rip),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fwrite_check@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serialize_string>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r13
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
lea    0x1(%rbx),%esi
mov    %r13,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
call   1050 <serialize_int@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %r13,%rcx
mov    %r15,%r8
call   1040 <fwrite_check@plt>
lea    0xe84(%rip),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r13,%rcx
mov    %r15,%r8
call   1040 <fwrite_check@plt>
movslq %ebx,%rax
mov    (%r14),%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,(%r14)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define void @serialize_string(i32* %0, i8* %1, i64* %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64*
%8 = alloca i8*
%9 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i64* %2, i64** %7
store i8* %3, i8** %8
%10 = load i8*, i8** %6
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %9
%12 = load i32*, i32** %5
%13 = load i32, i32* %9
%14 = add nsw i32 %13, 1
%15 = load i64*, i64** %7
%16 = load i8*, i8** %8
%17 = call i32 @serialize_int(i32* %12, i32 %14, i64* %15, i8* %16)
%18 = load i8*, i8** %6
%19 = load i32, i32* %9
%20 = load i32*, i32** %5
%21 = load i8*, i8** %8
%22 = call i32 @fwrite_check(i8* %18, i32 1, i32 %19, i32* %20, i8* %21)
%23 = load i32*, i32** %5
%24 = load i8*, i8** %8
%25 = call i32 @fwrite_check(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 1, i32 1, i32* %23, i8* %24)
%26 = load i32, i32* %9
%27 = add nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = load i64*, i64** %7
%30 = load i64, i64* %29
%31 = add nsw i64 %30, %28
store i64 %31, i64* %29
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define void @serialize_string(i32* %0, i8* %1, i64* %2, i8* %3) {
%5 = tail call i32 @strlen(i8* %1)
%6 = add nsw i32 %5, 1
%7 = tail call i32 @serialize_int(i32* %0, i32 %6, i64* %2, i8* %3)
%8 = tail call i32 @fwrite_check(i8* %1, i32 1, i32 %5, i32* %0, i8* %3)
%9 = tail call i32 @fwrite_check(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 1, i32 1, i32* %0, i8* %3)
%10 = sext i32 %6 to i64
%11 = load i64, i64* %2
%12 = add nsw i64 %11, %10
store i64 %12, i64* %2
ret void
}