#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 */
scalar_t__ malloc(int);
int *foo(int *x) {
  int *m = (int *)malloc(sizeof(int) * 10);
  int i;
  for (i = 0; i < 10; i++) {
    m[i] = x[i];
    x[i] = 0;
  }
  return m;
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x28,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    116e <foo+0x5e>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1131 <foo+0x21>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
push   %rbx
mov    %rdi,%rbx
mov    $0x28,%edi
call   1030 <malloc@plt>
mov    (%rbx),%ecx
mov    %ecx,(%rax)
movl   $0x0,(%rbx)
mov    0x4(%rbx),%ecx
mov    %ecx,0x4(%rax)
movl   $0x0,0x4(%rbx)
mov    0x8(%rbx),%ecx
mov    %ecx,0x8(%rax)
movl   $0x0,0x8(%rbx)
mov    0xc(%rbx),%ecx
mov    %ecx,0xc(%rax)
movl   $0x0,0xc(%rbx)
mov    0x10(%rbx),%ecx
mov    %ecx,0x10(%rax)
movl   $0x0,0x10(%rbx)
mov    0x14(%rbx),%ecx
mov    %ecx,0x14(%rax)
movl   $0x0,0x14(%rbx)
mov    0x18(%rbx),%ecx
mov    %ecx,0x18(%rax)
movl   $0x0,0x18(%rbx)
mov    0x1c(%rbx),%ecx
mov    %ecx,0x1c(%rax)
movl   $0x0,0x1c(%rbx)
mov    0x20(%rbx),%ecx
mov    %ecx,0x20(%rax)
movl   $0x0,0x20(%rbx)
mov    0x24(%rbx),%ecx
mov    %ecx,0x24(%rax)
movl   $0x0,0x24(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
define i32* @foo(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %2
%5 = call i64 @malloc(i32 40)
%6 = inttoptr i64 %5 to i32*
store i32* %6, i32** %3
store i32 0, i32* %4
br label %7
7: ; preds = %24, %1
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 10
br i1 %9, label %10, label %27
10: ; preds = %7
%11 = load i32*, i32** %2
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %11, i64 %13
%15 = load i32, i32* %14
%16 = load i32*, i32** %3
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
store i32 %15, i32* %19
%20 = load i32*, i32** %2
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
store i32 0, i32* %23
br label %24
24: ; preds = %10
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %7
27: ; preds = %7
%28 = load i32*, i32** %3
ret i32* %28
}

LLVM IR (-O2):
define i32* @foo(i32* nocapture %0) {
%2 = tail call i64 @malloc(i32 40)
%3 = inttoptr i64 %2 to i32*
%4 = load i32, i32* %0
store i32 %4, i32* %3
store i32 0, i32* %0
%5 = getelementptr inbounds i32, i32* %0, i64 1
%6 = load i32, i32* %5
%7 = getelementptr inbounds i32, i32* %3, i64 1
store i32 %6, i32* %7
store i32 0, i32* %5
%8 = getelementptr inbounds i32, i32* %0, i64 2
%9 = load i32, i32* %8
%10 = getelementptr inbounds i32, i32* %3, i64 2
store i32 %9, i32* %10
store i32 0, i32* %8
%11 = getelementptr inbounds i32, i32* %0, i64 3
%12 = load i32, i32* %11
%13 = getelementptr inbounds i32, i32* %3, i64 3
store i32 %12, i32* %13
store i32 0, i32* %11
%14 = getelementptr inbounds i32, i32* %0, i64 4
%15 = load i32, i32* %14
%16 = getelementptr inbounds i32, i32* %3, i64 4
store i32 %15, i32* %16
store i32 0, i32* %14
%17 = getelementptr inbounds i32, i32* %0, i64 5
%18 = load i32, i32* %17
%19 = getelementptr inbounds i32, i32* %3, i64 5
store i32 %18, i32* %19
store i32 0, i32* %17
%20 = getelementptr inbounds i32, i32* %0, i64 6
%21 = load i32, i32* %20
%22 = getelementptr inbounds i32, i32* %3, i64 6
store i32 %21, i32* %22
store i32 0, i32* %20
%23 = getelementptr inbounds i32, i32* %0, i64 7
%24 = load i32, i32* %23
%25 = getelementptr inbounds i32, i32* %3, i64 7
store i32 %24, i32* %25
store i32 0, i32* %23
%26 = getelementptr inbounds i32, i32* %0, i64 8
%27 = load i32, i32* %26
%28 = getelementptr inbounds i32, i32* %3, i64 8
store i32 %27, i32* %28
store i32 0, i32* %26
%29 = getelementptr inbounds i32, i32* %0, i64 9
%30 = load i32, i32* %29
%31 = getelementptr inbounds i32, i32* %3, i64 9
store i32 %30, i32* %31
store i32 0, i32* %29
ret i32* %3
}