#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 writeSector(char *buffer, int sector) {
  int relativeSector = mod(sector, 18) + 1;
  int head = mod(div(sector, 18), 2);
  int track = div(sector, 36);
  interrupt(0x13, 3 * 256 + 1, buffer, track * 256 + relativeSector,
            head * 256 + 0);
}


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

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

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

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