#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ printf(char *, ...);
int print_array(int _n, int _array[_n]) {
  int i;
  if (_n <= 0) {
    printf("Array is of invalid length!\n");
    return EXIT_FAILURE;
  }
  printf("[");
  for (i = 0; i < _n; i++) {
    if (i < _n - 1) {
      printf("%d, ", _array[i]);
    } else {
      printf("%d", _array[i]);
    }
  }
  printf("]");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<print_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     1148 <print_array+0x38>
lea    0xed0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2ea2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11de <print_array+0xce>
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11c4 <print_array+0xb4>
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1198 <print_array+0x88>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b1 <print_array+0xa1>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b6 <print_array+0xa6>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115d <print_array+0x4d>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    11a1 <print_array+0x71>
mov    %rsi,%r15
mov    %edi,%r14d
mov    $0x5b,%edi
call   1030 <putchar@plt>
lea    -0x1(%r14),%r12d
mov    %r14d,%ebx
lea    0xea3(%rip),%r14
lea    0xea1(%rip),%r13
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
cmp    %r12,%rbp
mov    (%r15,%rbp,4),%esi
mov    %r13,%rdi
cmovb  %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1170 <print_array+0x40>
mov    $0x5d,%edi
call   1030 <putchar@plt>
mov    0x2e39(%rip),%rax
jmp    11b4 <print_array+0x84>
lea    0xe60(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Array is of invalid length!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"[\00"
@.str.2 = [5 x i8] c"%d, \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [2 x i8] c"]\00"
@EXIT_SUCCESS = global i32 0
define i32 @print_array(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%7 = load i32, i32* %4
%8 = zext i32 %7 to i64
%9 = load i32, i32* %4
%10 = icmp sle i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
store i32 %13, i32* %3
br label %46
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %6
br label %16
16: ; preds = %40, %14
%17 = load i32, i32* %6
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %43
20: ; preds = %16
%21 = load i32, i32* %6
%22 = load i32, i32* %4
%23 = sub nsw i32 %22, 1
%24 = icmp slt i32 %21, %23
br i1 %24, label %25, label %32
25: ; preds = %20
%26 = load i32*, i32** %5
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = load i32, i32* %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %39
32: ; preds = %20
%33 = load i32*, i32** %5
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %32, %25
br label %40
40: ; preds = %39
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %16
43: ; preds = %16
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%45 = load i32, i32* @EXIT_SUCCESS
store i32 %45, i32* %3
br label %46
46: ; preds = %43, %11
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c"%d, \00"
@.str.3 = [3 x i8] c"%d\00"
@EXIT_SUCCESS = global i32 0
@str = [28 x i8] c"Array is of invalid length!\00"
define i32 @print_array(i32 %0, i32* nocapture %1) {
%3 = icmp slt i32 %0, 1
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %22
6: ; preds = %2
%7 = tail call i32 @putchar(i32 91)
%8 = add nsw i32 %0, -1
%9 = zext i32 %8 to i64
%10 = zext i32 %0 to i64
br label %11
11: ; preds = %6, %11
%12 = phi i64 [ 0, %6 ], [ %18, %11 ]
%13 = icmp ult i64 %12, %9
%14 = getelementptr inbounds i32, i32* %1, i64 %12
%15 = load i32, i32* %14
%16 = select i1 %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %16, i32 %15)
%18 = add nuw nsw i64 %12, 1
%19 = icmp eq i64 %18, %10
br i1 %19, label %20, label %11
20: ; preds = %11
%21 = tail call i32 @putchar(i32 93)
br label %22
22: ; preds = %20, %4
%23 = phi i32* [ @EXIT_FAILURE, %4 ], [ @EXIT_SUCCESS, %20 ]
%24 = load i32, i32* %23
ret i32 %24
}