#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*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ fat_uint16(int /*<<< orphan*/ *, int);
void fat_table_entry(uint8_t *dest, unsigned cluster) {
  if (cluster == 0) {
    fat_uint16(dest, 0xff00 | 0xf8);
  } else if (cluster < 0xf480 / 4) {
    bool last_in_sector = (cluster % 0x100) == (0x100 - 1);
    fat_uint16(dest, last_in_sector ? 0xffff : cluster + 1);
  } else {
    fat_uint16(dest, 0x0000);
  }
}


x86 assembly (clang, -O0):
<fat_table_entry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    113c <fat_table_entry+0x2c>
mov    -0x8(%rbp),%rdi
mov    $0xfff8,%esi
call   1030 <fat_uint16@plt>
jmp    11aa <fat_table_entry+0x9a>
cmpl   $0x3d20,-0xc(%rbp)
jae    119a <fat_table_entry+0x8a>
mov    -0xc(%rbp),%eax
and    $0xff,%eax
cmp    $0xff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1180 <fat_table_entry+0x70>
mov    $0xffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1189 <fat_table_entry+0x79>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <fat_uint16@plt>
jmp    11a5 <fat_table_entry+0x95>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1030 <fat_uint16@plt>
jmp    11aa <fat_table_entry+0x9a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fat_table_entry>:
test   %esi,%esi
je     1133 <fat_table_entry+0x23>
mov    %esi,%eax
xor    %esi,%esi
cmp    $0x3d1f,%eax
ja     112e <fat_table_entry+0x1e>
mov    %eax,%ecx
add    $0x1,%ecx
cmp    $0xff,%al
mov    $0xffff,%esi
cmovne %ecx,%esi
jmp    1030 <fat_uint16@plt>
mov    $0xfff8,%esi
jmp    1030 <fat_uint16@plt>

LLVM IR (-O0):
define void @fat_table_entry(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32*, i32** %3
%10 = call i32 @fat_uint16(i32* %9, i32 65528)
br label %33
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp ult i32 %12, 15648
br i1 %13, label %14, label %29
14: ; preds = %11
%15 = load i32, i32* %4
%16 = urem i32 %15, 256
%17 = icmp eq i32 %16, 255
%18 = zext i1 %17 to i32
store i32 %18, i32* %5
%19 = load i32*, i32** %3
%20 = load i32, i32* %5
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %14
br label %26
23: ; preds = %14
%24 = load i32, i32* %4
%25 = add i32 %24, 1
br label %26
26: ; preds = %23, %22
%27 = phi i32 [ 65535, %22 ], [ %25, %23 ]
%28 = call i32 @fat_uint16(i32* %19, i32 %27)
br label %32
29: ; preds = %11
%30 = load i32*, i32** %3
%31 = call i32 @fat_uint16(i32* %30, i32 0)
br label %32
32: ; preds = %29, %26
br label %33
33: ; preds = %32, %8
ret void
}

LLVM IR (-O2):
define void @fat_table_entry(i32* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %11, label %4
4: ; preds = %2
%5 = icmp ult i32 %1, 15648
br i1 %5, label %6, label %11
6: ; preds = %4
%7 = and i32 %1, 255
%8 = icmp eq i32 %7, 255
%9 = add nuw nsw i32 %1, 1
%10 = select i1 %8, i32 65535, i32 %9
br label %11
11: ; preds = %4, %2, %6
%12 = phi i32 [ %10, %6 ], [ 65528, %2 ], [ 0, %4 ]
%13 = tail call i32 @fat_uint16(i32* %0, i32 %12)
ret void
}