#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*/ VectorAdd(int *, int *, int *, int);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int, int);
int main() {
  int *a, *b, *c;
  a = (int *)malloc(1024 * sizeof(int));
  b = (int *)malloc(1024 * sizeof(int));
  c = (int *)malloc(1024 * sizeof(int));
  for (int i = 0; i < 1024; i++) {
    a[i] = i;
    b[i] = i;
    c[i] = 0;
  }
  VectorAdd(a, b, c, 1024);
  for (int i = 0; i < 10; i++) {
    printf("c[%d] = %d\n", i, c[i]);
  }
  free(a);
  free(b);
  free(c);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1000,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x1000,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x1000,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x400,-0x24(%rbp)
jge    11c6 <main+0x86>
mov    -0x24(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1180 <main+0x40>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    $0x400,%ecx
call   1060 <VectorAdd@plt>
movl   $0x0,-0x28(%rbp)
cmpl   $0xa,-0x28(%rbp)
jge    1215 <main+0xd5>
mov    -0x28(%rbp),%esi
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xdfe(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11e3 <main+0xa3>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x1000,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    $0x1000,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    $0x1000,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0x1000(%r14),%rax
lea    0x1000(%r15),%rsi
lea    0x1000(%rbx),%rdi
cmp    %rsi,%r14
setb   %r9b
cmp    %rax,%r15
setb   %dl
cmp    %rdi,%r14
setb   %cl
cmp    %rax,%rbx
setb   %r8b
cmp    %rdi,%r15
setb   %al
cmp    %rsi,%rbx
setb   %sil
test   %dl,%r9b
jne    1273 <main+0x133>
and    %r8b,%cl
jne    1273 <main+0x133>
and    %sil,%al
jne    1273 <main+0x133>
movdqa 0xe32(%rip),%xmm0
xor    %eax,%eax
movdqa 0xe38(%rip),%xmm1
xorps  %xmm2,%xmm2
movdqa 0xe3d(%rip),%xmm3
movdqa 0xe45(%rip),%xmm4
movdqa 0xe4d(%rip),%xmm5
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movdqa %xmm0,%xmm6
paddd  %xmm1,%xmm6
movdqu %xmm0,(%r14,%rax,4)
movdqu %xmm6,0x10(%r14,%rax,4)
movdqu %xmm0,(%r15,%rax,4)
movdqu %xmm6,0x10(%r15,%rax,4)
movups %xmm2,(%rbx,%rax,4)
movups %xmm2,0x10(%rbx,%rax,4)
movdqa %xmm0,%xmm6
paddd  %xmm3,%xmm6
movdqa %xmm0,%xmm7
paddd  %xmm4,%xmm7
movdqu %xmm6,0x20(%r14,%rax,4)
movdqu %xmm7,0x30(%r14,%rax,4)
movdqu %xmm6,0x20(%r15,%rax,4)
movdqu %xmm7,0x30(%r15,%rax,4)
movups %xmm2,0x20(%rbx,%rax,4)
movups %xmm2,0x30(%rbx,%rax,4)
add    $0x10,%rax
paddd  %xmm5,%xmm0
cmp    $0x400,%rax
jne    1200 <main+0xc0>
jmp    12b0 <main+0x170>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,(%r14,%rax,4)
mov    %eax,(%r15,%rax,4)
movl   $0x0,(%rbx,%rax,4)
lea    0x1(%rax),%ecx
mov    %ecx,0x4(%r14,%rax,4)
mov    %ecx,0x4(%r15,%rax,4)
movl   $0x0,0x4(%rbx,%rax,4)
add    $0x2,%rax
cmp    $0x400,%rax
jne    1280 <main+0x140>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    $0x400,%ecx
call   1060 <VectorAdd@plt>
mov    (%rbx),%edx
lea    0xd84(%rip),%r12
mov    %r12,%rdi
xor    %esi,%esi
call   1040 <printf@plt>
mov    0x4(%rbx),%edx
mov    %r12,%rdi
mov    $0x1,%esi
call   1040 <printf@plt>
mov    0x8(%rbx),%edx
mov    %r12,%rdi
mov    $0x2,%esi
call   1040 <printf@plt>
mov    0xc(%rbx),%edx
mov    %r12,%rdi
mov    $0x3,%esi
call   1040 <printf@plt>
mov    0x10(%rbx),%edx
mov    %r12,%rdi
mov    $0x4,%esi
call   1040 <printf@plt>
mov    0x14(%rbx),%edx
mov    %r12,%rdi
mov    $0x5,%esi
call   1040 <printf@plt>
mov    0x18(%rbx),%edx
mov    %r12,%rdi
mov    $0x6,%esi
call   1040 <printf@plt>
mov    0x1c(%rbx),%edx
mov    %r12,%rdi
mov    $0x7,%esi
call   1040 <printf@plt>
mov    0x20(%rbx),%edx
mov    %r12,%rdi
mov    $0x8,%esi
call   1040 <printf@plt>
mov    0x24(%rbx),%edx
mov    %r12,%rdi
mov    $0x9,%esi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"c[%d] = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i64 @malloc(i32 4096)
%8 = inttoptr i64 %7 to i32*
store i32* %8, i32** %2
%9 = call i64 @malloc(i32 4096)
%10 = inttoptr i64 %9 to i32*
store i32* %10, i32** %3
%11 = call i64 @malloc(i32 4096)
%12 = inttoptr i64 %11 to i32*
store i32* %12, i32** %4
store i32 0, i32* %5
br label %13
13: ; preds = %31, %0
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 1024
br i1 %15, label %16, label %34
16: ; preds = %13
%17 = load i32, i32* %5
%18 = load i32*, i32** %2
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
store i32 %17, i32* %21
%22 = load i32, i32* %5
%23 = load i32*, i32** %3
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
store i32 %22, i32* %26
%27 = load i32*, i32** %4
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
store i32 0, i32* %30
br label %31
31: ; preds = %16
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %13
34: ; preds = %13
%35 = load i32*, i32** %2
%36 = load i32*, i32** %3
%37 = load i32*, i32** %4
%38 = call i32 @VectorAdd(i32* %35, i32* %36, i32* %37, i32 1024)
store i32 0, i32* %6
br label %39
39: ; preds = %50, %34
%40 = load i32, i32* %6
%41 = icmp slt i32 %40, 10
br i1 %41, label %42, label %53
42: ; preds = %39
%43 = load i32, i32* %6
%44 = load i32*, i32** %4
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %44, i64 %46
%48 = load i32, i32* %47
%49 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %43, i32 %48)
br label %50
50: ; preds = %42
%51 = load i32, i32* %6
%52 = add nsw i32 %51, 1
store i32 %52, i32* %6
br label %39
53: ; preds = %39
%54 = load i32*, i32** %2
%55 = call i32 @free(i32* %54)
%56 = load i32*, i32** %3
%57 = call i32 @free(i32* %56)
%58 = load i32*, i32** %4
%59 = call i32 @free(i32* %58)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"c[%d] = %d\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 4096)
%2 = inttoptr i64 %1 to i32*
%3 = inttoptr i64 %1 to i8*
%4 = tail call i64 @malloc(i32 4096)
%5 = inttoptr i64 %4 to i32*
%6 = inttoptr i64 %4 to i8*
%7 = tail call i64 @malloc(i32 4096)
%8 = inttoptr i64 %7 to i32*
%9 = inttoptr i64 %7 to i8*
%10 = getelementptr i32, i32* %2, i64 1024
%11 = bitcast i32* %10 to i8*
%12 = getelementptr i32, i32* %5, i64 1024
%13 = bitcast i32* %12 to i8*
%14 = getelementptr i32, i32* %8, i64 1024
%15 = bitcast i32* %14 to i8*
%16 = icmp ult i8* %3, %13
%17 = icmp ult i8* %6, %11
%18 = and i1 %16, %17
%19 = icmp ult i8* %3, %15
%20 = icmp ult i8* %9, %11
%21 = and i1 %19, %20
%22 = or i1 %18, %21
%23 = icmp ult i8* %6, %15
%24 = icmp ult i8* %9, %13
%25 = and i1 %23, %24
%26 = or i1 %22, %25
br i1 %26, label %95, label %27
27: ; preds = %0, %27
%28 = phi i64 [ %58, %27 ], [ 0, %0 ]
%29 = phi <4 x i32> [ %59, %27 ], [ <i32 0, i32 1, i32 2, i32 3>, %0 ]
%30 = add <4 x i32> %29, <i32 4, i32 4, i32 4, i32 4>
%31 = getelementptr inbounds i32, i32* %2, i64 %28
%32 = bitcast i32* %31 to <4 x i32>*
store <4 x i32> %29, <4 x i32>* %32
%33 = getelementptr inbounds i32, i32* %31, i64 4
%34 = bitcast i32* %33 to <4 x i32>*
store <4 x i32> %30, <4 x i32>* %34
%35 = getelementptr inbounds i32, i32* %5, i64 %28
%36 = bitcast i32* %35 to <4 x i32>*
store <4 x i32> %29, <4 x i32>* %36
%37 = getelementptr inbounds i32, i32* %35, i64 4
%38 = bitcast i32* %37 to <4 x i32>*
store <4 x i32> %30, <4 x i32>* %38
%39 = getelementptr inbounds i32, i32* %8, i64 %28
%40 = bitcast i32* %39 to <4 x i32>*
store <4 x i32> zeroinitializer, <4 x i32>* %40
%41 = getelementptr inbounds i32, i32* %39, i64 4
%42 = bitcast i32* %41 to <4 x i32>*
store <4 x i32> zeroinitializer, <4 x i32>* %42
%43 = or i64 %28, 8
%44 = add <4 x i32> %29, <i32 8, i32 8, i32 8, i32 8>
%45 = add <4 x i32> %29, <i32 12, i32 12, i32 12, i32 12>
%46 = getelementptr inbounds i32, i32* %2, i64 %43
%47 = bitcast i32* %46 to <4 x i32>*
store <4 x i32> %44, <4 x i32>* %47
%48 = getelementptr inbounds i32, i32* %46, i64 4
%49 = bitcast i32* %48 to <4 x i32>*
store <4 x i32> %45, <4 x i32>* %49
%50 = getelementptr inbounds i32, i32* %5, i64 %43
%51 = bitcast i32* %50 to <4 x i32>*
store <4 x i32> %44, <4 x i32>* %51
%52 = getelementptr inbounds i32, i32* %50, i64 4
%53 = bitcast i32* %52 to <4 x i32>*
store <4 x i32> %45, <4 x i32>* %53
%54 = getelementptr inbounds i32, i32* %8, i64 %43
%55 = bitcast i32* %54 to <4 x i32>*
store <4 x i32> zeroinitializer, <4 x i32>* %55
%56 = getelementptr inbounds i32, i32* %54, i64 4
%57 = bitcast i32* %56 to <4 x i32>*
store <4 x i32> zeroinitializer, <4 x i32>* %57
%58 = add nuw nsw i64 %28, 16
%59 = add <4 x i32> %29, <i32 16, i32 16, i32 16, i32 16>
%60 = icmp eq i64 %58, 1024
br i1 %60, label %61, label %27
61: ; preds = %27, %95
%62 = tail call i32 @VectorAdd(i32* %2, i32* %5, i32* %8, i32 1024)
%63 = load i32, i32* %8
%64 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 0, i32 %63)
%65 = getelementptr inbounds i32, i32* %8, i64 1
%66 = load i32, i32* %65
%67 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 1, i32 %66)
%68 = getelementptr inbounds i32, i32* %8, i64 2
%69 = load i32, i32* %68
%70 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 2, i32 %69)
%71 = getelementptr inbounds i32, i32* %8, i64 3
%72 = load i32, i32* %71
%73 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 3, i32 %72)
%74 = getelementptr inbounds i32, i32* %8, i64 4
%75 = load i32, i32* %74
%76 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 4, i32 %75)
%77 = getelementptr inbounds i32, i32* %8, i64 5
%78 = load i32, i32* %77
%79 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 5, i32 %78)
%80 = getelementptr inbounds i32, i32* %8, i64 6
%81 = load i32, i32* %80
%82 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 6, i32 %81)
%83 = getelementptr inbounds i32, i32* %8, i64 7
%84 = load i32, i32* %83
%85 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 7, i32 %84)
%86 = getelementptr inbounds i32, i32* %8, i64 8
%87 = load i32, i32* %86
%88 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 8, i32 %87)
%89 = getelementptr inbounds i32, i32* %8, i64 9
%90 = load i32, i32* %89
%91 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 9, i32 %90)
%92 = tail call i32 @free(i32* %2)
%93 = tail call i32 @free(i32* %5)
%94 = tail call i32 @free(i32* %8)
ret i32 0
95: ; preds = %0, %95
%96 = phi i64 [ %106, %95 ], [ 0, %0 ]
%97 = getelementptr inbounds i32, i32* %2, i64 %96
%98 = trunc i64 %96 to i32
store i32 %98, i32* %97
%99 = getelementptr inbounds i32, i32* %5, i64 %96
store i32 %98, i32* %99
%100 = getelementptr inbounds i32, i32* %8, i64 %96
store i32 0, i32* %100
%101 = or i64 %96, 1
%102 = getelementptr inbounds i32, i32* %2, i64 %101
%103 = trunc i64 %101 to i32
store i32 %103, i32* %102
%104 = getelementptr inbounds i32, i32* %5, i64 %101
store i32 %103, i32* %104
%105 = getelementptr inbounds i32, i32* %8, i64 %101
store i32 0, i32* %105
%106 = add nuw nsw i64 %96, 2
%107 = icmp eq i64 %106, 1024
br i1 %107, label %61, label %95
}