#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 u_int32_t;
typedef int fsblocks;

/* Variables and functions */
int CHAR_BIT;
int /*<<< orphan*/ diskread(char *, int);
int /*<<< orphan*/ printf(char *, ...);
void dumpbits(u_int32_t fsblocks) {
  u_int32_t nblocks =
      (((((fsblocks) + ((512 * CHAR_BIT)) - 1) / ((512 * CHAR_BIT))) *
        (512 * CHAR_BIT)) /
       (512 * CHAR_BIT));
  u_int32_t i, j;
  char data[512];
  printf("Freemap: %u blocks (%u %u %u)\n", nblocks,
         ((((fsblocks) + ((512 * CHAR_BIT)) - 1) / ((512 * CHAR_BIT))) *
          (512 * CHAR_BIT)),
         fsblocks, (512 * CHAR_BIT));
  for (i = 0; i < nblocks; i++) {
    diskread(data, 2 + i);
    for (j = 0; j < 512; j++) {
      printf("%02x", (unsigned char)data[j]);
      if (j % 32 == 31) {
        printf("\n");
      }
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<dumpbits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2ea8(%rip),%rcx
mov    (%rcx),%ecx
shl    $0x9,%ecx
add    %ecx,%eax
sub    $0x1,%eax
mov    0x2e97(%rip),%rcx
mov    (%rcx),%ecx
shl    $0x9,%ecx
cltd
idiv   %ecx
mov    0x2e88(%rip),%rcx
mov    (%rcx),%ecx
shl    $0x9,%ecx
imul   %ecx,%eax
mov    0x2e79(%rip),%rcx
mov    (%rcx),%ecx
shl    $0x9,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x4(%rbp),%eax
mov    0x2e61(%rip),%rcx
mov    (%rcx),%ecx
shl    $0x9,%ecx
add    %ecx,%eax
sub    $0x1,%eax
mov    0x2e50(%rip),%rcx
mov    (%rcx),%ecx
shl    $0x9,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
shl    $0x9,%eax
imul   %eax,%edx
mov    -0x4(%rbp),%ecx
mov    0x2e2d(%rip),%rax
mov    (%rax),%r8d
shl    $0x9,%r8d
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1263 <dumpbits+0x143>
lea    -0x210(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x2,%esi
call   1040 <diskread@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x200,-0x10(%rbp)
jge    1250 <dumpbits+0x130>
movslq -0x10(%rbp),%rax
movzbl -0x210(%rbp,%rax,1),%esi
ff
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
cmp    $0x1f,%edx
jne    123d <dumpbits+0x11d>
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1242 <dumpbits+0x122>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11f4 <dumpbits+0xd4>
jmp    1255 <dumpbits+0x135>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11cf <dumpbits+0xaf>
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dumpbits>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %edi,%ecx
mov    0x2e98(%rip),%rax
mov    (%rax),%r8d
shl    $0x9,%r8d
lea    (%rcx,%r8,1),%ebx
add    $0xffffffff,%ebx
mov    %ebx,%eax
cltd
idiv   %r8d
mov    %eax,%r15d
sub    %edx,%ebx
lea    0xe98(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
test   %r15d,%r15d
jle    11df <dumpbits+0xaf>
mov    %rsp,%r14
lea    0xe9d(%rip),%rbx
xor    %r12d,%r12d
jmp    1199 <dumpbits+0x69>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r12d
cmp    %r15d,%r12d
je     11df <dumpbits+0xaf>
lea    0x2(%r12),%esi
mov    %r14,%rdi
call   1050 <diskread@plt>
xor    %ebp,%ebp
jmp    11bd <dumpbits+0x8d>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    $0x200,%rbp
je     1190 <dumpbits+0x60>
movzbl (%rsp,%rbp,1),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%eax
not    %eax
test   $0x1f,%al
jne    11b0 <dumpbits+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11b0 <dumpbits+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CHAR_BIT = global i32 0
@.str = [31 x i8] c"Freemap: %u blocks (%u %u %u)\0A\00"
@.str.1 = [5 x i8] c"%02x\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @dumpbits(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [512 x i8]
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = load i32, i32* @CHAR_BIT
%9 = mul nsw i32 512, %8
%10 = add nsw i32 %7, %9
%11 = sub nsw i32 %10, 1
%12 = load i32, i32* @CHAR_BIT
%13 = mul nsw i32 512, %12
%14 = sdiv i32 %11, %13
%15 = load i32, i32* @CHAR_BIT
%16 = mul nsw i32 512, %15
%17 = mul nsw i32 %14, %16
%18 = load i32, i32* @CHAR_BIT
%19 = mul nsw i32 512, %18
%20 = sdiv i32 %17, %19
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = load i32, i32* %2
%23 = load i32, i32* @CHAR_BIT
%24 = mul nsw i32 512, %23
%25 = add nsw i32 %22, %24
%26 = sub nsw i32 %25, 1
%27 = load i32, i32* @CHAR_BIT
%28 = mul nsw i32 512, %27
%29 = sdiv i32 %26, %28
%30 = load i32, i32* @CHAR_BIT
%31 = mul nsw i32 512, %30
%32 = mul nsw i32 %29, %31
%33 = load i32, i32* %2
%34 = load i32, i32* @CHAR_BIT
%35 = mul nsw i32 512, %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %32, i32 %33, i32 %35)
store i32 0, i32* %4
br label %37
37: ; preds = %66, %1
%38 = load i32, i32* %4
%39 = load i32, i32* %3
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %69
41: ; preds = %37
%42 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%43 = load i32, i32* %4
%44 = add nsw i32 2, %43
%45 = call i32 @diskread(i8* %42, i32 %44)
store i32 0, i32* %5
br label %46
46: ; preds = %62, %41
%47 = load i32, i32* %5
%48 = icmp slt i32 %47, 512
br i1 %48, label %49, label %65
49: ; preds = %46
%50 = load i32, i32* %5
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 %51
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %54)
%56 = load i32, i32* %5
%57 = srem i32 %56, 32
%58 = icmp eq i32 %57, 31
br i1 %58, label %59, label %61
59: ; preds = %49
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %61
61: ; preds = %59, %49
br label %62
62: ; preds = %61
%63 = load i32, i32* %5
%64 = add nsw i32 %63, 1
store i32 %64, i32* %5
br label %46
65: ; preds = %46
br label %66
66: ; preds = %65
%67 = load i32, i32* %4
%68 = add nsw i32 %67, 1
store i32 %68, i32* %4
br label %37
69: ; preds = %37
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@CHAR_BIT = global i32 0
@.str = [31 x i8] c"Freemap: %u blocks (%u %u %u)\0A\00"
@.str.1 = [5 x i8] c"%02x\00"
define void @dumpbits(i32 %0) {
%2 = alloca [512 x i8]
%3 = load i32, i32* @CHAR_BIT
%4 = shl nsw i32 %3, 9
%5 = add i32 %0, -1
%6 = add i32 %5, %4
%7 = sdiv i32 %6, %4
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%9 = srem i32 %6, %4
%10 = sub i32 %6, %9
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %10, i32 %0, i32 %4)
%12 = icmp sgt i32 %7, 0
br i1 %12, label %13, label %33
13: ; preds = %1, %30
%14 = phi i32 [ %31, %30 ], [ 0, %1 ]
%15 = add nuw nsw i32 %14, 2
%16 = call i32 @diskread(i8* %8, i32 %15)
br label %17
17: ; preds = %13, %27
%18 = phi i64 [ 0, %13 ], [ %28, %27 ]
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = and i64 %18, 31
%24 = icmp eq i64 %23, 31
br i1 %24, label %25, label %27
25: ; preds = %17
%26 = call i32 @putchar(i32 10)
br label %27
27: ; preds = %17, %25
%28 = add nuw nsw i64 %18, 1
%29 = icmp eq i64 %28, 512
br i1 %29, label %30, label %17
30: ; preds = %27
%31 = add nuw nsw i32 %14, 1
%32 = icmp eq i32 %31, %7
br i1 %32, label %33, label %13
33: ; preds = %30, %1
%34 = call i32 @putchar(i32 10)
ret void
}