#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 */
short BIG_ENDIAN;
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, unsigned short,
                           unsigned short);
char write_2byte_number(FILE *f, unsigned short n, short writeEndian) {
  if (writeEndian == BIG_ENDIAN) {
    fprintf(f, "%c%c", n / 256, n % 256);
  } else {
    fprintf(f, "%c%c", n % 256, n / 256);
  }
  return (ferror(f) ? 2 : 1);
}


x86 assembly (clang, -O0):
<write_2byte_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dx,%ax
mov    %si,%cx
mov    %rdi,-0x8(%rbp)
mov    %cx,-0xa(%rbp)
mov    %ax,-0xc(%rbp)
movswl -0xc(%rbp),%eax
mov    0x2e9b(%rip),%rcx
movswl (%rcx),%ecx
cmp    %ecx,%eax
jne    1189 <write_2byte_number+0x69>
mov    -0x8(%rbp),%rdi
movzwl -0xa(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %ax,%cx
movzwl -0xa(%rbp),%eax
mov    $0x100,%esi
cltd
idiv   %esi
mov    %dx,%ax
lea    0xe87(%rip),%rsi
movzwl %cx,%edx
movzwl %ax,%ecx
call   1040 <fprintf@plt>
jmp    11ba <write_2byte_number+0x9a>
mov    -0x8(%rbp),%rdi
movzwl -0xa(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %dx,%cx
movzwl -0xa(%rbp),%eax
mov    $0x100,%esi
cltd
idiv   %esi
lea    0xe51(%rip),%rsi
movzwl %cx,%edx
movzwl %ax,%ecx
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
mov    %rax,%rdx
mov    $0x1,%eax
mov    $0x2,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
movsbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_2byte_number>:
push   %rbx
mov    %rdi,%rbx
mov    0x2eb5(%rip),%rax
cmp    %dx,(%rax)
jne    113c <write_2byte_number+0x1c>
movzwl %si,%edx
shr    $0x8,%edx
movzbl %sil,%ecx
jmp    1145 <write_2byte_number+0x25>
movzwl %si,%ecx
movzbl %cl,%edx
shr    $0x8,%ecx
lea    0xeb4(%rip),%rsi
mov    %rbx,%rdi
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <ferror@plt>
cmp    $0x1,%rax
mov    $0x2,%al
sbb    $0x0,%al
pop    %rbx
ret

LLVM IR (-O0):
@BIG_ENDIAN = global i16 0
@.str = [5 x i8] c"%c%c\00"
define signext i8 @write_2byte_number(i32* %0, i16 zeroext %1, i16 signext %2) {
%4 = alloca i32*
%5 = alloca i16
%6 = alloca i16
store i32* %0, i32** %4
store i16 %1, i16* %5
store i16 %2, i16* %6
%7 = load i16, i16* %6
%8 = sext i16 %7 to i32
%9 = load i16, i16* @BIG_ENDIAN
%10 = sext i16 %9 to i32
%11 = icmp eq i32 %8, %10
br i1 %11, label %12, label %23
12: ; preds = %3
%13 = load i32*, i32** %4
%14 = load i16, i16* %5
%15 = zext i16 %14 to i32
%16 = sdiv i32 %15, 256
%17 = trunc i32 %16 to i16
%18 = load i16, i16* %5
%19 = zext i16 %18 to i32
%20 = srem i32 %19, 256
%21 = trunc i32 %20 to i16
%22 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i16 zeroext %17, i16 zeroext %21)
br label %34
23: ; preds = %3
%24 = load i32*, i32** %4
%25 = load i16, i16* %5
%26 = zext i16 %25 to i32
%27 = srem i32 %26, 256
%28 = trunc i32 %27 to i16
%29 = load i16, i16* %5
%30 = zext i16 %29 to i32
%31 = sdiv i32 %30, 256
%32 = trunc i32 %31 to i16
%33 = call i32 @fprintf(i32* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i16 zeroext %28, i16 zeroext %32)
br label %34
34: ; preds = %23, %12
%35 = load i32*, i32** %4
%36 = call i64 @ferror(i32* %35)
%37 = icmp ne i64 %36, 0
%38 = zext i1 %37 to i64
%39 = select i1 %37, i32 2, i32 1
%40 = trunc i32 %39 to i8
ret i8 %40
}

LLVM IR (-O2):
@BIG_ENDIAN = global i16 0
@.str = [5 x i8] c"%c%c\00"
define signext i8 @write_2byte_number(i32* nocapture %0, i16 zeroext %1, i16 signext %2) {
%4 = load i16, i16* @BIG_ENDIAN
%5 = icmp eq i16 %4, %2
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = lshr i16 %1, 8
%8 = and i16 %1, 255
%9 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i16 zeroext %7, i16 zeroext %8)
br label %14
10: ; preds = %3
%11 = and i16 %1, 255
%12 = lshr i16 %1, 8
%13 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i16 zeroext %11, i16 zeroext %12)
br label %14
14: ; preds = %10, %6
%15 = tail call i64 @ferror(i32* %0)
%16 = icmp eq i64 %15, 0
%17 = select i1 %16, i8 1, i8 2
ret i8 %17
}