#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*/ weights;

/* Variables and functions */
int /*<<< orphan*/ free(long long *);
long long *malloc(int const);
int /*<<< orphan*/ printf(char *, int, long long);
void test2() {
  const int NUM_WEIGHTS = 5;
  long long *weights = malloc(NUM_WEIGHTS * sizeof(weights));
  for (int i = 0; i < NUM_WEIGHTS; i++) {
    weights[i] = 100 + i;
    printf("%d: %lld", i, weights[i]);
  }
  free(weights);
  weights[0] = 0;
}


x86 assembly (clang, -O0):
<test2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x5,-0x4(%rbp)
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    119c <test2+0x6c>
mov    -0x14(%rbp),%eax
add    $0x64,%eax
movslq %eax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1154 <test2+0x24>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test2>:
push   %r14
push   %rbx
push   %rax
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xed8(%rip),%r14
mov    $0x64,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <printf@plt>
movaps 0xea2(%rip),%xmm0
movups %xmm0,(%rbx)
mov    $0x65,%edx
mov    %r14,%rdi
mov    $0x1,%esi
call   1040 <printf@plt>
mov    $0x66,%edx
mov    %r14,%rdi
mov    $0x2,%esi
call   1040 <printf@plt>
movaps 0xe84(%rip),%xmm0
movups %xmm0,0x10(%rbx)
mov    $0x67,%edx
mov    %r14,%rdi
mov    $0x3,%esi
call   1040 <printf@plt>
movq   $0x68,0x20(%rbx)
mov    $0x68,%edx
mov    %r14,%rdi
mov    $0x4,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"%d: %lld\00"
define void @test2() {
%1 = alloca i32
%2 = alloca i64*
%3 = alloca i32
store i32 5, i32* %1
%4 = call i64* @malloc(i32 40)
store i64* %4, i64** %2
store i32 0, i32* %3
br label %5
5: ; preds = %23, %0
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 5
br i1 %7, label %8, label %26
8: ; preds = %5
%9 = load i32, i32* %3
%10 = add nsw i32 100, %9
%11 = sext i32 %10 to i64
%12 = load i64*, i64** %2
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i64, i64* %12, i64 %14
store i64 %11, i64* %15
%16 = load i32, i32* %3
%17 = load i64*, i64** %2
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i64, i64* %17, i64 %19
%21 = load i64, i64* %20
%22 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %16, i64 %21)
br label %23
23: ; preds = %8
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %5
26: ; preds = %5
%27 = load i64*, i64** %2
%28 = call i32 @free(i64* %27)
%29 = load i64*, i64** %2
%30 = getelementptr inbounds i64, i64* %29, i64 0
store i64 0, i64* %30
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"%d: %lld\00"
define void @test2() {
%1 = tail call i64* @malloc(i32 40)
%2 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 0, i64 100)
%3 = bitcast i64* %1 to <2 x i64>*
store <2 x i64> <i64 100, i64 101>, <2 x i64>* %3
%4 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 1, i64 101)
%5 = getelementptr inbounds i64, i64* %1, i64 2
%6 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 2, i64 102)
%7 = bitcast i64* %5 to <2 x i64>*
store <2 x i64> <i64 102, i64 103>, <2 x i64>* %7
%8 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 3, i64 103)
%9 = getelementptr inbounds i64, i64* %1, i64 4
store i64 104, i64* %9
%10 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 4, i64 104)
%11 = tail call i32 @free(i64* %1)
ret void
}