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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
void array_print(FILE *fp, int *arr, size_t length) {
  size_t i;
  if (length < 1)
    return;
  for (i = 0; i < length - 1; ++i) {
    fprintf(fp, "%d, ", arr[i]);
  }
  fprintf(fp, "%d\n", arr[length - 1]);
}


x86 assembly (clang, -O0):
<array_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x1,-0x18(%rbp)
jae    1134 <array_print+0x24>
jmp    119c <array_print+0x8c>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    117d <array_print+0x6d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe99(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    113c <array_print+0x2c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe6e(%rip),%rsi
call   1030 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<array_print>:
test   %rdx,%rdx
je     117b <array_print+0x6b>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%r15
mov    %rdx,%rbx
add    $0xffffffffffffffff,%rbx
je     1159 <array_print+0x49>
xor    %ebp,%ebp
lea    0xec5(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13,%rbp,4),%edx
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1140 <array_print+0x30>
mov    -0x4(%r13,%r14,4),%edx
lea    0xea0(%rip),%rsi
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fprintf@plt>
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"%d, \00"
@.str.1 = [4 x i8] c"%d\0A\00"
define void @array_print(i32* nocapture %0, i32* nocapture %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %19, label %5
5: ; preds = %3
%6 = add i64 %2, -1
%7 = icmp eq i64 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %5, %8
%9 = phi i64 [ %13, %8 ], [ 0, %5 ]
%10 = getelementptr inbounds i32, i32* %1, i64 %9
%11 = load i32, i32* %10
%12 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = add nuw i64 %9, 1
%14 = icmp eq i64 %13, %6
br i1 %14, label %15, label %8
15: ; preds = %8, %5
%16 = getelementptr inbounds i32, i32* %1, i64 %6
%17 = load i32, i32* %16
%18 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %3, %15
ret void
}