#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 fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int WriteUSHORT(unsigned short x, FILE *f) {
  unsigned char little[2];
  little[1] = (unsigned char)((x & 0xff00) >> 8);
  little[0] = (unsigned char)((x & 0x00ff) >> 0);
  return (f && fwrite(little, 2, 1, f) == 1);
}


x86 assembly (clang, -O0):
<WriteUSHORT>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
movzwl -0x2(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %al,-0x11(%rbp)
movzwl -0x2(%rbp),%eax
and    $0xff,%eax
sar    $0x0,%eax
mov    %al,-0x12(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x13(%rbp)
je     1171 <WriteUSHORT+0x61>
lea    -0x12(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1,%edx
call   1030 <fwrite@plt>
cmp    $0x1,%eax
sete   %al
mov    %al,-0x13(%rbp)
mov    -0x13(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WriteUSHORT>:
push   %rax
mov    %di,0x6(%rsp)
test   %rsi,%rsi
je     113e <WriteUSHORT+0x2e>
mov    %rsi,%rcx
lea    0x6(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1030 <fwrite@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
sete   %al
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @WriteUSHORT(i16 zeroext %0, i32* %1) {
%3 = alloca i16
%4 = alloca i32*
%5 = alloca [2 x i8]
store i16 %0, i16* %3
store i32* %1, i32** %4
%6 = load i16, i16* %3
%7 = zext i16 %6 to i32
%8 = and i32 %7, 65280
%9 = ashr i32 %8, 8
%10 = trunc i32 %9 to i8
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 1
store i8 %10, i8* %11
%12 = load i16, i16* %3
%13 = zext i16 %12 to i32
%14 = and i32 %13, 255
%15 = ashr i32 %14, 0
%16 = trunc i32 %15 to i8
%17 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
store i8 %16, i8* %17
%18 = load i32*, i32** %4
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %25
20: ; preds = %2
%21 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%22 = load i32*, i32** %4
%23 = call i32 @fwrite(i8* %21, i32 2, i32 1, i32* %22)
%24 = icmp eq i32 %23, 1
br label %25
25: ; preds = %20, %2
%26 = phi i1 [ false, %2 ], [ %24, %20 ]
%27 = zext i1 %26 to i32
ret i32 %27
}

LLVM IR (-O2):
define i32 @WriteUSHORT(i16 zeroext %0, i32* %1) {
%3 = alloca [2 x i8]
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%5 = lshr i16 %0, 8
%6 = trunc i16 %5 to i8
%7 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
store i8 %6, i8* %7
%8 = trunc i16 %0 to i8
store i8 %8, i8* %4
%9 = icmp eq i32* %1, null
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = call i32 @fwrite(i8* %4, i32 2, i32 1, i32* %1)
%12 = icmp eq i32 %11, 1
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %10, %2
%15 = phi i32 [ 0, %2 ], [ %13, %10 ]
ret i32 %15
}