#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*/ __builtin_sthio(unsigned short *, int);
void test_sthio(unsigned short *p1, unsigned short *p2) {
  __builtin_sthio(p1, *p2);
  __builtin_sthio(p2, 0);
  __builtin_sthio(p2 + 1, 0x8000);
  __builtin_sthio(p2 + 2, 0x7fff);
  __builtin_sthio(p2 + 1023, 0x8000);
  __builtin_sthio(p2 + 1024, 0x7fff);
}


x86 assembly (clang, -O0):
<test_sthio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movzwl (%rax),%esi
call   1030 <__builtin_sthio@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1030 <__builtin_sthio@plt>
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
mov    $0x8000,%esi
call   1030 <__builtin_sthio@plt>
mov    -0x10(%rbp),%rdi
add    $0x4,%rdi
mov    $0x7fff,%esi
call   1030 <__builtin_sthio@plt>
mov    -0x10(%rbp),%rdi
add    $0x7fe,%rdi
mov    $0x8000,%esi
call   1030 <__builtin_sthio@plt>
mov    -0x10(%rbp),%rdi
add    $0x800,%rdi
mov    $0x7fff,%esi
call   1030 <__builtin_sthio@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_sthio>:
push   %rbx
mov    %rsi,%rbx
movzwl (%rsi),%esi
call   1030 <__builtin_sthio@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <__builtin_sthio@plt>
lea    0x2(%rbx),%rdi
mov    $0x8000,%esi
call   1030 <__builtin_sthio@plt>
lea    0x4(%rbx),%rdi
mov    $0x7fff,%esi
call   1030 <__builtin_sthio@plt>
lea    0x7fe(%rbx),%rdi
mov    $0x8000,%esi
call   1030 <__builtin_sthio@plt>
add    $0x800,%rbx
mov    %rbx,%rdi
mov    $0x7fff,%esi
pop    %rbx
jmp    1030 <__builtin_sthio@plt>

LLVM IR (-O0):
define void @test_sthio(i16* %0, i16* %1) {
%3 = alloca i16*
%4 = alloca i16*
store i16* %0, i16** %3
store i16* %1, i16** %4
%5 = load i16*, i16** %3
%6 = load i16*, i16** %4
%7 = load i16, i16* %6
%8 = zext i16 %7 to i32
%9 = call i32 @__builtin_sthio(i16* %5, i32 %8)
%10 = load i16*, i16** %4
%11 = call i32 @__builtin_sthio(i16* %10, i32 0)
%12 = load i16*, i16** %4
%13 = getelementptr inbounds i16, i16* %12, i64 1
%14 = call i32 @__builtin_sthio(i16* %13, i32 32768)
%15 = load i16*, i16** %4
%16 = getelementptr inbounds i16, i16* %15, i64 2
%17 = call i32 @__builtin_sthio(i16* %16, i32 32767)
%18 = load i16*, i16** %4
%19 = getelementptr inbounds i16, i16* %18, i64 1023
%20 = call i32 @__builtin_sthio(i16* %19, i32 32768)
%21 = load i16*, i16** %4
%22 = getelementptr inbounds i16, i16* %21, i64 1024
%23 = call i32 @__builtin_sthio(i16* %22, i32 32767)
ret void
}

LLVM IR (-O2):
define void @test_sthio(i16* %0, i16* %1) {
%3 = load i16, i16* %1
%4 = zext i16 %3 to i32
%5 = tail call i32 @__builtin_sthio(i16* %0, i32 %4)
%6 = tail call i32 @__builtin_sthio(i16* %1, i32 0)
%7 = getelementptr inbounds i16, i16* %1, i64 1
%8 = tail call i32 @__builtin_sthio(i16* %7, i32 32768)
%9 = getelementptr inbounds i16, i16* %1, i64 2
%10 = tail call i32 @__builtin_sthio(i16* %9, i32 32767)
%11 = getelementptr inbounds i16, i16* %1, i64 1023
%12 = tail call i32 @__builtin_sthio(i16* %11, i32 32768)
%13 = getelementptr inbounds i16, i16* %1, i64 1024
%14 = tail call i32 @__builtin_sthio(i16* %13, i32 32767)
ret void
}