#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*/ printf(char *, ...);
void print_vec(int n, double *b) {
  if (n > 0)
    printf("[%f", b[0]);
  for (int row = 1; row < n; row++)
    printf(", %f", b[row]);
  printf("]");
}


x86 assembly (clang, -O0):
<print_vec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    113f <print_vec+0x2f>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
lea    0xec8(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    117b <print_vec+0x6b>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe9e(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1146 <print_vec+0x36>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_vec>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
jle    1179 <print_vec+0x59>
mov    %rsi,%r15
mov    %edi,%ebp
movsd  (%rsi),%xmm0
lea    0xec5(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
cmp    $0x1,%ebp
je     1179 <print_vec+0x59>
mov    %ebp,%ebp
mov    $0x1,%ebx
lea    0xeaf(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
movsd  (%r15,%rbx,8),%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <print_vec+0x40>
mov    $0x5d,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

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