#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 *, ...);
int /*<<< orphan*/ free(double *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *);
double *malloc(int);
int /*<<< orphan*/ readArray(int /*<<< orphan*/ *, double *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stephens(double *, int);
int main(int argc, char *argv[]) {
  FILE *fp;
  double *x = NULL;
  int n;
  if (argc != 2) {
    fprintf(stderr, "Error: missing input file name\n");
    exit(-2);
  }
  fp = fopen(argv[1], "r");
  if (fp == NULL) {
    fprintf(stderr, "Error: Can not open input file: %s\n", argv[1]);
    exit(-1);
  }
  if (fscanf(fp, "#%d\n", &n)) {
    fprintf(stderr, "Can not read number of elements\n");
    exit(-1);
  }
  x = malloc(sizeof(double) * n);
  readArray(fp, x, n);
  fclose(fp);
  stephens(x, n);
  free(x);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x4(%rbp)
je     11d2 <main+0x42>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0xfffffffe,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe3f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    121e <main+0x8e>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe15(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xe1d(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1050 <fscanf@plt>
cmp    $0x0,%rax
je     125d <main+0xcd>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
movslq -0x24(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   10b0 <readArray@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1080 <stephens@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    1229 <main+0x99>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe70(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     124a <main+0xba>
mov    %rax,%r15
lea    0xe7e(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
test   %rax,%rax
jne    126f <main+0xdf>
mov    0xc(%rsp),%r14d
lea    0x0(,%r14,8),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
mov    %r14d,%edx
call   10b0 <readArray@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1080 <stephens@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    0xdc7(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xfffffffe,%edi
call   10a0 <exit@plt>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xdc4(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"Error: missing input file name\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [36 x i8] c"Error: Can not open input file: %s\0A\00"
@.str.3 = [5 x i8] c"#%d\0A\00"
@.str.4 = [33 x i8] c"Can not read number of elements\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca double*
%7 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store double* null, double** %6
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 -2)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %4
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %5
%19 = load i32*, i32** %5
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %28
21: ; preds = %14
%22 = load i32, i32* @stderr
%23 = load i8**, i8*** %4
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = call i32 @exit(i32 -1)
unreachable
28: ; preds = %14
%29 = load i32*, i32** %5
%30 = call i64 @fscanf(i32* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32* %7)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 @exit(i32 -1)
unreachable
36: ; preds = %28
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = mul i64 8, %38
%40 = trunc i64 %39 to i32
%41 = call double* @malloc(i32 %40)
store double* %41, double** %6
%42 = load i32*, i32** %5
%43 = load double*, double** %6
%44 = load i32, i32* %7
%45 = call i32 @readArray(i32* %42, double* %43, i32 %44)
%46 = load i32*, i32** %5
%47 = call i32 @fclose(i32* %46)
%48 = load double*, double** %6
%49 = load i32, i32* %7
%50 = call i32 @stephens(double* %48, i32 %49)
%51 = load double*, double** %6
%52 = call i32 @free(double* %51)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"Error: missing input file name\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [36 x i8] c"Error: Can not open input file: %s\0A\00"
@.str.3 = [5 x i8] c"#%d\0A\00"
@.str.4 = [33 x i8] c"Can not read number of elements\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 -2)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %11
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = tail call i32 @exit(i32 -1)
unreachable
20: ; preds = %10
%21 = call i64 @fscanf(i32* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%22 = icmp eq i64 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 @exit(i32 -1)
unreachable
27: ; preds = %20
%28 = load i32, i32* %3
%29 = shl i32 %28, 3
%30 = call double* @malloc(i32 %29)
%31 = call i32 @readArray(i32* %13, double* %30, i32 %28)
%32 = call i32 @fclose(i32* %13)
%33 = load i32, i32* %3
%34 = call i32 @stephens(double* %30, i32 %33)
%35 = call i32 @free(double* %30)
ret i32 0
}