#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 */
char *malloc(int);
char *test1() {
  size_t i;
  char *start = malloc(2560 * 2);
  char *t = start;
  for (i = 1; i <= 2560; i++) {
    unsigned short *p;
    p = (unsigned short *)t;
    *p = i;
    t += 2;
  }
  return start;
}


x86 assembly (clang, -O0):
<test1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x1400,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x1,-0x8(%rbp)
cmpq   $0xa00,-0x8(%rbp)
ja     1177 <test1+0x67>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %ax,%cx
mov    -0x20(%rbp),%rax
mov    %cx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1136 <test1+0x26>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test1>:
push   %rax
mov    $0x1400,%edi
call   1030 <malloc@plt>
movdqa 0xedd(%rip),%xmm0
mov    $0x38,%ecx
movdqa 0xedf(%rip),%xmm8
movdqa 0xee6(%rip),%xmm9
movdqa 0xeed(%rip),%xmm10
movdqa 0xef5(%rip),%xmm4
movdqa 0xefd(%rip),%xmm5
movdqa 0xf05(%rip),%xmm6
movdqa 0xf0d(%rip),%xmm7
movdqa 0xf15(%rip),%xmm1
nopl   0x0(%rax,%rax,1)
movdqa %xmm0,%xmm2
paddw  %xmm8,%xmm2
movdqu %xmm0,-0x70(%rax,%rcx,2)
movdqu %xmm2,-0x60(%rax,%rcx,2)
movdqa %xmm0,%xmm2
paddw  %xmm9,%xmm2
movdqa %xmm0,%xmm3
paddw  %xmm10,%xmm3
movdqu %xmm2,-0x50(%rax,%rcx,2)
movdqu %xmm3,-0x40(%rax,%rcx,2)
movdqa %xmm0,%xmm2
paddw  %xmm4,%xmm2
movdqa %xmm0,%xmm3
paddw  %xmm5,%xmm3
movdqu %xmm2,-0x30(%rax,%rcx,2)
movdqu %xmm3,-0x20(%rax,%rcx,2)
movdqa %xmm0,%xmm2
paddw  %xmm6,%xmm2
movdqa %xmm0,%xmm3
paddw  %xmm7,%xmm3
movdqu %xmm2,-0x10(%rax,%rcx,2)
movdqu %xmm3,(%rax,%rcx,2)
paddw  %xmm1,%xmm0
add    $0x40,%rcx
cmp    $0xa38,%rcx
jne    1170 <test1+0x60>
pop    %rcx
ret

LLVM IR (-O0):
define i8* @test1() {
%1 = alloca i64
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i16*
%5 = call i8* @malloc(i32 5120)
store i8* %5, i8** %2
%6 = load i8*, i8** %2
store i8* %6, i8** %3
store i64 1, i64* %1
br label %7
7: ; preds = %18, %0
%8 = load i64, i64* %1
%9 = icmp ule i64 %8, 2560
br i1 %9, label %10, label %21
10: ; preds = %7
%11 = load i8*, i8** %3
%12 = bitcast i8* %11 to i16*
store i16* %12, i16** %4
%13 = load i64, i64* %1
%14 = trunc i64 %13 to i16
%15 = load i16*, i16** %4
store i16 %14, i16* %15
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 2
store i8* %17, i8** %3
br label %18
18: ; preds = %10
%19 = load i64, i64* %1
%20 = add i64 %19, 1
store i64 %20, i64* %1
br label %7
21: ; preds = %7
%22 = load i8*, i8** %2
ret i8* %22
}

LLVM IR (-O2):
define noalias i8* @test1() {
%1 = tail call dereferenceable_or_null(5120) i8* @malloc(i32 5120)
br label %2
2: ; preds = %2, %0
%3 = phi i64 [ 0, %0 ], [ %35, %2 ]
%4 = phi <8 x i16> [ <i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7, i16 8>, %0 ], [ %36, %2 ]
%5 = shl nuw i64 %3, 1
%6 = getelementptr i8, i8* %1, i64 %5
%7 = add <8 x i16> %4, <i16 8, i16 8, i16 8, i16 8, i16 8, i16 8, i16 8, i16 8>
%8 = bitcast i8* %6 to <8 x i16>*
store <8 x i16> %4, <8 x i16>* %8
%9 = getelementptr i8, i8* %6, i64 16
%10 = bitcast i8* %9 to <8 x i16>*
store <8 x i16> %7, <8 x i16>* %10
%11 = add <8 x i16> %4, <i16 16, i16 16, i16 16, i16 16, i16 16, i16 16, i16 16, i16 16>
%12 = shl nuw i64 %3, 1
%13 = or i64 %12, 32
%14 = getelementptr i8, i8* %1, i64 %13
%15 = add <8 x i16> %4, <i16 24, i16 24, i16 24, i16 24, i16 24, i16 24, i16 24, i16 24>
%16 = bitcast i8* %14 to <8 x i16>*
store <8 x i16> %11, <8 x i16>* %16
%17 = getelementptr i8, i8* %14, i64 16
%18 = bitcast i8* %17 to <8 x i16>*
store <8 x i16> %15, <8 x i16>* %18
%19 = add <8 x i16> %4, <i16 32, i16 32, i16 32, i16 32, i16 32, i16 32, i16 32, i16 32>
%20 = shl nuw i64 %3, 1
%21 = or i64 %20, 64
%22 = getelementptr i8, i8* %1, i64 %21
%23 = add <8 x i16> %4, <i16 40, i16 40, i16 40, i16 40, i16 40, i16 40, i16 40, i16 40>
%24 = bitcast i8* %22 to <8 x i16>*
store <8 x i16> %19, <8 x i16>* %24
%25 = getelementptr i8, i8* %22, i64 16
%26 = bitcast i8* %25 to <8 x i16>*
store <8 x i16> %23, <8 x i16>* %26
%27 = add <8 x i16> %4, <i16 48, i16 48, i16 48, i16 48, i16 48, i16 48, i16 48, i16 48>
%28 = shl nuw i64 %3, 1
%29 = or i64 %28, 96
%30 = getelementptr i8, i8* %1, i64 %29
%31 = add <8 x i16> %4, <i16 56, i16 56, i16 56, i16 56, i16 56, i16 56, i16 56, i16 56>
%32 = bitcast i8* %30 to <8 x i16>*
store <8 x i16> %27, <8 x i16>* %32
%33 = getelementptr i8, i8* %30, i64 16
%34 = bitcast i8* %33 to <8 x i16>*
store <8 x i16> %31, <8 x i16>* %34
%35 = add nuw nsw i64 %3, 64
%36 = add <8 x i16> %4, <i16 64, i16 64, i16 64, i16 64, i16 64, i16 64, i16 64, i16 64>
%37 = icmp eq i64 %35, 2560
br i1 %37, label %38, label %2
38: ; preds = %2
ret i8* %1
}