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

/* Variables and functions */
unsigned short partition_number_of_heads(int /*<<< orphan*/ *);
int write_data(int /*<<< orphan*/ *, int, unsigned char *, int);
int write_partition_number_of_heads(FILE *fp, int iHeads) {
  unsigned char aucBuf[2];
  unsigned short s =
      (iHeads < 0) ? partition_number_of_heads(fp) : (unsigned short)iHeads;
  if (!s)
    return 0;
  aucBuf[0] = (unsigned char)(s & 0xff);
  aucBuf[1] = (unsigned char)((s & 0xff00) >> 8);
  return write_data(fp, 0x1a, aucBuf, 2);
}


x86 assembly (clang, -O0):
<write_partition_number_of_heads>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    114d <write_partition_number_of_heads+0x2d>
mov    -0x10(%rbp),%rdi
call   1040 <partition_number_of_heads@plt>
movzwl %ax,%eax
mov    %eax,-0x1c(%rbp)
jmp    1156 <write_partition_number_of_heads+0x36>
mov    -0x14(%rbp),%eax
movzwl %ax,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %ax,-0x18(%rbp)
cmpw   $0x0,-0x18(%rbp)
jne    1174 <write_partition_number_of_heads+0x54>
movl   $0x0,-0x4(%rbp)
jmp    11a9 <write_partition_number_of_heads+0x89>
movzwl -0x18(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x16(%rbp)
movzwl -0x18(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %al,-0x15(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x16(%rbp),%rdx
mov    $0x1a,%esi
mov    $0x2,%ecx
call   1030 <write_data@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_partition_number_of_heads>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
test   %esi,%esi
js     1151 <write_partition_number_of_heads+0x31>
movzwl %si,%eax
test   %eax,%eax
je     1160 <write_partition_number_of_heads+0x40>
mov    %ax,0xe(%rsp)
lea    0xe(%rsp),%rdx
mov    %rbx,%rdi
mov    $0x1a,%esi
mov    $0x2,%ecx
call   1030 <write_data@plt>
jmp    1162 <write_partition_number_of_heads+0x42>
mov    %rbx,%rdi
call   1040 <partition_number_of_heads@plt>
movzwl %ax,%eax
test   %eax,%eax
jne    1133 <write_partition_number_of_heads+0x13>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @write_partition_number_of_heads(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [2 x i8]
%7 = alloca i16
store i32* %0, i32** %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32*, i32** %4
%12 = call zeroext i16 @partition_number_of_heads(i32* %11)
%13 = zext i16 %12 to i32
br label %18
14: ; preds = %2
%15 = load i32, i32* %5
%16 = trunc i32 %15 to i16
%17 = zext i16 %16 to i32
br label %18
18: ; preds = %14, %10
%19 = phi i32 [ %13, %10 ], [ %17, %14 ]
%20 = trunc i32 %19 to i16
store i16 %20, i16* %7
%21 = load i16, i16* %7
%22 = icmp ne i16 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %18
store i32 0, i32* %3
br label %39
24: ; preds = %18
%25 = load i16, i16* %7
%26 = zext i16 %25 to i32
%27 = and i32 %26, 255
%28 = trunc i32 %27 to i8
%29 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
store i8 %28, i8* %29
%30 = load i16, i16* %7
%31 = zext i16 %30 to i32
%32 = and i32 %31, 65280
%33 = ashr i32 %32, 8
%34 = trunc i32 %33 to i8
%35 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 1
store i8 %34, i8* %35
%36 = load i32*, i32** %4
%37 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%38 = call i32 @write_data(i32* %36, i32 26, i8* %37, i32 2)
store i32 %38, i32* %3
br label %39
39: ; preds = %24, %23
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
define i32 @write_partition_number_of_heads(i32* %0, i32 %1) {
%3 = alloca [2 x i8]
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %1, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call zeroext i16 @partition_number_of_heads(i32* %0)
%8 = zext i16 %7 to i32
br label %11
9: ; preds = %2
%10 = and i32 %1, 65535
br label %11
11: ; preds = %9, %6
%12 = phi i32 [ %8, %6 ], [ %10, %9 ]
%13 = icmp eq i32 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %11
%15 = trunc i32 %12 to i8
store i8 %15, i8* %4
%16 = lshr i32 %12, 8
%17 = trunc i32 %16 to i8
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
store i8 %17, i8* %18
%19 = call i32 @write_data(i32* %0, i32 26, i8* %4, i32 2)
br label %20
20: ; preds = %11, %14
%21 = phi i32 [ %19, %14 ], [ 0, %11 ]
ret i32 %21
}