#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 div(int, int);
int /*<<< orphan*/ interrupt(int, int, char *, int, scalar_t__);
int mod(int, int);
void readWriteSector(char *buffer, int sector, int readWrite) {
  int q;
  int trackNumber = div(sector, 36);
  int realativeSectorNumber = mod(sector, 18) + 1;
  int headNumber = mod(div(sector, 18), 2);
  interrupt(0x13, readWrite * 256 + 1, buffer,
            trackNumber * 256 + realativeSectorNumber, headNumber * 256 + 0);
  return;
}


x86 assembly (clang, -O0):
<readWriteSector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x24,%esi
call   1050 <div@plt>
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x12,%esi
call   1030 <mod@plt>
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x12,%esi
call   1050 <div@plt>
mov    %eax,%edi
mov    $0x2,%esi
call   1030 <mod@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%esi
shl    $0x8,%esi
add    $0x1,%esi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%ecx
shl    $0x8,%ecx
add    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%eax
shl    $0x8,%eax
add    $0x0,%eax
movslq %eax,%r8
mov    $0x13,%edi
call   1040 <interrupt@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readWriteSector>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebx
mov    %esi,%ebp
mov    %rdi,%r14
mov    %esi,%edi
mov    $0x24,%esi
call   1050 <div@plt>
mov    %eax,%r15d
mov    %ebp,%edi
mov    $0x12,%esi
call   1030 <mod@plt>
mov    %eax,%r12d
mov    %ebp,%edi
mov    $0x12,%esi
call   1050 <div@plt>
mov    %eax,%edi
mov    $0x2,%esi
call   1030 <mod@plt>
shl    $0x8,%ebx
or     $0x1,%ebx
shl    $0x8,%r15d
lea    (%r12,%r15,1),%ecx
add    $0x1,%ecx
shl    $0x8,%eax
movslq %eax,%r8
mov    $0x13,%edi
mov    %ebx,%esi
mov    %r14,%rdx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <interrupt@plt>

LLVM IR (-O0):
define void @readWriteSector(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* %5
%12 = call i32 @div(i32 %11, i32 36)
store i32 %12, i32* %8
%13 = load i32, i32* %5
%14 = call i32 @mod(i32 %13, i32 18)
%15 = add nsw i32 %14, 1
store i32 %15, i32* %9
%16 = load i32, i32* %5
%17 = call i32 @div(i32 %16, i32 18)
%18 = call i32 @mod(i32 %17, i32 2)
store i32 %18, i32* %10
%19 = load i32, i32* %6
%20 = mul nsw i32 %19, 256
%21 = add nsw i32 %20, 1
%22 = load i8*, i8** %4
%23 = load i32, i32* %8
%24 = mul nsw i32 %23, 256
%25 = load i32, i32* %9
%26 = add nsw i32 %24, %25
%27 = load i32, i32* %10
%28 = mul nsw i32 %27, 256
%29 = add nsw i32 %28, 0
%30 = sext i32 %29 to i64
%31 = call i32 @interrupt(i32 19, i32 %21, i8* %22, i32 %26, i64 %30)
ret void
}

LLVM IR (-O2):
define void @readWriteSector(i8* %0, i32 %1, i32 %2) {
%4 = tail call i32 @div(i32 %1, i32 36)
%5 = tail call i32 @mod(i32 %1, i32 18)
%6 = add nsw i32 %5, 1
%7 = tail call i32 @div(i32 %1, i32 18)
%8 = tail call i32 @mod(i32 %7, i32 2)
%9 = shl nsw i32 %2, 8
%10 = or i32 %9, 1
%11 = shl nsw i32 %4, 8
%12 = add nsw i32 %6, %11
%13 = shl nsw i32 %8, 8
%14 = sext i32 %13 to i64
%15 = tail call i32 @interrupt(i32 19, i32 %10, i8* %0, i32 %12, i64 %14)
ret void
}