#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 */

/* Variables and functions */
int /*<<< orphan*/ flip2(unsigned short const *, unsigned short *, int);
int write(int, unsigned short const *, int);
int write_uint2_array(int f, const unsigned short *iarray, int n) {
  int 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    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <flip2@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
shl    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <flip2@plt>
cmpl   $0x0,-0x18(%rbp)
jg     117d <write_uint2_array+0x5d>
movl   $0x0,-0x4(%rbp)
jmp    118b <write_uint2_array+0x6b>
mov    -0x18(%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    %edx,%ebx
mov    %rsi,%rbp
mov    %edi,%r14d
mov    %rsi,%rdi
call   1040 <flip2@plt>
lea    (%rbx,%rbx,1),%edx
mov    %r14d,%edi
mov    %rbp,%rsi
call   1030 <write@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1040 <flip2@plt>
test   %r14d,%r14d
jle    1164 <write_uint2_array+0x44>
mov    %r14d,%eax
shr    $0x1f,%eax
add    %r14d,%eax
sar    %eax
jmp    1166 <write_uint2_array+0x46>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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