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

/* Variables and functions */
scalar_t__ isprint(char const);
int /*<<< orphan*/ printf(char *, ...);
void display_mbr(const uint8_t *mbr, size_t len) {
  unsigned char c = 0;
  unsigned int i = 0, j = 0;
  printf("sizeof(MBR): %zu bytes\n", len);
  for (i = 0; i < len; i++) {
    if (!(i % 16))
      printf("%04d ", i);
    if (!(i % 8))
      printf(" ");
    c = mbr[i];
    printf("%02x ", c);
    if (!((i + 1) % 16)) {
      printf(" |");
      for (; j <= i; j++)
        printf("%c", isprint(mbr[j]) ? mbr[j] : '.');
      printf("|\n");
    }
  }
}


x86 assembly (clang, -O0):
<display_mbr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%rax
jae    126a <display_mbr+0x14a>
mov    -0x18(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    1188 <display_mbr+0x68>
mov    -0x18(%rbp),%esi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
and    $0x7,%eax
cmp    $0x0,%eax
jne    11a5 <display_mbr+0x85>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%esi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    1257 <display_mbr+0x137>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
ja     1249 <display_mbr+0x129>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     121d <display_mbr+0xfd>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x20(%rbp)
jmp    122a <display_mbr+0x10a>
mov    $0x2e,%eax
mov    %eax,-0x20(%rbp)
jmp    122a <display_mbr+0x10a>
mov    -0x20(%rbp),%esi
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e4 <display_mbr+0xc4>
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    125c <display_mbr+0x13c>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115b <display_mbr+0x3b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_mbr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xea8(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r14,%r14
je     1226 <display_mbr+0xe6>
lea    0xeaf(%rip),%r12
xor    %r15d,%r15d
xor    %r13d,%r13d
jmp    1198 <display_mbr+0x58>
nopw   0x0(%rax,%rax,1)
lea    0xe9e(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%r15d
cmp    %r14,%r15
jae    1226 <display_mbr+0xe6>
test   $0xf,%r15b
je     1200 <display_mbr+0xc0>
test   $0x7,%r15b
je     1217 <display_mbr+0xd7>
movzbl (%rbx,%r15,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x1(%r15),%ebp
test   $0xf,%bpl
jne    118c <display_mbr+0x4c>
lea    0xe60(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11de <display_mbr+0x9e>
nopl   (%rax)
movsbl (%rbx,%r13,1),%edi
call   1030 <putchar@plt>
add    $0x1,%r13d
cmp    %r15d,%r13d
ja     1180 <display_mbr+0x40>
mov    %r13d,%r13d
movsbl (%rbx,%r13,1),%edi
call   1060 <isprint@plt>
test   %rax,%rax
jne    11d0 <display_mbr+0x90>
mov    $0x2e,%edi
jmp    11d5 <display_mbr+0x95>
nopl   0x0(%rax)
lea    0xe11(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   $0x7,%r15b
jne    11a4 <display_mbr+0x64>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    11a4 <display_mbr+0x64>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"sizeof(MBR): %zu bytes\0A\00"
@.str.1 = [6 x i8] c"%04d \00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [6 x i8] c"%02x \00"
@.str.4 = [3 x i8] c" |\00"
@.str.5 = [3 x i8] c"%c\00"
@.str.6 = [3 x i8] c"|\0A\00"
define void @display_mbr(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
store i8 0, i8* %5
store i32 0, i32* %6
store i32 0, i32* %7
%8 = load i64, i64* %4
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %8)
store i32 0, i32* %6
br label %10
10: ; preds = %72, %2
%11 = load i32, i32* %6
%12 = zext i32 %11 to i64
%13 = load i64, i64* %4
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %75
15: ; preds = %10
%16 = load i32, i32* %6
%17 = urem i32 %16, 16
%18 = icmp ne i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = load i32, i32* %6
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %19, %15
%23 = load i32, i32* %6
%24 = urem i32 %23, 8
%25 = icmp ne i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %22
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %22
%29 = load i8*, i8** %3
%30 = load i32, i32* %6
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
store i8 %33, i8* %5
%34 = load i8, i8* %5
%35 = zext i8 %34 to i32
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %35)
%37 = load i32, i32* %6
%38 = add i32 %37, 1
%39 = urem i32 %38, 16
%40 = icmp ne i32 %39, 0
br i1 %40, label %71, label %41
41: ; preds = %28
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %43
43: ; preds = %66, %41
%44 = load i32, i32* %7
%45 = load i32, i32* %6
%46 = icmp ule i32 %44, %45
br i1 %46, label %47, label %69
47: ; preds = %43
%48 = load i8*, i8** %3
%49 = load i32, i32* %7
%50 = zext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = load i8, i8* %51
%53 = call i64 @isprint(i8 signext %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %62
55: ; preds = %47
%56 = load i8*, i8** %3
%57 = load i32, i32* %7
%58 = zext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
br label %63
62: ; preds = %47
br label %63
63: ; preds = %62, %55
%64 = phi i32 [ %61, %55 ], [ 46, %62 ]
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %64)
br label %66
66: ; preds = %63
%67 = load i32, i32* %7
%68 = add i32 %67, 1
store i32 %68, i32* %7
br label %43
69: ; preds = %43
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %71
71: ; preds = %69, %28
br label %72
72: ; preds = %71
%73 = load i32, i32* %6
%74 = add i32 %73, 1
store i32 %74, i32* %6
br label %10
75: ; preds = %10
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"sizeof(MBR): %zu bytes\0A\00"
@.str.1 = [6 x i8] c"%04d \00"
@.str.3 = [6 x i8] c"%02x \00"
@.str.4 = [3 x i8] c" |\00"
@str = [2 x i8] c"|\00"
define void @display_mbr(i8* nocapture %0, i64 %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %1)
%4 = icmp eq i64 %1, 0
br i1 %4, label %51, label %5
5: ; preds = %2, %47
%6 = phi i64 [ %49, %47 ], [ 0, %2 ]
%7 = phi i32 [ %48, %47 ], [ 0, %2 ]
%8 = trunc i64 %6 to i32
%9 = and i32 %8, 15
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %8)
br label %13
13: ; preds = %11, %5
%14 = and i32 %8, 7
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 @putchar(i32 32)
br label %18
18: ; preds = %16, %13
%19 = getelementptr inbounds i8, i8* %0, i64 %6
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = add i32 %8, 1
%24 = and i32 %23, 15
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %47
26: ; preds = %18
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%28 = icmp ugt i32 %7, %8
br i1 %28, label %44, label %29
29: ; preds = %26, %39
%30 = phi i32 [ %42, %39 ], [ %7, %26 ]
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %0, i64 %31
%33 = load i8, i8* %32
%34 = tail call i64 @isprint(i8 signext %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %29
%37 = load i8, i8* %32
%38 = sext i8 %37 to i32
br label %39
39: ; preds = %29, %36
%40 = phi i32 [ %38, %36 ], [ 46, %29 ]
%41 = tail call i32 @putchar(i32 %40)
%42 = add i32 %30, 1
%43 = icmp ugt i32 %42, %8
br i1 %43, label %44, label %29
44: ; preds = %39, %26
%45 = phi i32 [ %7, %26 ], [ %42, %39 ]
%46 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %47
47: ; preds = %18, %44
%48 = phi i32 [ %7, %18 ], [ %45, %44 ]
%49 = zext i32 %23 to i64
%50 = icmp ult i64 %49, %1
br i1 %50, label %5, label %51
51: ; preds = %47, %2
ret void
}