char *myfunction(char *array, int len) {
  char *myarray, i;
  printf("len : %d \n", len);
  myarray = (char *)malloc(len * sizeof(int));
  printf("myarray : %u \n", myarray);
  for (i = 0; i < len; i++) {
    myarray[i] = array[i];
    printf("i : %d ; len : %d \n", i, len);
  }
  return myarray;
}


x86 assembly (clang, -O0):
<myfunction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xedf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0xc(%rbp),%rdi
shl    $0x2,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x0,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ae <myfunction+0x8e>
mov    -0x8(%rbp),%rax
movsbq -0x19(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
movsbq -0x19(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
movsbl -0x19(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x19(%rbp),%al
add    $0x1,%al
mov    %al,-0x19(%rbp)
jmp    1167 <myfunction+0x47>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myfunction>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xee4(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movslq %ebp,%rbx
lea    0x0(,%rbx,4),%rdi
call   1040 <malloc@plt>
mov    %rax,%r15
lea    0xeab(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
test   %ebx,%ebx
jle    1194 <myfunction+0x74>
lea    0xea5(%rip),%r12
xor    %eax,%eax
nopl   0x0(%rax)
movslq %eax,%rbx
movzbl (%r14,%rbx,1),%eax
mov    %al,(%r15,%rbx,1)
mov    %r12,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%bl
movsbl %bl,%eax
cmp    %ebp,%eax
jl     1170 <myfunction+0x50>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"len : %d \0A\00"
@.str.1 = [15 x i8] c"myarray : %u \0A\00"
@.str.2 = [20 x i8] c"i : %d ; len : %d \0A\00"
define i8* @myfunction(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 4
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %13)
store i8 0, i8* %6
br label %15
15: ; preds = %34, %2
%16 = load i8, i8* %6
%17 = sext i8 %16 to i32
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %37
20: ; preds = %15
%21 = load i8*, i8** %3
%22 = load i8, i8* %6
%23 = sext i8 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = load i8*, i8** %5
%27 = load i8, i8* %6
%28 = sext i8 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 %25, i8* %29
%30 = load i8, i8* %6
%31 = sext i8 %30 to i32
%32 = load i32, i32* %4
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %31, i32 %32)
br label %34
34: ; preds = %20
%35 = load i8, i8* %6
%36 = add i8 %35, 1
store i8 %36, i8* %6
br label %15
37: ; preds = %15
%38 = load i8*, i8** %5
ret i8* %38
}

LLVM IR (-O2):
@.str = [11 x i8] c"len : %d \0A\00"
@.str.1 = [15 x i8] c"myarray : %u \0A\00"
@.str.2 = [20 x i8] c"i : %d ; len : %d \0A\00"
define i8* @myfunction(i8* nocapture %0, i32 %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %1)
%4 = sext i32 %1 to i64
%5 = shl nsw i64 %4, 2
%6 = tail call i8* @malloc(i64 %5)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %20
9: ; preds = %2, %9
%10 = phi i32 [ %18, %9 ], [ 0, %2 ]
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = getelementptr inbounds i8, i8* %6, i64 %11
store i8 %13, i8* %14
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %10, i32 %1)
%16 = shl nsw i32 %10, 24
%17 = add i32 %16, 16777216
%18 = ashr exact i32 %17, 24
%19 = icmp slt i32 %18, %1
br i1 %19, label %9, label %20
20: ; preds = %9, %2
ret i8* %6
}