void print_array(const int *array, const int size, const char *tag) {
  printf("%s - %s [", tag, __func__);
  for (unsigned int i = 0; i < size; ++i) {
    printf("%d", array[i]);
    if (i < size - 1)
      printf(",");
  }
  printf("]\n");
}


x86 assembly (clang, -O0):
<print_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xed2(%rip),%rdi
lea    0xed5(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1199 <print_array+0x89>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    (%rax,%rcx,4),%esi
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jae    1186 <print_array+0x76>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    118b <print_array+0x7b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1143 <print_array+0x33>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_array>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r15
lea    0xeba(%rip),%rdi
lea    0xebd(%rip),%rax
mov    %rdx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
test   %r14d,%r14d
je     11a8 <print_array+0x78>
lea    -0x1(%r14),%r12d
mov    %r14d,%r13d
lea    0xea9(%rip),%r14
xor    %ebx,%ebx
jmp    1189 <print_array+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r13
je     11a8 <print_array+0x78>
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %r12,%rbx
jae    1180 <print_array+0x50>
mov    $0x2c,%edi
call   1030 <putchar@plt>
jmp    1180 <print_array+0x50>
lea    0xe6a(%rip),%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <puts@plt>

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

LLVM IR (-O2):
@.str = [10 x i8] c"%s - %s [\00"
@__func__.print_array = [12 x i8] c"print_array\00"
@.str.1 = [3 x i8] c"%d\00"
@str = [2 x i8] c"]\00"
define void @print_array(i32* nocapture %0, i32 %1, i8* %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.print_array, i64 0, i64 0))
%5 = icmp eq i32 %1, 0
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = add nsw i32 %1, -1
%8 = zext i32 %7 to i64
%9 = zext i32 %1 to i64
br label %12
10: ; preds = %20, %3
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret void
12: ; preds = %6, %20
%13 = phi i64 [ 0, %6 ], [ %21, %20 ]
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = load i32, i32* %14
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = icmp ult i64 %13, %8
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = tail call i32 @putchar(i32 44)
br label %20
20: ; preds = %12, %18
%21 = add nuw nsw i64 %13, 1
%22 = icmp eq i64 %21, %9
br i1 %22, label %10, label %12
}