#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*/ assert(int);
int /*<<< orphan*/ printf(char *, ...);
void fillArray(int *array, int len) {
  printf("Filling an array at address %p with %d "
         "values\n",
         array, len);
  for (int i = 0; i < len; ++i) {
    array[i] = i * 3 + 2;
    assert(array[i] == i * 3 + 2);
  }
  printf("Done!\n");
}


x86 assembly (clang, -O0):
<fillArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1198 <fillArray+0x78>
imul   $0x3,-0x10(%rbp),%edx
add    $0x2,%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
imul   $0x3,-0x10(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114b <fillArray+0x2b>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fillArray>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xebd(%rip),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jle    117a <fillArray+0x4a>
mov    %ebp,%r15d
mov    $0x2,%ebx
xor    %ebp,%ebp
nopl   (%rax)
mov    %ebx,(%r14,%rbp,4)
mov    $0x1,%edi
call   1050 <assert@plt>
add    $0x1,%rbp
add    $0x3,%ebx
cmp    %rbp,%r15
jne    1160 <fillArray+0x30>
lea    0xeae(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [47 x i8] c"Filling an array at address %p with %d values\0A\00"
@.str.1 = [7 x i8] c"Done!\0A\00"
define void @fillArray(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%6 = load i32*, i32** %3
%7 = load i32, i32* %4
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32* %6, i32 %7)
store i32 0, i32* %5
br label %9
9: ; preds = %32, %2
%10 = load i32, i32* %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %35
13: ; preds = %9
%14 = load i32, i32* %5
%15 = mul nsw i32 %14, 3
%16 = add nsw i32 %15, 2
%17 = load i32*, i32** %3
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
store i32 %16, i32* %20
%21 = load i32*, i32** %3
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = load i32, i32* %24
%26 = load i32, i32* %5
%27 = mul nsw i32 %26, 3
%28 = add nsw i32 %27, 2
%29 = icmp eq i32 %25, %28
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
br label %32
32: ; preds = %13
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %9
35: ; preds = %9
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [47 x i8] c"Filling an array at address %p with %d values\0A\00"
@str = [6 x i8] c"Done!\00"
define void @fillArray(i32* %0, i32 %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32* %0, i32 %1)
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = zext i32 %1 to i64
br label %9
7: ; preds = %9, %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
ret void
9: ; preds = %5, %9
%10 = phi i64 [ 0, %5 ], [ %16, %9 ]
%11 = trunc i64 %10 to i32
%12 = mul nsw i32 %11, 3
%13 = add nuw nsw i32 %12, 2
%14 = getelementptr inbounds i32, i32* %0, i64 %10
store i32 %13, i32* %14
%15 = tail call i32 @assert(i32 1)
%16 = add nuw nsw i64 %10, 1
%17 = icmp eq i64 %16, %6
br i1 %17, label %7, label %9
}