#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 */
int 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) : iHeads;
  if (!s)
    return 0;
  aucBuf[0] = s & 0xff;
  aucBuf[1] = (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    114a <write_partition_number_of_heads+0x2a>
mov    -0x10(%rbp),%rdi
call   1040 <partition_number_of_heads@plt>
mov    %eax,-0x1c(%rbp)
jmp    1150 <write_partition_number_of_heads+0x30>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %ax,-0x18(%rbp)
cmpw   $0x0,-0x18(%rbp)
jne    116e <write_partition_number_of_heads+0x4e>
movl   $0x0,-0x4(%rbp)
jmp    11a3 <write_partition_number_of_heads+0x83>
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     114f <write_partition_number_of_heads+0x2f>
test   %si,%si
je     115e <write_partition_number_of_heads+0x3e>
mov    %si,0xe(%rsp)
lea    0xe(%rsp),%rdx
mov    %rbx,%rdi
mov    $0x1a,%esi
mov    $0x2,%ecx
call   1030 <write_data@plt>
jmp    1160 <write_partition_number_of_heads+0x40>
mov    %rbx,%rdi
call   1040 <partition_number_of_heads@plt>
mov    %eax,%esi
test   %si,%si
jne    1131 <write_partition_number_of_heads+0x11>
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 %13
10: ; preds = %2
%11 = load i32*, i32** %4
%12 = call i32 @partition_number_of_heads(i32* %11)
br label %15
13: ; preds = %2
%14 = load i32, i32* %5
br label %15
15: ; preds = %13, %10
%16 = phi i32 [ %12, %10 ], [ %14, %13 ]
%17 = trunc i32 %16 to i16
store i16 %17, i16* %7
%18 = load i16, i16* %7
%19 = icmp ne i16 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %15
store i32 0, i32* %3
br label %36
21: ; preds = %15
%22 = load i16, i16* %7
%23 = zext i16 %22 to i32
%24 = and i32 %23, 255
%25 = trunc i32 %24 to i8
%26 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
store i8 %25, i8* %26
%27 = load i16, i16* %7
%28 = zext i16 %27 to i32
%29 = and i32 %28, 65280
%30 = ashr i32 %29, 8
%31 = trunc i32 %30 to i8
%32 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 1
store i8 %31, i8* %32
%33 = load i32*, i32** %4
%34 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%35 = call i32 @write_data(i32* %33, i32 26, i8* %34, i32 2)
store i32 %35, i32* %3
br label %36
36: ; preds = %21, %20
%37 = load i32, i32* %3
ret i32 %37
}

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 %8
6: ; preds = %2
%7 = tail call i32 @partition_number_of_heads(i32* %0)
br label %8
8: ; preds = %2, %6
%9 = phi i32 [ %7, %6 ], [ %1, %2 ]
%10 = trunc i32 %9 to i16
%11 = icmp eq i16 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %8
%13 = trunc i32 %9 to i8
store i8 %13, i8* %4
%14 = lshr i32 %9, 8
%15 = trunc i32 %14 to i8
%16 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
store i8 %15, i8* %16
%17 = call i32 @write_data(i32* %0, i32 26, i8* %4, i32 2)
br label %18
18: ; preds = %8, %12
%19 = phi i32 [ %17, %12 ], [ 0, %8 ]
ret i32 %19
}