#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double, double);
int /*<<< orphan*/ printf(char *, char *);
void output_array(int n, double *A_re, double *A_im, char *outfile) {
  int i;
  FILE *fp;
  fp = fopen(outfile, "w");
  if (fp == NULL) {
    printf("could not open %s for output\n", outfile);
    exit(-1);
  }
  for (i = 0; i < n; i++)
    fprintf(fp, "%lf %lf\n", A_re[i], A_im[i]);
  fclose(fp);
}


x86 assembly (clang, -O0):
<output_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11a0 <output_array+0x50>
mov    -0x20(%rbp),%rsi
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11eb <output_array+0x9b>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
lea    0xe48(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a7 <output_array+0x57>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
lea    0xe93(%rip),%rsi
mov    %rcx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c6 <output_array+0x76>
mov    %rax,%r13
test   %ebp,%ebp
jle    11b0 <output_array+0x60>
mov    %ebp,%ebp
xor    %ebx,%ebx
lea    0xe94(%rip),%r12
nopl   0x0(%rax)
movsd  (%r15,%rbx,8),%xmm0
movsd  (%r14,%rbx,8),%xmm1
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1190 <output_array+0x40>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
lea    0xe35(%rip),%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [30 x i8] c"could not open %s for output\0A\00"
@.str.2 = [9 x i8] c"%lf %lf\0A\00"
define void @output_array(i32 %0, double* %1, double* %2, i8* %3) {
%5 = alloca i32
%6 = alloca double*
%7 = alloca double*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
store i32 %0, i32* %5
store double* %1, double** %6
store double* %2, double** %7
store i8* %3, i8** %8
%11 = load i8*, i8** %8
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %10
%13 = load i32*, i32** %10
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %4
%16 = load i8*, i8** %8
%17 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %4
store i32 0, i32* %9
br label %20
20: ; preds = %37, %19
%21 = load i32, i32* %9
%22 = load i32, i32* %5
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %40
24: ; preds = %20
%25 = load i32*, i32** %10
%26 = load double*, double** %6
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
%31 = load double*, double** %7
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
%35 = load double, double* %34
%36 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %30, double %35)
br label %37
37: ; preds = %24
%38 = load i32, i32* %9
%39 = add nsw i32 %38, 1
store i32 %39, i32* %9
br label %20
40: ; preds = %20
%41 = load i32*, i32** %10
%42 = call i32 @fclose(i32* %41)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [30 x i8] c"could not open %s for output\0A\00"
@.str.2 = [9 x i8] c"%lf %lf\0A\00"
define void @output_array(i32 %0, double* nocapture %1, double* nocapture %2, i8* %3) {
%5 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %23
9: ; preds = %7
%10 = zext i32 %0 to i64
br label %14
11: ; preds = %4
%12 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %9, %14
%15 = phi i64 [ 0, %9 ], [ %21, %14 ]
%16 = getelementptr inbounds double, double* %1, i64 %15
%17 = load double, double* %16
%18 = getelementptr inbounds double, double* %2, i64 %15
%19 = load double, double* %18
%20 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %17, double %19)
%21 = add nuw nsw i64 %15, 1
%22 = icmp eq i64 %21, %10
br i1 %22, label %23, label %14
23: ; preds = %14, %7
%24 = tail call i32 @fclose(i32* %5)
ret void
}