#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 /*<<< orphan*/ SEEK_SET;
unsigned int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(unsigned char **, int, int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
char getopt(int, char **, char *);
char *optarg;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ printusage(int, char **);
int main(int argc, char *argv[]) {
  FILE *fp;
  unsigned int blknum, i;
  unsigned char block[512];
  char c;
  blknum = 0;
  if (argc != 5) {
    printusage(argc, argv);
    exit(0);
  }
  while ((c = getopt(argc, argv, "n:f:h")) != -1) {
    switch (c) {
    case 'n':
      blknum = atoi(optarg);
      break;
    case 'f':
      fp = fopen(optarg, "r");
      if (fp == NULL) {
        printf("Could not open file: '%s'\n", optarg);
        exit(1);
      }
      break;
    case 'h':
      printusage(argc, argv);
      exit(0);
      break;
    }
  }
  if (fp == NULL) {
    printf("Must specify filename!\n");
    exit(1);
  }
  if (fseek(fp, 512 * blknum, SEEK_SET) < 0) {
    printf("Error seeking to block no. %d!\n", blknum);
    fclose(fp);
    exit(1);
  }
  if (fread(&block, 512, 1, fp) != 1) {
    printf("Error reading block no. %d!\n", blknum);
    fclose(fp);
    exit(1);
  }
  for (i = 0; i < 512; i++) {
    if ((i % 16) == 0)
      printf("\n");
    printf("%02x ", block[i]);
  }
  printf("\n");
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     11cd <main+0x3d>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <printusage@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
jmp    11d2 <main+0x42>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe20(%rip),%rdx
call   1090 <getopt@plt>
mov    %al,-0x221(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     12b5 <main+0x125>
movsbl -0x221(%rbp),%eax
mov    %eax,-0x228(%rbp)
sub    $0x66,%eax
je     1251 <main+0xc1>
jmp    1212 <main+0x82>
mov    -0x228(%rbp),%eax
sub    $0x68,%eax
je     129d <main+0x10d>
jmp    1226 <main+0x96>
mov    -0x228(%rbp),%eax
sub    $0x6e,%eax
jne    12b0 <main+0x120>
jmp    123a <main+0xaa>
mov    0x2db7(%rip),%rax
mov    (%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    12b0 <main+0x120>
mov    0x2da0(%rip),%rax
mov    (%rax),%rdi
lea    0xda4(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1298 <main+0x108>
mov    0x2d7b(%rip),%rax
mov    (%rax),%rsi
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    12b0 <main+0x120>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <printusage@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
jmp    11d2 <main+0x42>
cmpq   $0x0,-0x18(%rbp)
jne    12d8 <main+0x148>
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
shl    $0x9,%esi
mov    0x2cef(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
cmp    $0x0,%rax
jge    131e <main+0x18e>
mov    -0x1c(%rbp),%esi
lea    0xd37(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x200,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     1365 <main+0x1d5>
mov    -0x1c(%rbp),%esi
lea    0xd10(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movl   $0x0,-0x20(%rbp)
cmpl   $0x200,-0x20(%rbp)
jae    13bd <main+0x22d>
mov    -0x20(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    1396 <main+0x206>
lea    0xce7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%eax
movzbl -0x220(%rbp,%rax,1),%esi
ff
lea    0xcd0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    136c <main+0x1dc>
lea    0xcb2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%rbp
cmp    $0x5,%edi
jne    1337 <main+0x187>
lea    0xe2c(%rip),%rdx
mov    $0x5,%edi
mov    %rbp,%rsi
call   10b0 <getopt@plt>
cmp    $0xff,%al
je     1346 <main+0x196>
xor    %r14d,%r14d
mov    0x2e05(%rip),%r13
lea    0xe0c(%rip),%rbx
lea    0xdff(%rip),%r12
jmp    1230 <main+0x80>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x0(%r13),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r14d
mov    $0x5,%edi
mov    %rbp,%rsi
mov    %r12,%rdx
call   10b0 <getopt@plt>
cmp    $0xff,%al
je     1280 <main+0xd0>
movsbl %al,%eax
cmp    $0x66,%eax
je     1250 <main+0xa0>
cmp    $0x6e,%eax
je     1210 <main+0x60>
cmp    $0x68,%eax
jne    121c <main+0x6c>
jmp    1332 <main+0x182>
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13),%rdi
mov    %rbx,%rsi
call   10a0 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    121c <main+0x6c>
mov    0x0(%r13),%rsi
lea    0xd99(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
test   %r15,%r15
je     1346 <main+0x196>
mov    %r14d,%esi
shl    $0x9,%esi
mov    0x2d42(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
call   1090 <fseek@plt>
test   %rax,%rax
js     135c <main+0x1ac>
mov    %rsp,%rdi
mov    $0x200,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1050 <fread@plt>
cmp    $0x1,%eax
jne    1365 <main+0x1b5>
lea    0xd92(%rip),%rbp
xor    %ebx,%ebx
jmp    12fb <main+0x14b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rsp,%rbx,1),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%rbx
cmp    $0x200,%rbx
je     130c <main+0x15c>
test   $0xf,%bl
jne    12e0 <main+0x130>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    12e0 <main+0x130>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x5,%edi
mov    %rbp,%rsi
call   1080 <printusage@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
lea    0xd19(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xcc0(%rip),%rdi
jmp    136c <main+0x1bc>
lea    0xcd7(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"n:f:h\00"
@optarg = global i8* null
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [27 x i8] c"Could not open file: '%s'\0A\00"
@.str.3 = [24 x i8] c"Must specify filename!\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [32 x i8] c"Error seeking to block no. %d!\0A\00"
@.str.5 = [29 x i8] c"Error reading block no. %d!\0A\00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [6 x i8] c"%02x \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [512 x i8]
%10 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 5
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* %4
%15 = load i8**, i8*** %5
%16 = call i32 @printusage(i32 %14, i8** %15)
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %2
br label %19
19: ; preds = %46, %18
%20 = load i32, i32* %4
%21 = load i8**, i8*** %5
%22 = call signext i8 @getopt(i32 %20, i8** %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8 %22, i8* %10
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, -1
br i1 %24, label %25, label %47
25: ; preds = %19
%26 = load i8, i8* %10
%27 = sext i8 %26 to i32
switch i32 %27, label %46 [
i32 110, label %28
i32 102, label %31
i32 104, label %41
]
28: ; preds = %25
%29 = load i8*, i8** @optarg
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %7
br label %46
31: ; preds = %25
%32 = load i8*, i8** @optarg
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %33, i32** %6
%34 = load i32*, i32** %6
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %40
36: ; preds = %31
%37 = load i8*, i8** @optarg
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %31
br label %46
41: ; preds = %25
%42 = load i32, i32* %4
%43 = load i8**, i8*** %5
%44 = call i32 @printusage(i32 %42, i8** %43)
%45 = call i32 @exit(i32 0)
unreachable
46: ; preds = %25, %40, %28
br label %19
47: ; preds = %19
%48 = load i32*, i32** %6
%49 = icmp eq i32* %48, null
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %47
%54 = load i32*, i32** %6
%55 = load i32, i32* %7
%56 = mul i32 512, %55
%57 = load i32, i32* @SEEK_SET
%58 = call i64 @fseek(i32* %54, i32 %56, i32 %57)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %66
60: ; preds = %53
%61 = load i32, i32* %7
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %61)
%63 = load i32*, i32** %6
%64 = call i32 @fclose(i32* %63)
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %53
%67 = bitcast [512 x i8]* %9 to i8**
%68 = load i32*, i32** %6
%69 = call i32 @fread(i8** %67, i32 512, i32 1, i32* %68)
%70 = icmp ne i32 %69, 1
br i1 %70, label %71, label %77
71: ; preds = %66
%72 = load i32, i32* %7
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %72)
%74 = load i32*, i32** %6
%75 = call i32 @fclose(i32* %74)
%76 = call i32 @exit(i32 1)
unreachable
77: ; preds = %66
store i32 0, i32* %8
br label %78
78: ; preds = %94, %77
%79 = load i32, i32* %8
%80 = icmp ult i32 %79, 512
br i1 %80, label %81, label %97
81: ; preds = %78
%82 = load i32, i32* %8
%83 = urem i32 %82, 16
%84 = icmp eq i32 %83, 0
br i1 %84, label %85, label %87
85: ; preds = %81
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %87
87: ; preds = %85, %81
%88 = load i32, i32* %8
%89 = zext i32 %88 to i64
%90 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 %89
%91 = load i8, i8* %90
%92 = zext i8 %91 to i32
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %92)
br label %94
94: ; preds = %87
%95 = load i32, i32* %8
%96 = add i32 %95, 1
store i32 %96, i32* %8
br label %78
97: ; preds = %78
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%99 = load i32*, i32** %6
%100 = call i32 @fclose(i32* %99)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"n:f:h\00"
@optarg = global i8* null
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [27 x i8] c"Could not open file: '%s'\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [32 x i8] c"Error seeking to block no. %d!\0A\00"
@.str.5 = [29 x i8] c"Error reading block no. %d!\0A\00"
@.str.7 = [6 x i8] c"%02x \00"
@str = [23 x i8] c"Must specify filename!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 5
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call signext i8 @getopt(i32 5, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8 %7, -1
br i1 %8, label %38, label %12
9: ; preds = %2
%10 = tail call i32 @printusage(i32 %0, i8** %1)
%11 = tail call i32 @exit(i32 0)
unreachable
12: ; preds = %6, %31
%13 = phi i8 [ %34, %31 ], [ %7, %6 ]
%14 = phi i32* [ %33, %31 ], [ undef, %6 ]
%15 = phi i32 [ %32, %31 ], [ 0, %6 ]
%16 = sext i8 %13 to i32
switch i32 %16, label %31 [
i32 110, label %17
i32 102, label %20
i32 104, label %28
]
17: ; preds = %12
%18 = load i8*, i8** @optarg
%19 = tail call i32 @atoi(i8* %18)
br label %31
20: ; preds = %12
%21 = load i8*, i8** @optarg
%22 = tail call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %31
24: ; preds = %20
%25 = load i8*, i8** @optarg
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %12
%29 = tail call i32 @printusage(i32 5, i8** %1)
%30 = tail call i32 @exit(i32 0)
unreachable
31: ; preds = %20, %12, %17
%32 = phi i32 [ %15, %12 ], [ %15, %20 ], [ %19, %17 ]
%33 = phi i32* [ %14, %12 ], [ %22, %20 ], [ %14, %17 ]
%34 = tail call signext i8 @getopt(i32 5, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%35 = icmp eq i8 %34, -1
br i1 %35, label %36, label %12
36: ; preds = %31
%37 = icmp eq i32* %33, null
br i1 %37, label %38, label %41
38: ; preds = %6, %36
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%40 = tail call i32 @exit(i32 1)
unreachable
41: ; preds = %36
%42 = shl i32 %32, 9
%43 = load i32, i32* @SEEK_SET
%44 = tail call i64 @fseek(i32* %33, i32 %42, i32 %43)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %41
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%48 = tail call i32 @fclose(i32* %33)
%49 = tail call i32 @exit(i32 1)
unreachable
50: ; preds = %41
%51 = bitcast [512 x i8]* %3 to i8**
%52 = call i32 @fread(i8** %51, i32 512, i32 1, i32* %33)
%53 = icmp eq i32 %52, 1
br i1 %53, label %58, label %54
54: ; preds = %50
%55 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %32)
%56 = tail call i32 @fclose(i32* %33)
%57 = tail call i32 @exit(i32 1)
unreachable
58: ; preds = %50, %64
%59 = phi i64 [ %69, %64 ], [ 0, %50 ]
%60 = and i64 %59, 15
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %58
%63 = tail call i32 @putchar(i32 10)
br label %64
64: ; preds = %62, %58
%65 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %59
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
%68 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %67)
%69 = add nuw nsw i64 %59, 1
%70 = icmp eq i64 %69, 512
br i1 %70, label %71, label %58
71: ; preds = %64
%72 = tail call i32 @putchar(i32 10)
%73 = tail call i32 @fclose(i32* %33)
ret i32 0
}