#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ flip2(unsigned short const *, unsigned short *, size_t);
int write(int, unsigned short const *, int);
ssize_t write_uint2_array(int f, const unsigned short *iarray, size_t n) {
  ssize_t nwritten;
  flip2(iarray, (unsigned short *)iarray, n);
  nwritten = write(f, iarray, 2 * n);
  flip2(iarray, (unsigned short *)iarray, n);
  if (nwritten <= 0)
    return 0;
  else
    return nwritten / 2;
}


x86 assembly (clang, -O0):
<write_uint2_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <flip2@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <flip2@plt>
cmpl   $0x0,-0x1c(%rbp)
jg     1184 <write_uint2_array+0x64>
movl   $0x0,-0x4(%rbp)
jmp    1192 <write_uint2_array+0x72>
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_uint2_array>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
call   1040 <flip2@plt>
lea    (%r14,%r14,1),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <write@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <flip2@plt>
test   %ebp,%ebp
jle    1161 <write_uint2_array+0x41>
mov    %ebp,%eax
shr    $0x1f,%eax
add    %ebp,%eax
sar    %eax
jmp    1163 <write_uint2_array+0x43>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @write_uint2_array(i32 %0, i16* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i16*
%7 = alloca i64
%8 = alloca i32
store i32 %0, i32* %5
store i16* %1, i16** %6
store i64 %2, i64* %7
%9 = load i16*, i16** %6
%10 = load i16*, i16** %6
%11 = load i64, i64* %7
%12 = call i32 @flip2(i16* %9, i16* %10, i64 %11)
%13 = load i32, i32* %5
%14 = load i16*, i16** %6
%15 = load i64, i64* %7
%16 = mul i64 2, %15
%17 = trunc i64 %16 to i32
%18 = call i32 @write(i32 %13, i16* %14, i32 %17)
store i32 %18, i32* %8
%19 = load i16*, i16** %6
%20 = load i16*, i16** %6
%21 = load i64, i64* %7
%22 = call i32 @flip2(i16* %19, i16* %20, i64 %21)
%23 = load i32, i32* %8
%24 = icmp sle i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %3
store i32 0, i32* %4
br label %29
26: ; preds = %3
%27 = load i32, i32* %8
%28 = sdiv i32 %27, 2
store i32 %28, i32* %4
br label %29
29: ; preds = %26, %25
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
define i32 @write_uint2_array(i32 %0, i16* %1, i64 %2) {
%4 = tail call i32 @flip2(i16* %1, i16* %1, i64 %2)
%5 = trunc i64 %2 to i32
%6 = shl i32 %5, 1
%7 = tail call i32 @write(i32 %0, i16* %1, i32 %6)
%8 = tail call i32 @flip2(i16* %1, i16* %1, i64 %2)
%9 = sdiv i32 %7, 2
%10 = icmp sgt i32 %7, 0
%11 = select i1 %10, i32 %9, i32 0
ret i32 %11
}