#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;
int /*<<< orphan*/ dump_s(char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int print_sect(char *name, int sect) {
  FILE *fp;
  char dat[512];
  int x;
  fp = fopen(name, "rb");
  if (fp == NULL) {
    perror(name);
    return 1;
  }
  fseek(fp, sect * 512, SEEK_SET);
  x = fread(dat, 1, 512, fp);
  fclose(fp);
  if (x > 0) {
    dump_s(dat, x);
  }
  return (0);
}


x86 assembly (clang, -O0):
<print_sect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a6 <print_sect+0x46>
mov    -0x10(%rbp),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    120d <print_sect+0xad>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
shl    $0x9,%esi
mov    0x2e29(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
lea    -0x220(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x200,%edx
call   1030 <fread@plt>
mov    %eax,-0x224(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
cmpl   $0x0,-0x224(%rbp)
jle    1206 <print_sect+0xa6>
lea    -0x220(%rbp),%rdi
mov    -0x224(%rbp),%esi
call   1050 <dump_s@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_sect>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d7 <print_sect+0x77>
mov    %rax,%rbx
shl    $0x9,%ebp
mov    0x2e52(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <fseek@plt>
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %ebx,%ebx
test   %ebp,%ebp
jle    11c9 <print_sect+0x69>
mov    %rsp,%rdi
mov    %ebp,%esi
call   1050 <dump_s@plt>
mov    %ebx,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %r14,%rdi
call   1080 <perror@plt>
mov    $0x1,%ebx
jmp    11c9 <print_sect+0x69>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_SET = global i32 0
define i32 @print_sect(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca [512 x i8]
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i32 @perror(i8* %14)
store i32 1, i32* %3
br label %34
16: ; preds = %2
%17 = load i32*, i32** %6
%18 = load i32, i32* %5
%19 = mul nsw i32 %18, 512
%20 = load i32, i32* @SEEK_SET
%21 = call i32 @fseek(i32* %17, i32 %19, i32 %20)
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%23 = load i32*, i32** %6
%24 = call i32 @fread(i8* %22, i32 1, i32 512, i32* %23)
store i32 %24, i32* %8
%25 = load i32*, i32** %6
%26 = call i32 @fclose(i32* %25)
%27 = load i32, i32* %8
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %16
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%31 = load i32, i32* %8
%32 = call i32 @dump_s(i8* %30, i32 %31)
br label %33
33: ; preds = %29, %16
store i32 0, i32* %3
br label %34
34: ; preds = %33, %13
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_SET = global i32 0
define i32 @print_sect(i8* nocapture %0, i32 %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @perror(i8* %0)
br label %18
9: ; preds = %2
%10 = shl nsw i32 %1, 9
%11 = load i32, i32* @SEEK_SET
%12 = tail call i32 @fseek(i32* %5, i32 %10, i32 %11)
%13 = call i32 @fread(i8* %4, i32 1, i32 512, i32* %5)
%14 = tail call i32 @fclose(i32* %5)
%15 = icmp sgt i32 %13, 0
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = call i32 @dump_s(i8* %4, i32 %13)
br label %18
18: ; preds = %9, %16, %7
%19 = phi i32 [ 1, %7 ], [ 0, %16 ], [ 0, %9 ]
ret i32 %19
}