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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(void *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int sd_receive(void *data, uint32_t addr) {
  FILE *f = fopen("card.sd", "r+");
  fseek(f, addr, SEEK_SET);
  fread(data, 1, 512, f);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<sd_receive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2e6c(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x200,%edx
call   1030 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sd_receive>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xeb0(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <fseek@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"card.sd\00"
@.str.1 = [3 x i8] c"r+\00"
@SEEK_SET = global i32 0
define i32 @sd_receive(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %5
%7 = load i32*, i32** %5
%8 = load i32, i32* %4
%9 = load i32, i32* @SEEK_SET
%10 = call i32 @fseek(i32* %7, i32 %8, i32 %9)
%11 = load i8*, i8** %3
%12 = load i32*, i32** %5
%13 = call i32 @fread(i8* %11, i32 1, i32 512, i32* %12)
%14 = load i32*, i32** %5
%15 = call i32 @fclose(i32* %14)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"card.sd\00"
@.str.1 = [3 x i8] c"r+\00"
@SEEK_SET = global i32 0
define i32 @sd_receive(i8* nocapture %0, i32 %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = load i32, i32* @SEEK_SET
%5 = tail call i32 @fseek(i32* %3, i32 %1, i32 %4)
%6 = tail call i32 @fread(i8* %0, i32 1, i32 512, i32* %3)
%7 = tail call i32 @fclose(i32* %3)
ret i32 0
}