#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 *realloc(char *, int);
int main(void) {
  int i, t;
  char *x = malloc(1000);
  for (i = 0; i < 1000; i++)
    x[i] &= (i & 0xff);
  x = realloc(x, 10000);
  for (i = 0; i < 1000; i++)
    t += x[i];
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x3e8,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jge    1179 <main+0x59>
mov    -0x8(%rbp),%esi
and    $0xff,%esi
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
and    %esi,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1144 <main+0x24>
mov    -0x18(%rbp),%rdi
mov    $0x2710,%esi
call   1040 <realloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jge    11bf <main+0x9f>
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1192 <main+0x72>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0x3e8,%edi
call   1030 <malloc@plt>
movb   $0x0,(%rax)
movdqa 0xeca(%rip),%xmm0
mov    $0x11,%ecx
movdqa 0xecd(%rip),%xmm1
movdqa 0xed5(%rip),%xmm2
nopl   0x0(%rax,%rax,1)
movdqu -0x10(%rax,%rcx,1),%xmm3
movdqu (%rax,%rcx,1),%xmm4
pand   %xmm0,%xmm3
movdqu %xmm3,-0x10(%rax,%rcx,1)
movdqa %xmm0,%xmm3
paddb  %xmm1,%xmm3
pand   %xmm4,%xmm3
movdqu %xmm3,(%rax,%rcx,1)
paddb  %xmm2,%xmm0
add    $0x20,%rcx
cmp    $0x3f1,%rcx
jne    1150 <main+0x30>
andb   $0xe1,0x3e1(%rax)
andb   $0xe2,0x3e2(%rax)
andb   $0xe3,0x3e3(%rax)
andb   $0xe4,0x3e4(%rax)
andb   $0xe5,0x3e5(%rax)
andb   $0xe6,0x3e6(%rax)
andb   $0xe7,0x3e7(%rax)
mov    %rax,%rdi
mov    $0x2710,%esi
call   1040 <realloc@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 0, i32* %1
%5 = call i8* @malloc(i32 1000)
store i8* %5, i8** %4
store i32 0, i32* %2
br label %6
6: ; preds = %20, %0
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 1000
br i1 %8, label %9, label %23
9: ; preds = %6
%10 = load i32, i32* %2
%11 = and i32 %10, 255
%12 = load i8*, i8** %4
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = and i32 %17, %11
%19 = trunc i32 %18 to i8
store i8 %19, i8* %15
br label %20
20: ; preds = %9
%21 = load i32, i32* %2
%22 = add nsw i32 %21, 1
store i32 %22, i32* %2
br label %6
23: ; preds = %6
%24 = load i8*, i8** %4
%25 = call i8* @realloc(i8* %24, i32 10000)
store i8* %25, i8** %4
store i32 0, i32* %2
br label %26
26: ; preds = %38, %23
%27 = load i32, i32* %2
%28 = icmp slt i32 %27, 1000
br i1 %28, label %29, label %41
29: ; preds = %26
%30 = load i8*, i8** %4
%31 = load i32, i32* %2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = load i32, i32* %3
%37 = add nsw i32 %36, %35
store i32 %37, i32* %3
br label %38
38: ; preds = %29
%39 = load i32, i32* %2
%40 = add nsw i32 %39, 1
store i32 %40, i32* %2
br label %26
41: ; preds = %26
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call dereferenceable_or_null(1000) i8* @malloc(i32 1000)
store i8 0, i8* %1
br label %2
2: ; preds = %2, %0
%3 = phi i64 [ 0, %0 ], [ %18, %2 ]
%4 = phi <16 x i8> [ <i8 1, i8 2, i8 3, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16>, %0 ], [ %19, %2 ]
%5 = or i64 %3, 1
%6 = getelementptr inbounds i8, i8* %1, i64 %5
%7 = bitcast i8* %6 to <16 x i8>*
%8 = load <16 x i8>, <16 x i8>* %7
%9 = and <16 x i8> %8, %4
%10 = bitcast i8* %6 to <16 x i8>*
store <16 x i8> %9, <16 x i8>* %10
%11 = add <16 x i8> %4, <i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16>
%12 = or i64 %3, 17
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = bitcast i8* %13 to <16 x i8>*
%15 = load <16 x i8>, <16 x i8>* %14
%16 = and <16 x i8> %15, %11
%17 = bitcast i8* %13 to <16 x i8>*
store <16 x i8> %16, <16 x i8>* %17
%18 = add nuw nsw i64 %3, 32
%19 = add <16 x i8> %4, <i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32>
%20 = icmp eq i64 %18, 992
br i1 %20, label %21, label %2
21: ; preds = %2
%22 = getelementptr inbounds i8, i8* %1, i64 993
%23 = load i8, i8* %22
%24 = getelementptr inbounds i8, i8* %1, i64 993
%25 = and i8 %23, -31
store i8 %25, i8* %24
%26 = getelementptr inbounds i8, i8* %1, i64 994
%27 = load i8, i8* %26
%28 = getelementptr inbounds i8, i8* %1, i64 994
%29 = and i8 %27, -30
store i8 %29, i8* %28
%30 = getelementptr inbounds i8, i8* %1, i64 995
%31 = load i8, i8* %30
%32 = getelementptr inbounds i8, i8* %1, i64 995
%33 = and i8 %31, -29
store i8 %33, i8* %32
%34 = getelementptr inbounds i8, i8* %1, i64 996
%35 = load i8, i8* %34
%36 = getelementptr inbounds i8, i8* %1, i64 996
%37 = and i8 %35, -28
store i8 %37, i8* %36
%38 = getelementptr inbounds i8, i8* %1, i64 997
%39 = load i8, i8* %38
%40 = getelementptr inbounds i8, i8* %1, i64 997
%41 = and i8 %39, -27
store i8 %41, i8* %40
%42 = getelementptr inbounds i8, i8* %1, i64 998
%43 = load i8, i8* %42
%44 = getelementptr inbounds i8, i8* %1, i64 998
%45 = and i8 %43, -26
store i8 %45, i8* %44
%46 = getelementptr inbounds i8, i8* %1, i64 999
%47 = load i8, i8* %46
%48 = getelementptr inbounds i8, i8* %1, i64 999
%49 = and i8 %47, -25
store i8 %49, i8* %48
%50 = tail call i8* @realloc(i8* %1, i32 10000)
ret i32 0
}