#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 */

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int errno;
int /*<<< orphan*/ exit(int);
int lseek(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, int);
int read(int, char *, int);
void read_block(int fd, char *buf, int blk, int blk_size) {
  int ret;
  ret = lseek(fd, blk * blk_size, SEEK_SET);
  if (ret != blk * blk_size) {
    printf("lseek: %d, errno: %d\n", ret, errno);
    exit(1);
  }
  ret = read(fd, buf, blk_size);
  if (ret != blk_size) {
    printf("ret: %d, errno: %d\n", ret, errno);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<read_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%esi
imul   -0x18(%rbp),%esi
mov    0x2e72(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x14(%rbp),%ecx
imul   -0x18(%rbp),%ecx
cmp    %ecx,%eax
je     11a4 <read_block+0x64>
mov    -0x1c(%rbp),%esi
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
lea    0xe6b(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     11e4 <read_block+0xa4>
mov    -0x1c(%rbp),%esi
mov    0x2e14(%rip),%rax
mov    (%rax),%edx
lea    0xe41(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_block>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %edi,%r15d
imul   %ecx,%ebp
mov    0x2e7d(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%esi
call   1040 <lseek@plt>
cmp    %ebp,%eax
jne    1184 <read_block+0x44>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <read@plt>
cmp    %ebx,%eax
jne    1196 <read_block+0x56>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e55(%rip),%rcx
mov    (%rcx),%edx
lea    0xe6c(%rip),%rdi
jmp    11a6 <read_block+0x66>
mov    0x2e43(%rip),%rcx
mov    (%rcx),%edx
lea    0xe70(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [22 x i8] c"lseek: %d, errno: %d\0A\00"
@errno = global i32 0
@.str.1 = [20 x i8] c"ret: %d, errno: %d\0A\00"
define void @read_block(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32, i32* %5
%11 = load i32, i32* %7
%12 = load i32, i32* %8
%13 = mul nsw i32 %11, %12
%14 = load i32, i32* @SEEK_SET
%15 = call i32 @lseek(i32 %10, i32 %13, i32 %14)
store i32 %15, i32* %9
%16 = load i32, i32* %9
%17 = load i32, i32* %7
%18 = load i32, i32* %8
%19 = mul nsw i32 %17, %18
%20 = icmp ne i32 %16, %19
br i1 %20, label %21, label %26
21: ; preds = %4
%22 = load i32, i32* %9
%23 = load i32, i32* @errno
%24 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %22, i32 %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %4
%27 = load i32, i32* %5
%28 = load i8*, i8** %6
%29 = load i32, i32* %8
%30 = call i32 @read(i32 %27, i8* %28, i32 %29)
store i32 %30, i32* %9
%31 = load i32, i32* %9
%32 = load i32, i32* %8
%33 = icmp ne i32 %31, %32
br i1 %33, label %34, label %39
34: ; preds = %26
%35 = load i32, i32* %9
%36 = load i32, i32* @errno
%37 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %35, i32 %36)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %26
ret void
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [22 x i8] c"lseek: %d, errno: %d\0A\00"
@errno = global i32 0
@.str.1 = [20 x i8] c"ret: %d, errno: %d\0A\00"
define void @read_block(i32 %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = mul nsw i32 %3, %2
%6 = load i32, i32* @SEEK_SET
%7 = tail call i32 @lseek(i32 %0, i32 %5, i32 %6)
%8 = icmp eq i32 %7, %5
br i1 %8, label %13, label %9
9: ; preds = %4
%10 = load i32, i32* @errno
%11 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %4
%14 = tail call i32 @read(i32 %0, i8* %1, i32 %3)
%15 = icmp eq i32 %14, %3
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = load i32, i32* @errno
%18 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %17)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %13
ret void
}