#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*/ check_size_available(char *, int);
int sprintf(char *, char *, int, char *);
void append_mm_XMLfile(int runtime_count, char *content, char *file_memory) {
  int strlen = 0;
  int mem_ptr = 0;
  check_size_available(file_memory, 550);
  mem_ptr = *file_memory;
  mem_ptr = (mem_ptr << 8) + *(file_memory + 1);
  strlen = sprintf(
      (char *)(file_memory + 2 + mem_ptr),
      "\n<ble id=%d>\n<stw>\n<milliseconds>%s</milliseconds>\n</stw>\n</ble>\n",
      runtime_count, content);
  *file_memory = (char)(((strlen + mem_ptr) & 0xFF00) >> 8);
  *(file_memory + 1) = (char)((strlen + mem_ptr) & 0xFF);
}


x86 assembly (clang, -O0):
<append_mm_XMLfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x226,%esi
call   1030 <check_size_available@plt>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
shl    $0x8,%eax
mov    -0x18(%rbp),%rcx
movsbl 0x1(%rcx),%ecx
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x2,%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x4(%rbp),%edx
mov    -0x10(%rbp),%rcx
lea    0xe77(%rip),%rsi
call   1040 <sprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_mm_XMLfile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%r15d
mov    %rdx,%rdi
mov    $0x226,%esi
call   1030 <check_size_available@plt>
movsbq (%rbx),%rax
shl    $0x8,%rax
movsbq 0x1(%rbx),%rbp
add    %rax,%rbp
lea    (%rbx,%rbp,1),%rdi
add    $0x2,%rdi
lea    0xea4(%rip),%rsi
mov    %r15d,%edx
mov    %r14,%rcx
call   1040 <sprintf@plt>
add    %ebp,%eax
rol    $0x8,%ax
mov    %ax,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [66 x i8] c"\0A<ble id=%d>\0A<stw>\0A<milliseconds>%s</milliseconds>\0A</stw>\0A</ble>\0A\00"
define void @append_mm_XMLfile(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 0, i32* %7
store i32 0, i32* %8
%9 = load i8*, i8** %6
%10 = call i32 @check_size_available(i8* %9, i32 550)
%11 = load i8*, i8** %6
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = shl i32 %14, 8
%16 = load i8*, i8** %6
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = add nsw i32 %15, %19
store i32 %20, i32* %8
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i64 2
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i32, i32* %4
%27 = load i8*, i8** %5
%28 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i32 %26, i8* %27)
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = load i32, i32* %8
%31 = add nsw i32 %29, %30
%32 = and i32 %31, 65280
%33 = ashr i32 %32, 8
%34 = trunc i32 %33 to i8
%35 = load i8*, i8** %6
store i8 %34, i8* %35
%36 = load i32, i32* %7
%37 = load i32, i32* %8
%38 = add nsw i32 %36, %37
%39 = and i32 %38, 255
%40 = trunc i32 %39 to i8
%41 = load i8*, i8** %6
%42 = getelementptr inbounds i8, i8* %41, i64 1
store i8 %40, i8* %42
ret void
}

LLVM IR (-O2):
@.str = [66 x i8] c"\0A<ble id=%d>\0A<stw>\0A<milliseconds>%s</milliseconds>\0A</stw>\0A</ble>\0A\00"
define void @append_mm_XMLfile(i32 %0, i8* %1, i8* %2) {
%4 = tail call i32 @check_size_available(i8* %2, i32 550)
%5 = load i8, i8* %2
%6 = sext i8 %5 to i32
%7 = shl nsw i32 %6, 8
%8 = getelementptr inbounds i8, i8* %2, i64 1
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = add nsw i32 %7, %10
%12 = getelementptr inbounds i8, i8* %2, i64 2
%13 = sext i32 %11 to i64
%14 = getelementptr inbounds i8, i8* %12, i64 %13
%15 = tail call i32 @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i32 %0, i8* %1)
%16 = add nsw i32 %11, %15
%17 = lshr i32 %16, 8
%18 = trunc i32 %17 to i8
store i8 %18, i8* %2
%19 = trunc i32 %16 to i8
store i8 %19, i8* %8
ret void
}