#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*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, unsigned int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int read(int, unsigned char *, int);
void emmc_read_block(unsigned block, unsigned char *buf) {
  int fd = open("/dev/sdb", O_RDONLY);
  lseek(fd, block * 512, SEEK_SET);
  int r = read(fd, buf, 512);
  if (r != 512)
    printf("Read failed! Got %d bytes!\n", r);
  close(fd);
}


x86 assembly (clang, -O0):
<emmc_read_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x4(%rbp),%esi
shl    $0x9,%esi
mov    0x2e51(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x200,%edx
call   1060 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x200,-0x18(%rbp)
je     11be <emmc_read_block+0x6e>
mov    -0x18(%rbp),%esi
lea    0xe50(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<emmc_read_block>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
lea    0xe97(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
shl    $0x9,%ebp
mov    0x2e5e(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %ebp,%esi
call   1040 <lseek@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x200,%edx
call   1060 <read@plt>
cmp    $0x200,%eax
je     11a9 <emmc_read_block+0x59>
lea    0xe67(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %ebx,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <close@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/sdb\00"
@O_RDONLY = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [28 x i8] c"Read failed! Got %d bytes!\0A\00"
define void @emmc_read_block(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = load i32, i32* %3
%11 = mul i32 %10, 512
%12 = load i32, i32* @SEEK_SET
%13 = call i32 @lseek(i32 %9, i32 %11, i32 %12)
%14 = load i32, i32* %5
%15 = load i8*, i8** %4
%16 = call i32 @read(i32 %14, i8* %15, i32 512)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp ne i32 %17, 512
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = load i32, i32* %6
%21 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %19, %2
%23 = load i32, i32* %5
%24 = call i32 @close(i32 %23)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/sdb\00"
@O_RDONLY = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [28 x i8] c"Read failed! Got %d bytes!\0A\00"
define void @emmc_read_block(i32 %0, i8* nocapture %1) {
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = shl i32 %0, 9
%6 = load i32, i32* @SEEK_SET
%7 = tail call i32 @lseek(i32 %4, i32 %5, i32 %6)
%8 = tail call i32 @read(i32 %4, i8* %1, i32 512)
%9 = icmp eq i32 %8, 512
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %8)
br label %12
12: ; preds = %10, %2
%13 = tail call i32 @close(i32 %4)
ret void
}