#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*/ _out(int, int);
scalar_t__ check_cs(unsigned int, unsigned int);
int /*<<< orphan*/ goto_sector(unsigned int, unsigned int);
int /*<<< orphan*/ yield_hw();
void format_sector(unsigned int c, unsigned int s, unsigned int nsector,
                   unsigned int value) {
  if (check_cs(c, s)) {
    nsector = nsector > 512 ? 512 : nsector;
    goto_sector(c, s);
    _out(0x110, (nsector >> 8) & 0xFF);
    _out(0x110 + 1, nsector & 0xFF);
    _out(0x110 + 2, (value >> 24) & 0xFF);
    _out(0x110 + 3, (value >> 16) & 0xFF);
    _out(0x110 + 4, (value >> 8) & 0xFF);
    _out(0x110 + 5, value & 0xFF);
    _out(0x3F6, 0x08);
    yield_hw();
  }
}


x86 assembly (clang, -O0):
<format_sector>:
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    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1060 <check_cs@plt>
cmp    $0x0,%rax
je     122e <format_sector+0xee>
cmpl   $0x200,-0xc(%rbp)
jbe    1183 <format_sector+0x43>
mov    $0x200,%eax
mov    %eax,-0x14(%rbp)
jmp    1189 <format_sector+0x49>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <goto_sector@plt>
mov    -0xc(%rbp),%esi
shr    $0x8,%esi
and    $0xff,%esi
mov    $0x110,%edi
call   1040 <_out@plt>
mov    -0xc(%rbp),%esi
and    $0xff,%esi
mov    $0x111,%edi
call   1040 <_out@plt>
mov    -0x10(%rbp),%esi
shr    $0x18,%esi
and    $0xff,%esi
mov    $0x112,%edi
call   1040 <_out@plt>
mov    -0x10(%rbp),%esi
shr    $0x10,%esi
and    $0xff,%esi
mov    $0x113,%edi
call   1040 <_out@plt>
mov    -0x10(%rbp),%esi
shr    $0x8,%esi
and    $0xff,%esi
mov    $0x114,%edi
call   1040 <_out@plt>
mov    -0x10(%rbp),%esi
and    $0xff,%esi
mov    $0x115,%edi
call   1040 <_out@plt>
mov    $0x3f6,%edi
mov    $0x8,%esi
call   1040 <_out@plt>
mov    $0x0,%al
call   1050 <yield_hw@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_sector>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r12d
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%ebx
call   1060 <check_cs@plt>
test   %rax,%rax
je     11f8 <format_sector+0xb8>
cmp    $0x200,%r14d
mov    $0x200,%ebp
cmovb  %r14d,%ebp
mov    %ebx,%edi
mov    %r15d,%esi
call   1030 <goto_sector@plt>
mov    %ebp,%esi
shr    $0x8,%esi
mov    $0x110,%edi
call   1040 <_out@plt>
movzbl %bpl,%esi
mov    $0x111,%edi
call   1040 <_out@plt>
mov    %r12d,%ebx
mov    %r12d,%eax
shr    $0x18,%eax
mov    $0x112,%edi
mov    %eax,%esi
call   1040 <_out@plt>
mov    %r12d,%eax
shr    $0x10,%eax
movzbl %al,%esi
mov    $0x113,%edi
call   1040 <_out@plt>
movzbl %bh,%esi
mov    $0x114,%edi
call   1040 <_out@plt>
movzbl %bl,%esi
mov    $0x115,%edi
call   1040 <_out@plt>
mov    $0x3f6,%edi
mov    $0x8,%esi
call   1040 <_out@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <yield_hw@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @format_sector(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%9 = load i32, i32* %5
%10 = load i32, i32* %6
%11 = call i64 @check_cs(i32 %9, i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %48
13: ; preds = %4
%14 = load i32, i32* %7
%15 = icmp ugt i32 %14, 512
br i1 %15, label %16, label %17
16: ; preds = %13
br label %19
17: ; preds = %13
%18 = load i32, i32* %7
br label %19
19: ; preds = %17, %16
%20 = phi i32 [ 512, %16 ], [ %18, %17 ]
store i32 %20, i32* %7
%21 = load i32, i32* %5
%22 = load i32, i32* %6
%23 = call i32 @goto_sector(i32 %21, i32 %22)
%24 = load i32, i32* %7
%25 = lshr i32 %24, 8
%26 = and i32 %25, 255
%27 = call i32 @_out(i32 272, i32 %26)
%28 = load i32, i32* %7
%29 = and i32 %28, 255
%30 = call i32 @_out(i32 273, i32 %29)
%31 = load i32, i32* %8
%32 = lshr i32 %31, 24
%33 = and i32 %32, 255
%34 = call i32 @_out(i32 274, i32 %33)
%35 = load i32, i32* %8
%36 = lshr i32 %35, 16
%37 = and i32 %36, 255
%38 = call i32 @_out(i32 275, i32 %37)
%39 = load i32, i32* %8
%40 = lshr i32 %39, 8
%41 = and i32 %40, 255
%42 = call i32 @_out(i32 276, i32 %41)
%43 = load i32, i32* %8
%44 = and i32 %43, 255
%45 = call i32 @_out(i32 277, i32 %44)
%46 = call i32 @_out(i32 1014, i32 8)
%47 = call i32 (...) @yield_hw()
br label %48
48: ; preds = %19, %4
ret void
}

LLVM IR (-O2):
define void @format_sector(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i64 @check_cs(i32 %0, i32 %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %27, label %7
7: ; preds = %4
%8 = icmp ult i32 %2, 512
%9 = select i1 %8, i32 %2, i32 512
%10 = tail call i32 @goto_sector(i32 %0, i32 %1)
%11 = lshr i32 %9, 8
%12 = tail call i32 @_out(i32 272, i32 %11)
%13 = and i32 %9, 255
%14 = tail call i32 @_out(i32 273, i32 %13)
%15 = lshr i32 %3, 24
%16 = tail call i32 @_out(i32 274, i32 %15)
%17 = lshr i32 %3, 16
%18 = and i32 %17, 255
%19 = tail call i32 @_out(i32 275, i32 %18)
%20 = lshr i32 %3, 8
%21 = and i32 %20, 255
%22 = tail call i32 @_out(i32 276, i32 %21)
%23 = and i32 %3, 255
%24 = tail call i32 @_out(i32 277, i32 %23)
%25 = tail call i32 @_out(i32 1014, i32 8)
%26 = tail call i32 (...) @yield_hw()
br label %27
27: ; preds = %7, %4
ret void
}