#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 uint8_t;
typedef int uint16_t;

/* Variables and functions */
int mdv_csum(int *, int);
int /*<<< orphan*/ memcpy(int *, int *, int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ strncpy(int *, char *, int);
void mdv_make_bufhdr(uint8_t *buf, uint8_t rec, uint8_t *bits) {
  printf("logical %d for %04x\n", rec, ((uint16_t)rec) << 8);
  memset(buf, 0, 14);
  buf[0] = 0;
  buf[1] = rec;
  buf[2] = 0;
  buf[3] = 2;
  strncpy(buf + 4, "FKERNEL.OS", 10);
  buf[14] = mdv_csum(buf, 14);
  memcpy(buf + 15, bits, 512);
  buf[527] = mdv_csum(buf + 15, 512);
}


x86 assembly (clang, -O0):
<mdv_make_bufhdr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%edx
shl    $0x8,%edx
lea    0xe8d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0xe,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%rax
movl   $0x0,(%rax)
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%rax
movl   $0x0,0x8(%rax)
mov    -0x8(%rbp),%rax
movl   $0x2,0xc(%rax)
mov    -0x8(%rbp),%rdi
add    $0x10,%rdi
lea    0xe54(%rip),%rsi
mov    $0xa,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rdi
mov    $0xe,%esi
call   1060 <mdv_csum@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x38(%rax)
mov    -0x8(%rbp),%rdi
add    $0x3c,%rdi
mov    -0x18(%rbp),%rsi
mov    $0x200,%edx
call   1070 <memcpy@plt>
mov    -0x8(%rbp),%rdi
add    $0x3c,%rdi
mov    $0x200,%esi
call   1060 <mdv_csum@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x83c(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mdv_make_bufhdr>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %esi,%edx
shl    $0x8,%edx
lea    0xe98(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xe,%edx
call   1050 <memset@plt>
movl   $0x0,(%rbx)
mov    %ebp,0x4(%rbx)
movabs $0x200000000,%rax
mov    %rax,0x8(%rbx)
lea    0x10(%rbx),%rdi
lea    0xe77(%rip),%rsi
mov    $0xa,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
mov    $0xe,%esi
call   1060 <mdv_csum@plt>
mov    %eax,0x38(%rbx)
lea    0x3c(%rbx),%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
mov    $0x200,%edx
call   1070 <memcpy@plt>
mov    %rbp,%rdi
mov    $0x200,%esi
call   1060 <mdv_csum@plt>
mov    %eax,0x83c(%rbx)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"logical %d for %04x\0A\00"
@.str.1 = [11 x i8] c"FKERNEL.OS\00"
define void @mdv_make_bufhdr(i32* %0, i32 %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%7 = load i32, i32* %5
%8 = load i32, i32* %5
%9 = shl i32 %8, 8
%10 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %9)
%11 = load i32*, i32** %4
%12 = call i32 @memset(i32* %11, i32 0, i32 14)
%13 = load i32*, i32** %4
%14 = getelementptr inbounds i32, i32* %13, i64 0
store i32 0, i32* %14
%15 = load i32, i32* %5
%16 = load i32*, i32** %4
%17 = getelementptr inbounds i32, i32* %16, i64 1
store i32 %15, i32* %17
%18 = load i32*, i32** %4
%19 = getelementptr inbounds i32, i32* %18, i64 2
store i32 0, i32* %19
%20 = load i32*, i32** %4
%21 = getelementptr inbounds i32, i32* %20, i64 3
store i32 2, i32* %21
%22 = load i32*, i32** %4
%23 = getelementptr inbounds i32, i32* %22, i64 4
%24 = call i32 @strncpy(i32* %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 10)
%25 = load i32*, i32** %4
%26 = call i32 @mdv_csum(i32* %25, i32 14)
%27 = load i32*, i32** %4
%28 = getelementptr inbounds i32, i32* %27, i64 14
store i32 %26, i32* %28
%29 = load i32*, i32** %4
%30 = getelementptr inbounds i32, i32* %29, i64 15
%31 = load i32*, i32** %6
%32 = call i32 @memcpy(i32* %30, i32* %31, i32 512)
%33 = load i32*, i32** %4
%34 = getelementptr inbounds i32, i32* %33, i64 15
%35 = call i32 @mdv_csum(i32* %34, i32 512)
%36 = load i32*, i32** %4
%37 = getelementptr inbounds i32, i32* %36, i64 527
store i32 %35, i32* %37
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"logical %d for %04x\0A\00"
@.str.1 = [11 x i8] c"FKERNEL.OS\00"
define void @mdv_make_bufhdr(i32* %0, i32 %1, i32* %2) {
%4 = shl i32 %1, 8
%5 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %4)
%6 = tail call i32 @memset(i32* %0, i32 0, i32 14)
store i32 0, i32* %0
%7 = getelementptr inbounds i32, i32* %0, i64 1
store i32 %1, i32* %7
%8 = getelementptr inbounds i32, i32* %0, i64 2
store i32 0, i32* %8
%9 = getelementptr inbounds i32, i32* %0, i64 3
store i32 2, i32* %9
%10 = getelementptr inbounds i32, i32* %0, i64 4
%11 = tail call i32 @strncpy(i32* %10, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 10)
%12 = tail call i32 @mdv_csum(i32* %0, i32 14)
%13 = getelementptr inbounds i32, i32* %0, i64 14
store i32 %12, i32* %13
%14 = getelementptr inbounds i32, i32* %0, i64 15
%15 = tail call i32 @memcpy(i32* %14, i32* %2, i32 512)
%16 = tail call i32 @mdv_csum(i32* %14, i32 512)
%17 = getelementptr inbounds i32, i32* %0, i64 527
store i32 %16, i32* %17
ret void
}