#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double);
void maxima(int n, double *time, double *u_in, double *u_out) {
  FILE *file = fopen("time", "w+");
  for (int i = 0; i < n; i++) {
    fprintf(file, "%lf ", time[i]);
  }
  fclose(file);
  file = fopen("u_in", "w+");
  for (int i = 0; i < n; i++) {
    fprintf(file, "%lf ", u_in[i]);
  }
  fclose(file);
  file = fopen("u_out", "w+");
  for (int i = 0; i < n; i++) {
    fprintf(file, "%lf ", u_out[i]);
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<maxima>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    0xeb2(%rip),%rdi
lea    0xeb0(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    119c <maxima+0x6c>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe7f(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1165 <maxima+0x35>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe61(%rip),%rdi
lea    0xe52(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11fa <maxima+0xca>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe21(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11c3 <maxima+0x93>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe08(%rip),%rdi
lea    0xdf4(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1258 <maxima+0x128>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xdc3(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1221 <maxima+0xf1>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<maxima>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,0x10(%rsp)
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %edi,%r15d
lea    0xead(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbp
mov    %r15d,%r14d
mov    %r15d,0xc(%rsp)
test   %r15d,%r15d
jle    119a <maxima+0x6a>
xor    %r15d,%r15d
lea    0xe8f(%rip),%r13
nopl   0x0(%rax)
movsd  (%rbx,%r15,8),%xmm0
mov    %rbp,%rdi
mov    %r13,%rsi
call   1040 <fprintf@plt>
add    $0x1,%r15
cmp    %r15,%r14
jne    1180 <maxima+0x50>
mov    %rbp,%rdi
call   1030 <fclose@plt>
lea    0xe64(%rip),%rdi
lea    0xe55(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%r13d
test   %r13d,%r13d
jle    11ea <maxima+0xba>
xor    %ebp,%ebp
lea    0xe3d(%rip),%r15
nopl   0x0(%rax,%rax,1)
movsd  (%r12,%rbp,8),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r14
jne    11d0 <maxima+0xa0>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe19(%rip),%rdi
lea    0xe05(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r12
test   %r13d,%r13d
mov    0x10(%rsp),%rbx
jle    1239 <maxima+0x109>
xor    %ebp,%ebp
lea    0xded(%rip),%r15
nopl   0x0(%rax,%rax,1)
movsd  (%rbx,%rbp,8),%xmm0
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1220 <maxima+0xf0>
mov    %r12,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"time\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [5 x i8] c"%lf \00"
@.str.3 = [5 x i8] c"u_in\00"
@.str.4 = [6 x i8] c"u_out\00"
define void @maxima(i32 %0, double* %1, double* %2, double* %3) {
%5 = alloca i32
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %5
store double* %1, double** %6
store double* %2, double** %7
store double* %3, double** %8
%13 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %9
store i32 0, i32* %10
br label %14
14: ; preds = %26, %4
%15 = load i32, i32* %10
%16 = load i32, i32* %5
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %29
18: ; preds = %14
%19 = load i32*, i32** %9
%20 = load double*, double** %6
%21 = load i32, i32* %10
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
%24 = load double, double* %23
%25 = call i32 @fprintf(i32* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %24)
br label %26
26: ; preds = %18
%27 = load i32, i32* %10
%28 = add nsw i32 %27, 1
store i32 %28, i32* %10
br label %14
29: ; preds = %14
%30 = load i32*, i32** %9
%31 = call i32 @fclose(i32* %30)
%32 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %32, i32** %9
store i32 0, i32* %11
br label %33
33: ; preds = %45, %29
%34 = load i32, i32* %11
%35 = load i32, i32* %5
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %48
37: ; preds = %33
%38 = load i32*, i32** %9
%39 = load double*, double** %7
%40 = load i32, i32* %11
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %39, i64 %41
%43 = load double, double* %42
%44 = call i32 @fprintf(i32* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %43)
br label %45
45: ; preds = %37
%46 = load i32, i32* %11
%47 = add nsw i32 %46, 1
store i32 %47, i32* %11
br label %33
48: ; preds = %33
%49 = load i32*, i32** %9
%50 = call i32 @fclose(i32* %49)
%51 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %51, i32** %9
store i32 0, i32* %12
br label %52
52: ; preds = %64, %48
%53 = load i32, i32* %12
%54 = load i32, i32* %5
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %67
56: ; preds = %52
%57 = load i32*, i32** %9
%58 = load double*, double** %8
%59 = load i32, i32* %12
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %58, i64 %60
%62 = load double, double* %61
%63 = call i32 @fprintf(i32* %57, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %62)
br label %64
64: ; preds = %56
%65 = load i32, i32* %12
%66 = add nsw i32 %65, 1
store i32 %66, i32* %12
br label %52
67: ; preds = %52
%68 = load i32*, i32** %9
%69 = call i32 @fclose(i32* %68)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"time\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [5 x i8] c"%lf \00"
@.str.3 = [5 x i8] c"u_in\00"
@.str.4 = [6 x i8] c"u_out\00"
define void @maxima(i32 %0, double* nocapture %1, double* nocapture %2, double* nocapture %3) {
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = zext i32 %0 to i64
br label %14
9: ; preds = %14, %4
%10 = tail call i32 @fclose(i32* %5)
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br i1 %6, label %12, label %21
12: ; preds = %9
%13 = zext i32 %0 to i64
br label %26
14: ; preds = %7, %14
%15 = phi i64 [ 0, %7 ], [ %19, %14 ]
%16 = getelementptr inbounds double, double* %1, i64 %15
%17 = load double, double* %16
%18 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %17)
%19 = add nuw nsw i64 %15, 1
%20 = icmp eq i64 %19, %8
br i1 %20, label %9, label %14
21: ; preds = %26, %9
%22 = tail call i32 @fclose(i32* %11)
%23 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br i1 %6, label %24, label %33
24: ; preds = %21
%25 = zext i32 %0 to i64
br label %35
26: ; preds = %12, %26
%27 = phi i64 [ 0, %12 ], [ %31, %26 ]
%28 = getelementptr inbounds double, double* %2, i64 %27
%29 = load double, double* %28
%30 = tail call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %29)
%31 = add nuw nsw i64 %27, 1
%32 = icmp eq i64 %31, %13
br i1 %32, label %21, label %26
33: ; preds = %35, %21
%34 = tail call i32 @fclose(i32* %23)
ret void
35: ; preds = %24, %35
%36 = phi i64 [ 0, %24 ], [ %40, %35 ]
%37 = getelementptr inbounds double, double* %3, i64 %36
%38 = load double, double* %37
%39 = tail call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %38)
%40 = add nuw nsw i64 %36, 1
%41 = icmp eq i64 %40, %25
br i1 %41, label %33, label %35
}