#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, unsigned long,
                         int /*<<< orphan*/);
scalar_t__ isprint(int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
void printHex(FILE *pSrc, unsigned long page) {
  int c;
  unsigned hexIndex = 0, printablesIndex = 0, readBytes = 0;
  char currentLine[80];
  fseek(pSrc, page * 19 * 16, 0);
  memset(currentLine, ' ', 80);
  currentLine[80 - 1] = '\0';
  for (;;) {
    c = fgetc(pSrc);
    ++readBytes;
    if (c != EOF) {
      sprintf(currentLine + hexIndex, " %02x", c);
      currentLine[hexIndex + 3] = ' ';
      if (isprint(c))
        currentLine[48 + 15 + printablesIndex++] = c;
      else
        currentLine[48 + 15 + printablesIndex++] = '.';
      hexIndex += 3;
    }
    if (printablesIndex == 16 || c == EOF) {
      puts(currentLine);
      if (c == EOF)
        break;
      hexIndex = 0;
      printablesIndex = 0;
      memset(currentLine, ' ', 80);
      currentLine[80 - 1] = '\0';
    }
    if (readBytes == 19 * 16)
      break;
  }
}


x86 assembly (clang, -O0):
<printHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
imul   $0x13,-0x10(%rbp),%rsi
shl    $0x4,%rsi
xor    %edx,%edx
call   1060 <fseek@plt>
lea    -0x70(%rbp),%rdi
mov    $0x20,%esi
mov    $0x50,%edx
call   1040 <memset@plt>
movb   $0x0,-0x21(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%eax
je     124b <printHex+0xeb>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%eax
add    %rax,%rdi
mov    -0x14(%rbp),%edx
lea    0xe15(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x3,%eax
mov    %eax,%eax
movb   $0x20,-0x70(%rbp,%rax,1)
mov    -0x14(%rbp),%edi
call   1070 <isprint@plt>
cmp    $0x0,%rax
je     122d <printHex+0xcd>
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x1c(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
add    $0x3f,%eax
mov    %eax,%eax
mov    %cl,-0x70(%rbp,%rax,1)
jmp    1242 <printHex+0xe2>
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
add    $0x3f,%eax
mov    %eax,%eax
movb   $0x2e,-0x70(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x10,-0x1c(%rbp)
je     1267 <printHex+0x107>
mov    -0x14(%rbp),%eax
mov    0x2d89(%rip),%rcx
cmp    (%rcx),%eax
jne    12ac <printHex+0x14c>
lea    -0x70(%rbp),%rdi
call   1030 <puts@plt>
mov    -0x14(%rbp),%eax
mov    0x2d6e(%rip),%rcx
cmp    (%rcx),%eax
jne    1287 <printHex+0x127>
jmp    12c3 <printHex+0x163>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x70(%rbp),%rdi
mov    $0x20,%esi
mov    $0x50,%edx
call   1040 <memset@plt>
movb   $0x0,-0x21(%rbp)
cmpl   $0x130,-0x20(%rbp)
jne    12be <printHex+0x15e>
jmp    12c3 <printHex+0x163>
jmp    11b0 <printHex+0x50>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printHex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%r12
imul   $0x130,%rsi,%rsi
xor    %r13d,%r13d
xor    %edx,%edx
call   1060 <fseek@plt>
mov    %rsp,%rdi
mov    $0x20,%esi
mov    $0x50,%edx
call   1040 <memset@plt>
movb   $0x0,0x4f(%rsp)
mov    $0x130,%ebx
mov    0x2e43(%rip),%r15
xor    %r14d,%r14d
jmp    11b9 <printHex+0x59>
nopw   0x0(%rax,%rax,1)
add    $0xffffffff,%ebx
je     123f <printHex+0xdf>
mov    %r12,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebp
cmp    (%r15),%eax
je     1210 <printHex+0xb0>
mov    %r13d,%eax
lea    (%rsp,%rax,1),%rdi
lea    0xe2a(%rip),%rsi
mov    %ebp,%edx
call   1080 <sprintf@plt>
add    $0x3,%r13d
movb   $0x20,(%rsp,%r13,1)
mov    %ebp,%edi
call   1070 <isprint@plt>
test   %rax,%rax
mov    %ebp,%eax
mov    $0x2e,%ecx
cmove  %ecx,%eax
lea    0x3f(%r14),%ecx
mov    %al,(%rsp,%rcx,1)
add    $0x1,%r14d
cmp    $0x10,%r14d
je     1210 <printHex+0xb0>
cmp    (%r15),%ebp
jne    11b0 <printHex+0x50>
mov    %rsp,%rdi
call   1030 <puts@plt>
cmp    (%r15),%ebp
je     123f <printHex+0xdf>
mov    %rsp,%rdi
mov    $0x20,%esi
mov    $0x50,%edx
call   1040 <memset@plt>
movb   $0x0,0x4f(%rsp)
xor    %r13d,%r13d
xor    %r14d,%r14d
jmp    11b0 <printHex+0x50>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [6 x i8] c" %02x\00"
define void @printHex(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [80 x i8]
store i32* %0, i32** %3
store i64 %1, i64* %4
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%10 = load i32*, i32** %3
%11 = load i64, i64* %4
%12 = mul i64 %11, 19
%13 = mul i64 %12, 16
%14 = call i32 @fseek(i32* %10, i64 %13, i32 0)
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%16 = call i32 @memset(i8* %15, i8 signext 32, i32 80)
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 79
store i8 0, i8* %17
br label %18
18: ; preds = %79, %2
%19 = load i32*, i32** %3
%20 = call i32 @fgetc(i32* %19)
store i32 %20, i32* %5
%21 = load i32, i32* %8
%22 = add i32 %21, 1
store i32 %22, i32* %8
%23 = load i32, i32* %5
%24 = load i32, i32* @EOF
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %57
26: ; preds = %18
%27 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%28 = load i32, i32* %6
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i32, i32* %5
%32 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %6
%34 = add i32 %33, 3
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 %35
store i8 32, i8* %36
%37 = load i32, i32* %5
%38 = call i64 @isprint(i32 %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %48
40: ; preds = %26
%41 = load i32, i32* %5
%42 = trunc i32 %41 to i8
%43 = load i32, i32* %7
%44 = add i32 %43, 1
store i32 %44, i32* %7
%45 = add i32 63, %43
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 %46
store i8 %42, i8* %47
br label %54
48: ; preds = %26
%49 = load i32, i32* %7
%50 = add i32 %49, 1
store i32 %50, i32* %7
%51 = add i32 63, %49
%52 = zext i32 %51 to i64
%53 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 %52
store i8 46, i8* %53
br label %54
54: ; preds = %48, %40
%55 = load i32, i32* %6
%56 = add i32 %55, 3
store i32 %56, i32* %6
br label %57
57: ; preds = %54, %18
%58 = load i32, i32* %7
%59 = icmp eq i32 %58, 16
br i1 %59, label %64, label %60
60: ; preds = %57
%61 = load i32, i32* %5
%62 = load i32, i32* @EOF
%63 = icmp eq i32 %61, %62
br i1 %63, label %64, label %75
64: ; preds = %60, %57
%65 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%66 = call i32 @puts(i8* %65)
%67 = load i32, i32* %5
%68 = load i32, i32* @EOF
%69 = icmp eq i32 %67, %68
br i1 %69, label %70, label %71
70: ; preds = %64
br label %80
71: ; preds = %64
store i32 0, i32* %6
store i32 0, i32* %7
%72 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%73 = call i32 @memset(i8* %72, i8 signext 32, i32 80)
%74 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 79
store i8 0, i8* %74
br label %75
75: ; preds = %71, %60
%76 = load i32, i32* %8
%77 = icmp eq i32 %76, 304
br i1 %77, label %78, label %79
78: ; preds = %75
br label %80
79: ; preds = %75
br label %18
80: ; preds = %78, %70
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [6 x i8] c" %02x\00"
define void @printHex(i32* nocapture %0, i64 %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = mul i64 %1, 304
%6 = tail call i32 @fseek(i32* %0, i64 %5, i32 0)
%7 = call i32 @memset(i8* %4, i8 signext 32, i32 80)
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 79
store i8 0, i8* %8
br label %9
9: ; preds = %42, %2
%10 = phi i32 [ 0, %2 ], [ %43, %42 ]
%11 = phi i32 [ 0, %2 ], [ %44, %42 ]
%12 = phi i32 [ 0, %2 ], [ %14, %42 ]
%13 = call i32 @fgetc(i32* %0)
%14 = add nuw nsw i32 %12, 1
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %13, %15
br i1 %16, label %36, label %17
17: ; preds = %9
%18 = zext i32 %10 to i64
%19 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %18
%20 = call i32 @sprintf(i8* %19, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %13)
%21 = add i32 %10, 3
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %22
store i8 32, i8* %23
%24 = call i64 @isprint(i32 %13)
%25 = icmp eq i64 %24, 0
%26 = trunc i32 %13 to i8
%27 = select i1 %25, i8 46, i8 %26
%28 = add i32 %11, 63
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %29
store i8 %27, i8* %30
%31 = add i32 %11, 1
%32 = load i32, i32* @EOF
%33 = icmp eq i32 %31, 16
%34 = icmp eq i32 %13, %32
%35 = select i1 %33, i1 true, i1 %34
br i1 %35, label %36, label %42
36: ; preds = %9, %17
%37 = call i32 @puts(i8* %4)
%38 = load i32, i32* @EOF
%39 = icmp eq i32 %13, %38
br i1 %39, label %46, label %40
40: ; preds = %36
%41 = call i32 @memset(i8* %4, i8 signext 32, i32 80)
store i8 0, i8* %8
br label %42
42: ; preds = %17, %40
%43 = phi i32 [ 0, %40 ], [ %21, %17 ]
%44 = phi i32 [ 0, %40 ], [ %31, %17 ]
%45 = icmp eq i32 %14, 304
br i1 %45, label %46, label %9
46: ; preds = %42, %36
ret void
}