#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 char uint8_t;
typedef int /*<<< orphan*/ len_str;

/* Variables and functions */
int /*<<< orphan*/ encode_field(char *, int, int *, char *, char *);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned int);
void fill_fpga_metadata_page(uint8_t *metadata, size_t actual_bitstream_len) {
  char len_str[10];
  int idx = 0;
  memset(len_str, 0, sizeof(len_str));
  memset(metadata, 0xff, 256);
  snprintf(len_str, sizeof(len_str), "%u", (unsigned int)actual_bitstream_len);
  encode_field((char *)metadata, 256, &idx, "LEN", len_str);
}


x86 assembly (clang, -O0):
<fill_fpga_metadata_page>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
lea    -0x1a(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    $0xff,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
lea    -0x1a(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %eax,%ecx
mov    $0xa,%esi
lea    0xe80(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x1a(%rbp),%r8
mov    $0x100,%esi
lea    -0x20(%rbp),%rdx
lea    0xe66(%rip),%rcx
call   1050 <encode_field@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_fpga_metadata_page>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
movl   $0x0,(%rsp)
lea    0x6(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    $0xff,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
lea    0xe8d(%rip),%rdx
mov    %r14,%rdi
mov    $0xa,%esi
mov    %r15d,%ecx
call   1030 <snprintf@plt>
lea    0xe79(%rip),%rcx
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r14,%r8
call   1050 <encode_field@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%u\00"
@.str.1 = [4 x i8] c"LEN\00"
define void @fill_fpga_metadata_page(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca [10 x i8]
%6 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
store i32 0, i32* %6
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 10)
%9 = load i8*, i8** %3
%10 = call i32 @memset(i8* %9, i32 255, i32 256)
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%12 = load i64, i64* %4
%13 = trunc i64 %12 to i32
%14 = call i32 @snprintf(i8* %11, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i8*, i8** %3
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%17 = call i32 @encode_field(i8* %15, i32 256, i32* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %16)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%u\00"
@.str.1 = [4 x i8] c"LEN\00"
define void @fill_fpga_metadata_page(i8* %0, i64 %1) {
%3 = alloca [10 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%7 = call i32 @memset(i8* %5, i32 0, i32 10)
%8 = call i32 @memset(i8* %0, i32 255, i32 256)
%9 = trunc i64 %1 to i32
%10 = call i32 @snprintf(i8* %5, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32 @encode_field(i8* %0, i32 256, i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %5)
ret void
}