#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 /*<<< orphan*/ write16(short, int /*<<< orphan*/ *);
void writearr(register long *p, register int n, register FILE *out) {
  while (n) {
    write16((short)(*p >> 16), out);
    write16((short)(*p & 65535), out);
    p++;
    n--;
  }
}


x86 assembly (clang, -O0):
<writearr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1177 <writearr+0x67>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
sar    $0x10,%rax
mov    -0x18(%rbp),%rsi
movswl %ax,%edi
call   1030 <write16@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
and    $0xffff,%rax
mov    -0x18(%rbp),%rsi
movswl %ax,%edi
call   1030 <write16@plt>
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <writearr+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writearr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     1154 <writearr+0x44>
mov    %rdx,%r14
mov    %rdi,%r12
mov    %esi,%r15d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movswl 0x2(%r12,%rbx,8),%edi
mov    %r14,%rsi
call   1030 <write16@plt>
movswl (%r12,%rbx,8),%edi
mov    %r14,%rsi
call   1030 <write16@plt>
add    $0x1,%rbx
cmp    %ebx,%r15d
jne    1130 <writearr+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @writearr(i64* %0, i32 %1, i32* %2) {
%4 = alloca i64*
%5 = alloca i32
%6 = alloca i32*
store i64* %0, i64** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
br label %7
7: ; preds = %10, %3
%8 = load i32, i32* %5
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %27
10: ; preds = %7
%11 = load i64*, i64** %4
%12 = load i64, i64* %11
%13 = ashr i64 %12, 16
%14 = trunc i64 %13 to i16
%15 = load i32*, i32** %6
%16 = call i32 @write16(i16 signext %14, i32* %15)
%17 = load i64*, i64** %4
%18 = load i64, i64* %17
%19 = and i64 %18, 65535
%20 = trunc i64 %19 to i16
%21 = load i32*, i32** %6
%22 = call i32 @write16(i16 signext %20, i32* %21)
%23 = load i64*, i64** %4
%24 = getelementptr inbounds i64, i64* %23, i32 1
store i64* %24, i64** %4
%25 = load i32, i32* %5
%26 = add nsw i32 %25, -1
store i32 %26, i32* %5
br label %7
27: ; preds = %7
ret void
}

LLVM IR (-O2):
define void @writearr(i64* nocapture %0, i32 %1, i32* %2) {
%4 = icmp eq i32 %1, 0
br i1 %4, label %18, label %5
5: ; preds = %3, %5
%6 = phi i64* [ %15, %5 ], [ %0, %3 ]
%7 = phi i32 [ %16, %5 ], [ %1, %3 ]
%8 = load i64, i64* %6
%9 = lshr i64 %8, 16
%10 = trunc i64 %9 to i16
%11 = tail call i32 @write16(i16 signext %10, i32* %2)
%12 = load i64, i64* %6
%13 = trunc i64 %12 to i16
%14 = tail call i32 @write16(i16 signext %13, i32* %2)
%15 = getelementptr inbounds i64, i64* %6, i64 1
%16 = add nsw i32 %7, -1
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %5
18: ; preds = %5, %3
ret void
}