#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;

/* Variables and functions */
int checksum(int *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ rand();
int /*<<< orphan*/ write16(int *, int /*<<< orphan*/);
int /*<<< orphan*/ write24(int *, int);
void setup_freemap(uint8_t *base, int sectors) {
  int free_sect = sectors - (5 + 2);
  base[0x000] = (5 + 2);
  write24(base + 0x0fc, sectors);
  base[0x0ff] = checksum(base);
  putchar('\n');
  write24(base + 0x100, free_sect);
  write16(base + 0x1fb, rand());
  base[0x1fe] = 3;
  base[0x1ff] = checksum(base + 0x100);
}


x86 assembly (clang, -O0):
<setup_freemap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x7,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movl   $0x7,(%rax)
mov    -0x8(%rbp),%rdi
add    $0x3f0,%rdi
mov    -0xc(%rbp),%esi
call   1050 <write24@plt>
mov    -0x8(%rbp),%rdi
call   1040 <checksum@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x3fc(%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x8(%rbp),%rdi
add    $0x400,%rdi
mov    -0x10(%rbp),%esi
call   1050 <write24@plt>
mov    -0x8(%rbp),%rax
add    $0x7ec,%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%esi
call   1070 <write16@plt>
mov    -0x8(%rbp),%rax
movl   $0x3,0x7f8(%rax)
mov    -0x8(%rbp),%rdi
add    $0x400,%rdi
call   1040 <checksum@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x7fc(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_freemap>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    -0x7(%rsi),%r14d
movl   $0x7,(%rdi)
add    $0x3f0,%rdi
call   1050 <write24@plt>
mov    %rbx,%rdi
call   1040 <checksum@plt>
mov    %eax,0x3fc(%rbx)
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x400(%rbx),%rbp
mov    %rbp,%rdi
mov    %r14d,%esi
call   1050 <write24@plt>
lea    0x7ec(%rbx),%r14
xor    %eax,%eax
call   1060 <rand@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1070 <write16@plt>
movl   $0x3,0x7f8(%rbx)
mov    %rbp,%rdi
call   1040 <checksum@plt>
mov    %eax,0x7fc(%rbx)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @setup_freemap(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = sub nsw i32 %6, 7
store i32 %7, i32* %5
%8 = load i32*, i32** %3
%9 = getelementptr inbounds i32, i32* %8, i64 0
store i32 7, i32* %9
%10 = load i32*, i32** %3
%11 = getelementptr inbounds i32, i32* %10, i64 252
%12 = load i32, i32* %4
%13 = call i32 @write24(i32* %11, i32 %12)
%14 = load i32*, i32** %3
%15 = call i32 @checksum(i32* %14)
%16 = load i32*, i32** %3
%17 = getelementptr inbounds i32, i32* %16, i64 255
store i32 %15, i32* %17
%18 = call i32 @putchar(i8 signext 10)
%19 = load i32*, i32** %3
%20 = getelementptr inbounds i32, i32* %19, i64 256
%21 = load i32, i32* %5
%22 = call i32 @write24(i32* %20, i32 %21)
%23 = load i32*, i32** %3
%24 = getelementptr inbounds i32, i32* %23, i64 507
%25 = call i32 (...) @rand()
%26 = call i32 @write16(i32* %24, i32 %25)
%27 = load i32*, i32** %3
%28 = getelementptr inbounds i32, i32* %27, i64 510
store i32 3, i32* %28
%29 = load i32*, i32** %3
%30 = getelementptr inbounds i32, i32* %29, i64 256
%31 = call i32 @checksum(i32* %30)
%32 = load i32*, i32** %3
%33 = getelementptr inbounds i32, i32* %32, i64 511
store i32 %31, i32* %33
ret void
}

LLVM IR (-O2):
define void @setup_freemap(i32* %0, i32 %1) {
%3 = add nsw i32 %1, -7
store i32 7, i32* %0
%4 = getelementptr inbounds i32, i32* %0, i64 252
%5 = tail call i32 @write24(i32* %4, i32 %1)
%6 = tail call i32 @checksum(i32* %0)
%7 = getelementptr inbounds i32, i32* %0, i64 255
store i32 %6, i32* %7
%8 = tail call i32 @putchar(i8 signext 10)
%9 = getelementptr inbounds i32, i32* %0, i64 256
%10 = tail call i32 @write24(i32* %9, i32 %3)
%11 = getelementptr inbounds i32, i32* %0, i64 507
%12 = tail call i32 (...) @rand()
%13 = tail call i32 @write16(i32* %11, i32 %12)
%14 = getelementptr inbounds i32, i32* %0, i64 510
store i32 3, i32* %14
%15 = tail call i32 @checksum(i32* %9)
%16 = getelementptr inbounds i32, i32* %0, i64 511
store i32 %15, i32* %16
ret void
}