#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 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 = (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)
mov    -0x14(%rbp),%eax
mov    %ax,-0x18(%rbp)
cmpw   $0x0,-0x18(%rbp)
jne    113d <write_partition_number_of_heads+0x2d>
movl   $0x0,-0x4(%rbp)
jmp    1172 <write_partition_number_of_heads+0x62>
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>:
test   %si,%si
je     1134 <write_partition_number_of_heads+0x24>
push   %rax
mov    %si,0x6(%rsp)
lea    0x6(%rsp),%rdx
mov    $0x1a,%esi
mov    $0x2,%ecx
call   1030 <write_data@plt>
add    $0x8,%rsp
ret
xor    %eax,%eax
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 = trunc i32 %8 to i16
store i16 %9, i16* %7
%10 = load i16, i16* %7
%11 = icmp ne i16 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %2
store i32 0, i32* %3
br label %28
13: ; preds = %2
%14 = load i16, i16* %7
%15 = zext i16 %14 to i32
%16 = and i32 %15, 255
%17 = trunc i32 %16 to i8
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
store i8 %17, i8* %18
%19 = load i16, i16* %7
%20 = zext i16 %19 to i32
%21 = and i32 %20, 65280
%22 = ashr i32 %21, 8
%23 = trunc i32 %22 to i8
%24 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 1
store i8 %23, i8* %24
%25 = load i32*, i32** %4
%26 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%27 = call i32 @write_data(i32* %25, i32 26, i8* %26, i32 2)
store i32 %27, i32* %3
br label %28
28: ; preds = %13, %12
%29 = load i32, i32* %3
ret i32 %29
}

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