#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 EOF;
int autocorr(double *, int, int);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(double *);
int fscanf(int /*<<< orphan*/ *, char *, double *);
int getopt(int, char **, char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  int i, n = 0, log_scale = 0;
  char *datfile;
  FILE *fp;
  double *dat;
  int c;
  extern char *optarg;
  extern int optind, optopt;
  if (argc < 2)
    usage((char *)argv[0]);
  while ((c = getopt(argc, (char **)argv, "l")) != -1) {
    switch (c) {
    case 'l':
      log_scale = 1;
      break;
    case '?':
      usage((char *)argv[0]);
    }
  }
  datfile = argv[optind];
  if (!datfile) {
    fprintf(stderr, "error: invalid datafile\n");
    usage((char *)argv[0]);
  } else
    fp = fopen(datfile, "r");
  if (!fp) {
    fprintf(stderr, "error: could not open datafile %s\n", datfile);
    usage((char *)argv[0]);
  }
  dat = (double *)calloc(4000000, sizeof(double));
  if (!dat) {
    fprintf(stderr, "couldn't allocate working memory buffer\n");
    exit(1);
  }
  for (i = 0; n != EOF; i++) {
    n = fscanf(fp, "%lg", (dat + i));
  }
  fclose(fp);
  printf("# correlation time = %d\n", autocorr(dat, (i - 1), log_scale));
  free(dat);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11ea <main+0x3a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <usage@plt>
jmp    11ef <main+0x3f>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe03(%rip),%rdx
call   10c0 <getopt@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
je     1250 <main+0xa0>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x40(%rbp)
sub    $0x3f,%eax
je     123f <main+0x8f>
jmp    1222 <main+0x72>
mov    -0x40(%rbp),%eax
sub    $0x6c,%eax
jne    124b <main+0x9b>
jmp    1233 <main+0x83>
movl   $0x1,-0x1c(%rbp)
jmp    124b <main+0x9b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <usage@plt>
jmp    11ef <main+0x3f>
mov    -0x10(%rbp),%rax
mov    0x2d75(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1299 <main+0xe9>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
lea    0xd81(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <usage@plt>
jmp    12ad <main+0xfd>
mov    -0x28(%rbp),%rdi
lea    0xd77(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12df <main+0x12f>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xd51(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <usage@plt>
mov    $0x3d0900,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    131e <main+0x16e>
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
lea    0xd33(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2cb9(%rip),%rcx
cmp    (%rcx),%eax
je     1367 <main+0x1b7>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rdx
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
lea    0xd18(%rip),%rsi
call   1070 <fscanf@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1325 <main+0x175>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
mov    -0x1c(%rbp),%edx
call   1040 <autocorr@plt>
mov    %eax,%esi
lea    0xce2(%rip),%rdi
call   1060 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
cmp    $0x1,%edi
jg     11cd <main+0x1d>
mov    (%rbx),%rdi
call   10a0 <usage@plt>
xor    %r14d,%r14d
lea    0xe29(%rip),%r15
jmp    11e0 <main+0x30>
mov    $0x1,%r14d
nop
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   10c0 <getopt@plt>
cmp    $0x3f,%eax
je     1200 <main+0x50>
cmp    $0x6c,%eax
je     11d9 <main+0x29>
cmp    $0xffffffff,%eax
jne    11e0 <main+0x30>
jmp    120a <main+0x5a>
xchg   %ax,%ax
mov    (%rbx),%rdi
call   10a0 <usage@plt>
jmp    11e0 <main+0x30>
mov    0x2dbf(%rip),%rax
movslq (%rax),%rax
mov    (%rbx,%rax,8),%r15
test   %r15,%r15
jne    123e <main+0x8e>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
lea    0xdd5(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%rbx),%rdi
call   10a0 <usage@plt>
jmp    1255 <main+0xa5>
lea    0xdd6(%rip),%rsi
mov    %r15,%rdi
call   10b0 <fopen@plt>
mov    %rax,%r13
test   %rax,%rax
jne    127a <main+0xca>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
lea    0xdb8(%rip),%rsi
xor    %r13d,%r13d
mov    %r15,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%rbx),%rdi
call   10a0 <usage@plt>
mov    $0x3d0900,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
test   %rax,%rax
jne    12af <main+0xff>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
lea    0xda2(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    %rax,(%rsp)
mov    0x2d2e(%rip),%r15
mov    $0xffffffff,%ebx
cmpl   $0x0,(%r15)
je     12fa <main+0x14a>
mov    $0xffffffff,%ebx
lea    0xd98(%rip),%r12
mov    (%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1070 <fscanf@plt>
add    $0x8,%rbp
add    $0x1,%ebx
cmp    (%r15),%eax
jne    12e0 <main+0x130>
mov    %r13,%rdi
call   1050 <fclose@plt>
mov    (%rsp),%rbp
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
call   1040 <autocorr@plt>
lea    0xd53(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"l\00"
@optind = external global i32
@stderr = global i32 0
@.str.1 = [25 x i8] c"error: invalid datafile\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [35 x i8] c"error: could not open datafile %s\0A\00"
@.str.4 = [41 x i8] c"couldn't allocate working memory buffer\0A\00"
@EOF = global i32 0
@.str.5 = [4 x i8] c"%lg\00"
@.str.6 = [25 x i8] c"# correlation time = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca double*
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @usage(i8* %18)
br label %20
20: ; preds = %15, %2
br label %21
21: ; preds = %34, %20
%22 = load i32, i32* %4
%23 = load i8**, i8*** %5
%24 = call i32 @getopt(i32 %22, i8** %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %24, i32* %12
%25 = icmp ne i32 %24, -1
br i1 %25, label %26, label %35
26: ; preds = %21
%27 = load i32, i32* %12
switch i32 %27, label %34 [
i32 108, label %28
i32 63, label %29
]
28: ; preds = %26
store i32 1, i32* %8
br label %34
29: ; preds = %26
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = call i32 @usage(i8* %32)
br label %34
34: ; preds = %29, %26, %28
br label %21
35: ; preds = %21
%36 = load i8**, i8*** %5
%37 = load i32, i32* @optind
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
%40 = load i8*, i8** %39
store i8* %40, i8** %9
%41 = load i8*, i8** %9
%42 = icmp ne i8* %41, null
br i1 %42, label %50, label %43
43: ; preds = %35
%44 = load i32, i32* @stderr
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 0
%48 = load i8*, i8** %47
%49 = call i32 @usage(i8* %48)
br label %53
50: ; preds = %35
%51 = load i8*, i8** %9
%52 = call i32* @fopen(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %52, i32** %10
br label %53
53: ; preds = %50, %43
%54 = load i32*, i32** %10
%55 = icmp ne i32* %54, null
br i1 %55, label %64, label %56
56: ; preds = %53
%57 = load i32, i32* @stderr
%58 = load i8*, i8** %9
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %58)
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 0
%62 = load i8*, i8** %61
%63 = call i32 @usage(i8* %62)
br label %64
64: ; preds = %56, %53
%65 = call i64 @calloc(i32 4000000, i32 8)
%66 = inttoptr i64 %65 to double*
store double* %66, double** %11
%67 = load double*, double** %11
%68 = icmp ne double* %67, null
br i1 %68, label %73, label %69
69: ; preds = %64
%70 = load i32, i32* @stderr
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %64
store i32 0, i32* %6
br label %74
74: ; preds = %85, %73
%75 = load i32, i32* %7
%76 = load i32, i32* @EOF
%77 = icmp ne i32 %75, %76
br i1 %77, label %78, label %88
78: ; preds = %74
%79 = load i32*, i32** %10
%80 = load double*, double** %11
%81 = load i32, i32* %6
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds double, double* %80, i64 %82
%84 = call i32 @fscanf(i32* %79, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), double* %83)
store i32 %84, i32* %7
br label %85
85: ; preds = %78
%86 = load i32, i32* %6
%87 = add nsw i32 %86, 1
store i32 %87, i32* %6
br label %74
88: ; preds = %74
%89 = load i32*, i32** %10
%90 = call i32 @fclose(i32* %89)
%91 = load double*, double** %11
%92 = load i32, i32* %6
%93 = sub nsw i32 %92, 1
%94 = load i32, i32* %8
%95 = call i32 @autocorr(double* %91, i32 %93, i32 %94)
%96 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %95)
%97 = load double*, double** %11
%98 = call i32 @free(double* %97)
%99 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [2 x i8] c"l\00"
@optind = external global i32
@stderr = global i32 0
@.str.1 = [25 x i8] c"error: invalid datafile\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [35 x i8] c"error: could not open datafile %s\0A\00"
@.str.4 = [41 x i8] c"couldn't allocate working memory buffer\0A\00"
@EOF = global i32 0
@.str.5 = [4 x i8] c"%lg\00"
@.str.6 = [25 x i8] c"# correlation time = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @usage(i8* %5)
br label %7
7: ; preds = %4, %2
br label %8
8: ; preds = %10, %7
%9 = phi i32 [ 0, %7 ], [ 1, %10 ]
br label %10
10: ; preds = %12, %8
%11 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
switch i32 %11, label %12 [
i32 -1, label %16
i32 108, label %8
i32 63, label %13
]
12: ; preds = %10, %13
br label %10
13: ; preds = %10
%14 = load i8*, i8** %1
%15 = tail call i32 @usage(i8* %14)
br label %12
16: ; preds = %10
%17 = load i32, i32* @optind
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i8*, i8** %19
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %27
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%25 = load i8*, i8** %1
%26 = tail call i32 @usage(i8* %25)
br label %30
27: ; preds = %16
%28 = tail call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %35
30: ; preds = %22, %27
%31 = load i32, i32* @stderr
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%33 = load i8*, i8** %1
%34 = tail call i32 @usage(i8* %33)
br label %35
35: ; preds = %30, %27
%36 = phi i32* [ null, %30 ], [ %28, %27 ]
%37 = tail call i64 @calloc(i32 4000000, i32 8)
%38 = inttoptr i64 %37 to double*
%39 = icmp eq i64 %37, 0
br i1 %39, label %43, label %40
40: ; preds = %35
%41 = load i32, i32* @EOF
%42 = icmp eq i32 %41, 0
br i1 %42, label %57, label %47
43: ; preds = %35
%44 = load i32, i32* @stderr
%45 = tail call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
%46 = tail call i32 @exit(i32 1)
unreachable
47: ; preds = %40, %47
%48 = phi i64 [ %51, %47 ], [ 0, %40 ]
%49 = getelementptr inbounds double, double* %38, i64 %48
%50 = tail call i32 @fscanf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), double* %49)
%51 = add nuw i64 %48, 1
%52 = load i32, i32* @EOF
%53 = icmp eq i32 %50, %52
br i1 %53, label %54, label %47
54: ; preds = %47
%55 = trunc i64 %51 to i32
%56 = add i32 %55, -1
br label %57
57: ; preds = %54, %40
%58 = phi i32 [ -1, %40 ], [ %56, %54 ]
%59 = tail call i32 @fclose(i32* %36)
%60 = tail call i32 @autocorr(double* %38, i32 %58, i32 %9)
%61 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %60)
%62 = tail call i32 @free(double* %38)
%63 = tail call i32 @exit(i32 0)
unreachable
}