#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 uint32_t;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
void write_cluster(int fatFd, int outFd, uint32_t base_address,
                   uint16_t cluster, uint32_t cluster_size,
                   uint32_t write_size) {
  lseek(fatFd, base_address + cluster_size * (cluster - 2), SEEK_SET);
  char *buff = malloc(cluster_size * sizeof *buff);
  read(fatFd, buff, cluster_size);
  write(outFd, buff, write_size);
}


x86 assembly (clang, -O0):
<write_cluster>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
mov    %r9d,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x2,%ecx
imul   %ecx,%eax
add    %eax,%esi
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <read@plt>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <write@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_cluster>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r9d,%r14d
mov    %r8d,%ebp
mov    %esi,%r15d
mov    %edi,%r12d
lea    -0x2(%rcx),%esi
imul   %r8d,%esi
add    %edx,%esi
mov    0x2e7c(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %r12d,%edi
mov    %rax,%rsi
mov    %ebp,%edx
call   1050 <read@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <write@plt>

LLVM IR (-O0):
@SEEK_SET = global i32 0
define void @write_cluster(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%14 = load i32, i32* %7
%15 = load i32, i32* %9
%16 = load i32, i32* %11
%17 = load i32, i32* %10
%18 = sub nsw i32 %17, 2
%19 = mul nsw i32 %16, %18
%20 = add nsw i32 %15, %19
%21 = load i32, i32* @SEEK_SET
%22 = call i32 @lseek(i32 %14, i32 %20, i32 %21)
%23 = load i32, i32* %11
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 1
%26 = trunc i64 %25 to i32
%27 = call i8* @malloc(i32 %26)
store i8* %27, i8** %13
%28 = load i32, i32* %7
%29 = load i8*, i8** %13
%30 = load i32, i32* %11
%31 = call i32 @read(i32 %28, i8* %29, i32 %30)
%32 = load i32, i32* %8
%33 = load i8*, i8** %13
%34 = load i32, i32* %12
%35 = call i32 @write(i32 %32, i8* %33, i32 %34)
ret void
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define void @write_cluster(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = add nsw i32 %3, -2
%8 = mul nsw i32 %7, %4
%9 = add nsw i32 %8, %2
%10 = load i32, i32* @SEEK_SET
%11 = tail call i32 @lseek(i32 %0, i32 %9, i32 %10)
%12 = tail call i8* @malloc(i32 %4)
%13 = tail call i32 @read(i32 %0, i8* %12, i32 %4)
%14 = tail call i32 @write(i32 %1, i8* %12, i32 %5)
ret void
}