#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 EXIT_SUCCESS;
int /*<<< orphan*/ assert(int /*<<< orphan*/ *);
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
size_t fread(double *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ fwrite(double *, int, int, int /*<<< orphan*/ *);
int getopt(int, char **, char *);
double *malloc(int);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int i;
  int dim = 0;
  int opt;
  int showhelp = 0;
  while ((opt = getopt(argc, argv, "d:h")) != -1) {
    switch (opt) {
    case 'd':
      dim = atoi(optarg);
      break;
    case 'h':
      showhelp = 1;
      break;
    default:
      showhelp = 1;
      break;
    }
  }
  if (showhelp || dim <= 0 || argc - optind < 2) {
    fprintf(stderr, "Usage: %s -d [dims] input output\n", argv[0]);
    return EXIT_SUCCESS;
  }
  FILE *in = fopen(argv[optind], "r");
  assert(in);
  unsigned int c = 0;
  double *sum = malloc(dim * sizeof(double));
  for (i = 0; i < dim; i++) {
    sum[i] = 0.0;
  }
  double *buffer = malloc(dim * sizeof(double));
  size_t r;
  while ((r = fread(buffer, sizeof(double), dim, in)) == dim) {
    for (i = 0; i < dim; i++) {
      sum[i] += buffer[i];
    }
    c++;
  }
  fclose(in);
  for (i = 0; i < dim; i++) {
    sum[i] /= (double)c;
  }
  FILE *out = fopen(argv[optind + 1], "w");
  assert(out);
  fwrite(sum, sizeof(double), dim, out);
  fclose(out);
  free(buffer);
  free(sum);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe2e(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     1236 <main+0x96>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x54(%rbp)
sub    $0x64,%eax
je     1208 <main+0x68>
jmp    11f7 <main+0x57>
mov    -0x54(%rbp),%eax
sub    $0x68,%eax
je     121e <main+0x7e>
jmp    122a <main+0x8a>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
call   10b0 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    1231 <main+0x91>
movl   $0x1,-0x20(%rbp)
jmp    1231 <main+0x91>
movl   $0x1,-0x20(%rbp)
jmp    11c4 <main+0x24>
cmpl   $0x0,-0x20(%rbp)
jne    125f <main+0xbf>
cmpl   $0x0,-0x18(%rbp)
jle    125f <main+0xbf>
mov    -0x8(%rbp),%eax
mov    0x2d8c(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x2,%eax
jge    128c <main+0xec>
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd8e(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    143d <main+0x29d>
mov    -0x10(%rbp),%rax
mov    0x2d49(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd81(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <assert@plt>
movl   $0x0,-0x2c(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1302 <main+0x162>
mov    -0x38(%rbp),%rax
movslq -0x14(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12d8 <main+0x138>
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x8,%esi
call   1040 <fread@plt>
mov    %rax,-0x48(%rbp)
movslq -0x18(%rbp),%rcx
cmp    %rcx,%rax
jne    1389 <main+0x1e9>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    137b <main+0x1db>
mov    -0x40(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rax
movslq -0x14(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1342 <main+0x1a2>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1315 <main+0x175>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    13d1 <main+0x231>
mov    -0x2c(%rbp),%eax
cvtsi2sd %rax,%xmm1
mov    -0x38(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1399 <main+0x1f9>
mov    -0x10(%rbp),%rax
mov    0x2c04(%rip),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xc39(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
call   1060 <assert@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x50(%rbp),%rcx
mov    $0x8,%esi
call   10c0 <fwrite@plt>
mov    -0x50(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    0x2b90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
xor    %r13d,%r13d
lea    0xe33(%rip),%r12
mov    0x2e24(%rip),%rbp
xor    %r15d,%r15d
jmp    11eb <main+0x3b>
nopl   0x0(%rax)
mov    0x0(%rbp),%edi
call   10c0 <atoi@plt>
mov    %eax,%r15d
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r12,%rdx
call   10b0 <getopt@plt>
cmp    $0x64,%eax
je     11e0 <main+0x30>
cmp    $0xffffffff,%eax
je     1207 <main+0x57>
mov    $0x1,%r13b
jmp    11eb <main+0x3b>
test   %r15d,%r15d
setle  %al
or     %al,%r13b
test   $0x1,%r13b
jne    1227 <main+0x77>
mov    0x2dc3(%rip),%rax
movslq (%rax),%rax
sub    %eax,%ebx
cmp    $0x1,%ebx
jg     1244 <main+0x94>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xdca(%rip),%rsi
call   1080 <fprintf@plt>
jmp    1541 <main+0x391>
mov    (%r14,%rax,8),%rdi
lea    0xdd7(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,0x8(%rsp)
mov    %rax,%rdi
call   1070 <assert@plt>
mov    %r15d,%ebp
lea    0x0(,%r15,8),%r12d
mov    %r12d,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
lea    0x0(,%rbp,8),%rdx
xor    %r13d,%r13d
mov    %rax,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    %r12d,%edi
call   1090 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    $0x8,%esi
mov    %r15d,%edx
mov    0x8(%rsp),%rcx
call   1040 <fread@plt>
xorpd  %xmm0,%xmm0
cmp    %rbp,%rax
jne    1424 <main+0x274>
mov    %ebp,%eax
and    $0xfffffffc,%eax
mov    %rax,0x10(%rsp)
add    $0xfffffffffffffffc,%rax
mov    %rax,0x30(%rsp)
mov    %rax,%rcx
shr    $0x2,%rcx
add    $0x1,%rcx
mov    %rcx,%rax
mov    %rcx,0x28(%rsp)
and    $0xfffffffffffffffe,%rcx
mov    %rcx,0x20(%rsp)
jmp    1312 <main+0x162>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r13d
mov    %r12,%rdi
mov    $0x8,%esi
mov    %r15d,%edx
mov    0x8(%rsp),%rcx
call   1040 <fread@plt>
cmp    %rbp,%rax
jne    1419 <main+0x269>
cmp    $0x4,%r15d
jae    1320 <main+0x170>
xor    %eax,%eax
jmp    13f0 <main+0x240>
nop
cmpq   $0x0,0x30(%rsp)
je     140e <main+0x25e>
mov    0x20(%rsp),%rcx
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movupd (%r12,%rax,8),%xmm0
movupd 0x10(%r12,%rax,8),%xmm1
movupd (%rbx,%rax,8),%xmm2
addpd  %xmm0,%xmm2
movupd 0x10(%rbx,%rax,8),%xmm0
addpd  %xmm1,%xmm0
movupd 0x20(%rbx,%rax,8),%xmm1
movupd 0x30(%rbx,%rax,8),%xmm3
movupd %xmm2,(%rbx,%rax,8)
movupd %xmm0,0x10(%rbx,%rax,8)
movupd 0x20(%r12,%rax,8),%xmm0
addpd  %xmm1,%xmm0
movupd 0x30(%r12,%rax,8),%xmm1
addpd  %xmm3,%xmm1
movupd %xmm0,0x20(%rbx,%rax,8)
movupd %xmm1,0x30(%rbx,%rax,8)
add    $0x8,%rax
add    $0xfffffffffffffffe,%rcx
jne    1340 <main+0x190>
testb  $0x1,0x28(%rsp)
je     13d5 <main+0x225>
movupd (%r12,%rax,8),%xmm0
movupd 0x10(%r12,%rax,8),%xmm1
movupd (%rbx,%rax,8),%xmm2
addpd  %xmm0,%xmm2
movupd 0x10(%rbx,%rax,8),%xmm0
addpd  %xmm1,%xmm0
movupd %xmm2,(%rbx,%rax,8)
movupd %xmm0,0x10(%rbx,%rax,8)
mov    0x10(%rsp),%rcx
mov    %rcx,%rax
cmp    %rbp,%rcx
je     12f0 <main+0x140>
cs nopw 0x0(%rax,%rax,1)
movsd  (%r12,%rax,8),%xmm0
addsd  (%rbx,%rax,8),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
add    $0x1,%rax
cmp    %rax,%rbp
jne    13f0 <main+0x240>
jmp    12f0 <main+0x140>
xor    %eax,%eax
testb  $0x1,0x28(%rsp)
jne    13aa <main+0x1fa>
jmp    13d5 <main+0x225>
mov    %r13d,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movapd %xmm0,0x10(%rsp)
mov    0x8(%rsp),%rdi
call   1050 <fclose@plt>
cmp    $0x2,%r15d
jae    144e <main+0x29e>
xor    %eax,%eax
mov    0x2b9d(%rip),%rcx
movapd 0x10(%rsp),%xmm3
jmp    14e0 <main+0x330>
mov    %ebp,%eax
and    $0xfffffffe,%eax
movapd 0x10(%rsp),%xmm3
movapd %xmm3,%xmm0
unpcklpd %xmm3,%xmm0
lea    -0x2(%rax),%rdx
mov    %rdx,%rcx
shr    %rcx
add    $0x1,%rcx
test   %rdx,%rdx
je     1559 <main+0x3a9>
mov    %rcx,%rsi
and    $0xfffffffffffffffe,%rsi
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movupd (%rbx,%rdx,8),%xmm1
movupd 0x10(%rbx,%rdx,8),%xmm2
divpd  %xmm0,%xmm1
movupd %xmm1,(%rbx,%rdx,8)
divpd  %xmm0,%xmm2
movupd %xmm2,0x10(%rbx,%rdx,8)
add    $0x4,%rdx
add    $0xfffffffffffffffe,%rsi
jne    1490 <main+0x2e0>
test   $0x1,%cl
je     14cb <main+0x31b>
movupd (%rbx,%rdx,8),%xmm1
divpd  %xmm0,%xmm1
movupd %xmm1,(%rbx,%rdx,8)
cmp    %rbp,%rax
mov    0x2b0b(%rip),%rcx
je     14f7 <main+0x347>
nopw   0x0(%rax,%rax,1)
movsd  (%rbx,%rax,8),%xmm0
divsd  %xmm3,%xmm0
movsd  %xmm0,(%rbx,%rax,8)
add    $0x1,%rax
cmp    %rax,%rbp
jne    14e0 <main+0x330>
movslq (%rcx),%rax
mov    0x8(%r14,%rax,8),%rdi
lea    0xb22(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1070 <assert@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
mov    %r15d,%edx
mov    %rbp,%rcx
call   10d0 <fwrite@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2a80(%rip),%rax
mov    (%rax),%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edx,%edx
test   $0x1,%cl
jne    14bd <main+0x30d>
jmp    14cb <main+0x31b>

LLVM IR (-O0):
@.str = [4 x i8] c"d:h\00"
@optarg = global i32 0
@optind = global i32 0
@stderr = global i32 0
@.str.1 = [34 x i8] c"Usage: %s -d [dims] input output\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c"w\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 i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca double*
%13 = alloca double*
%14 = alloca i64
%15 = 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* %9
br label %16
16: ; preds = %28, %2
%17 = load i32, i32* %4
%18 = load i8**, i8*** %5
%19 = call i32 @getopt(i32 %17, i8** %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %19, i32* %8
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %29
21: ; preds = %16
%22 = load i32, i32* %8
switch i32 %22, label %27 [
i32 100, label %23
i32 104, label %26
]
23: ; preds = %21
%24 = load i32, i32* @optarg
%25 = call i32 @atoi(i32 %24)
store i32 %25, i32* %7
br label %28
26: ; preds = %21
store i32 1, i32* %9
br label %28
27: ; preds = %21
store i32 1, i32* %9
br label %28
28: ; preds = %27, %26, %23
br label %16
29: ; preds = %16
%30 = load i32, i32* %9
%31 = icmp ne i32 %30, 0
br i1 %31, label %40, label %32
32: ; preds = %29
%33 = load i32, i32* %7
%34 = icmp sle i32 %33, 0
br i1 %34, label %40, label %35
35: ; preds = %32
%36 = load i32, i32* %4
%37 = load i32, i32* @optind
%38 = sub nsw i32 %36, %37
%39 = icmp slt i32 %38, 2
br i1 %39, label %40, label %47
40: ; preds = %35, %32, %29
%41 = load i32, i32* @stderr
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %44)
%46 = load i32, i32* @EXIT_SUCCESS
store i32 %46, i32* %3
br label %150
47: ; preds = %35
%48 = load i8**, i8*** %5
%49 = load i32, i32* @optind
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
%52 = load i8*, i8** %51
%53 = call i32* @fopen(i8* %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %53, i32** %10
%54 = load i32*, i32** %10
%55 = call i32 @assert(i32* %54)
store i32 0, i32* %11
%56 = load i32, i32* %7
%57 = sext i32 %56 to i64
%58 = mul i64 %57, 8
%59 = trunc i64 %58 to i32
%60 = call double* @malloc(i32 %59)
store double* %60, double** %12
store i32 0, i32* %6
br label %61
61: ; preds = %70, %47
%62 = load i32, i32* %6
%63 = load i32, i32* %7
%64 = icmp slt i32 %62, %63
br i1 %64, label %65, label %73
65: ; preds = %61
%66 = load double*, double** %12
%67 = load i32, i32* %6
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds double, double* %66, i64 %68
store double 0.000000e+00, double* %69
br label %70
70: ; preds = %65
%71 = load i32, i32* %6
%72 = add nsw i32 %71, 1
store i32 %72, i32* %6
br label %61
73: ; preds = %61
%74 = load i32, i32* %7
%75 = sext i32 %74 to i64
%76 = mul i64 %75, 8
%77 = trunc i64 %76 to i32
%78 = call double* @malloc(i32 %77)
store double* %78, double** %13
br label %79
79: ; preds = %107, %73
%80 = load double*, double** %13
%81 = load i32, i32* %7
%82 = load i32*, i32** %10
%83 = call i64 @fread(double* %80, i32 8, i32 %81, i32* %82)
store i64 %83, i64* %14
%84 = load i32, i32* %7
%85 = sext i32 %84 to i64
%86 = icmp eq i64 %83, %85
br i1 %86, label %87, label %110
87: ; preds = %79
store i32 0, i32* %6
br label %88
88: ; preds = %104, %87
%89 = load i32, i32* %6
%90 = load i32, i32* %7
%91 = icmp slt i32 %89, %90
br i1 %91, label %92, label %107
92: ; preds = %88
%93 = load double*, double** %13
%94 = load i32, i32* %6
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds double, double* %93, i64 %95
%97 = load double, double* %96
%98 = load double*, double** %12
%99 = load i32, i32* %6
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds double, double* %98, i64 %100
%102 = load double, double* %101
%103 = fadd double %102, %97
store double %103, double* %101
br label %104
104: ; preds = %92
%105 = load i32, i32* %6
%106 = add nsw i32 %105, 1
store i32 %106, i32* %6
br label %88
107: ; preds = %88
%108 = load i32, i32* %11
%109 = add i32 %108, 1
store i32 %109, i32* %11
br label %79
110: ; preds = %79
%111 = load i32*, i32** %10
%112 = call i32 @fclose(i32* %111)
store i32 0, i32* %6
br label %113
113: ; preds = %126, %110
%114 = load i32, i32* %6
%115 = load i32, i32* %7
%116 = icmp slt i32 %114, %115
br i1 %116, label %117, label %129
117: ; preds = %113
%118 = load i32, i32* %11
%119 = uitofp i32 %118 to double
%120 = load double*, double** %12
%121 = load i32, i32* %6
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds double, double* %120, i64 %122
%124 = load double, double* %123
%125 = fdiv double %124, %119
store double %125, double* %123
br label %126
126: ; preds = %117
%127 = load i32, i32* %6
%128 = add nsw i32 %127, 1
store i32 %128, i32* %6
br label %113
129: ; preds = %113
%130 = load i8**, i8*** %5
%131 = load i32, i32* @optind
%132 = add nsw i32 %131, 1
%133 = sext i32 %132 to i64
%134 = getelementptr inbounds i8*, i8** %130, i64 %133
%135 = load i8*, i8** %134
%136 = call i32* @fopen(i8* %135, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %136, i32** %15
%137 = load i32*, i32** %15
%138 = call i32 @assert(i32* %137)
%139 = load double*, double** %12
%140 = load i32, i32* %7
%141 = load i32*, i32** %15
%142 = call i32 @fwrite(double* %139, i32 8, i32 %140, i32* %141)
%143 = load i32*, i32** %15
%144 = call i32 @fclose(i32* %143)
%145 = load double*, double** %13
%146 = call i32 @free(double* %145)
%147 = load double*, double** %12
%148 = call i32 @free(double* %147)
%149 = load i32, i32* @EXIT_SUCCESS
store i32 %149, i32* %3
br label %150
150: ; preds = %129, %40
%151 = load i32, i32* %3
ret i32 %151
}

LLVM IR (-O2):
@.str = [4 x i8] c"d:h\00"
@optarg = global i32 0
@optind = global i32 0
@stderr = global i32 0
@.str.1 = [34 x i8] c"Usage: %s -d [dims] input output\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %6, %2
%4 = phi i1 [ false, %2 ], [ true, %6 ]
%5 = phi i32 [ 0, %2 ], [ %7, %6 ]
br label %6
6: ; preds = %3, %9
%7 = phi i32 [ %11, %9 ], [ %5, %3 ]
%8 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %8, label %3 [
i32 -1, label %12
i32 100, label %9
]
9: ; preds = %6
%10 = load i32, i32* @optarg
%11 = tail call i32 @atoi(i32 %10)
br label %6
12: ; preds = %6
%13 = icmp slt i32 %7, 1
%14 = select i1 %4, i1 true, i1 %13
br i1 %14, label %19, label %15
15: ; preds = %12
%16 = load i32, i32* @optind
%17 = sub nsw i32 %0, %16
%18 = icmp slt i32 %17, 2
br i1 %18, label %19, label %23
19: ; preds = %15, %12
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %1
%22 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %192
23: ; preds = %15
%24 = sext i32 %16 to i64
%25 = getelementptr inbounds i8*, i8** %1, i64 %24
%26 = load i8*, i8** %25
%27 = tail call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%28 = tail call i32 @assert(i32* %27)
%29 = zext i32 %7 to i64
%30 = shl i32 %7, 3
%31 = tail call double* @malloc(i32 %30)
%32 = bitcast double* %31 to i8*
%33 = shl nuw nsw i64 %29, 3
%34 = tail call double* @malloc(i32 %30)
%35 = tail call i64 @fread(double* %34, i32 8, i32 %7, i32* %27)
%36 = icmp eq i64 %35, %29
br i1 %36, label %37, label %128
37: ; preds = %23
%38 = and i64 %29, 4294967292
%39 = add nsw i64 %38, -4
%40 = lshr exact i64 %39, 2
%41 = add nuw nsw i64 %40, 1
%42 = icmp ult i32 %7, 4
%43 = and i64 %29, 4294967292
%44 = and i64 %41, 1
%45 = icmp eq i64 %39, 0
%46 = and i64 %41, 9223372036854775806
%47 = icmp eq i64 %44, 0
%48 = icmp eq i64 %43, %29
br label %49
49: ; preds = %37, %122
%50 = phi i32 [ %123, %122 ], [ 0, %37 ]
br i1 %42, label %111, label %51
51: ; preds = %49
br i1 %45, label %91, label %52
52: ; preds = %51, %52
%53 = phi i64 [ %88, %52 ], [ 0, %51 ]
%54 = phi i64 [ %89, %52 ], [ 0, %51 ]
%55 = getelementptr inbounds double, double* %34, i64 %53
%56 = bitcast double* %55 to <2 x double>*
%57 = load <2 x double>, <2 x double>* %56
%58 = getelementptr inbounds double, double* %55, i64 2
%59 = bitcast double* %58 to <2 x double>*
%60 = load <2 x double>, <2 x double>* %59
%61 = getelementptr inbounds double, double* %31, i64 %53
%62 = bitcast double* %61 to <2 x double>*
%63 = load <2 x double>, <2 x double>* %62
%64 = getelementptr inbounds double, double* %61, i64 2
%65 = bitcast double* %64 to <2 x double>*
%66 = load <2 x double>, <2 x double>* %65
%67 = fadd <2 x double> %57, %63
%68 = fadd <2 x double> %60, %66
%69 = bitcast double* %61 to <2 x double>*
store <2 x double> %67, <2 x double>* %69
%70 = bitcast double* %64 to <2 x double>*
store <2 x double> %68, <2 x double>* %70
%71 = or i64 %53, 4
%72 = getelementptr inbounds double, double* %34, i64 %71
%73 = bitcast double* %72 to <2 x double>*
%74 = load <2 x double>, <2 x double>* %73
%75 = getelementptr inbounds double, double* %72, i64 2
%76 = bitcast double* %75 to <2 x double>*
%77 = load <2 x double>, <2 x double>* %76
%78 = getelementptr inbounds double, double* %31, i64 %71
%79 = bitcast double* %78 to <2 x double>*
%80 = load <2 x double>, <2 x double>* %79
%81 = getelementptr inbounds double, double* %78, i64 2
%82 = bitcast double* %81 to <2 x double>*
%83 = load <2 x double>, <2 x double>* %82
%84 = fadd <2 x double> %74, %80
%85 = fadd <2 x double> %77, %83
%86 = bitcast double* %78 to <2 x double>*
store <2 x double> %84, <2 x double>* %86
%87 = bitcast double* %81 to <2 x double>*
store <2 x double> %85, <2 x double>* %87
%88 = add nuw i64 %53, 8
%89 = add i64 %54, 2
%90 = icmp eq i64 %89, %46
br i1 %90, label %91, label %52
91: ; preds = %52, %51
%92 = phi i64 [ 0, %51 ], [ %88, %52 ]
br i1 %47, label %110, label %93
93: ; preds = %91
%94 = getelementptr inbounds double, double* %34, i64 %92
%95 = bitcast double* %94 to <2 x double>*
%96 = load <2 x double>, <2 x double>* %95
%97 = getelementptr inbounds double, double* %94, i64 2
%98 = bitcast double* %97 to <2 x double>*
%99 = load <2 x double>, <2 x double>* %98
%100 = getelementptr inbounds double, double* %31, i64 %92
%101 = bitcast double* %100 to <2 x double>*
%102 = load <2 x double>, <2 x double>* %101
%103 = getelementptr inbounds double, double* %100, i64 2
%104 = bitcast double* %103 to <2 x double>*
%105 = load <2 x double>, <2 x double>* %104
%106 = fadd <2 x double> %96, %102
%107 = fadd <2 x double> %99, %105
%108 = bitcast double* %100 to <2 x double>*
store <2 x double> %106, <2 x double>* %108
%109 = bitcast double* %103 to <2 x double>*
store <2 x double> %107, <2 x double>* %109
br label %110
110: ; preds = %91, %93
br i1 %48, label %122, label %111
111: ; preds = %49, %110
%112 = phi i64 [ 0, %49 ], [ %43, %110 ]
br label %113
113: ; preds = %111, %113
%114 = phi i64 [ %120, %113 ], [ %112, %111 ]
%115 = getelementptr inbounds double, double* %34, i64 %114
%116 = load double, double* %115
%117 = getelementptr inbounds double, double* %31, i64 %114
%118 = load double, double* %117
%119 = fadd double %116, %118
store double %119, double* %117
%120 = add nuw nsw i64 %114, 1
%121 = icmp eq i64 %120, %29
br i1 %121, label %122, label %113
122: ; preds = %113, %110
%123 = add i32 %50, 1
%124 = tail call i64 @fread(double* %34, i32 8, i32 %7, i32* %27)
%125 = icmp eq i64 %124, %29
br i1 %125, label %49, label %126
126: ; preds = %122
%127 = uitofp i32 %123 to double
br label %128
128: ; preds = %23, %126
%129 = phi double [ 0.000000e+00, %23 ], [ %127, %126 ]
%130 = tail call i32 @fclose(i32* %27)
%131 = icmp ult i32 %7, 2
br i1 %131, label %171, label %132
132: ; preds = %128
%133 = and i64 %29, 4294967294
%134 = insertelement <2 x double> poison, double %129, i64 0
%135 = shufflevector <2 x double> %134, <2 x double> poison, <2 x i32> zeroinitializer
%136 = add nsw i64 %133, -2
%137 = lshr exact i64 %136, 1
%138 = add nuw i64 %137, 1
%139 = and i64 %138, 1
%140 = icmp eq i64 %136, 0
br i1 %140, label %160, label %141
141: ; preds = %132
%142 = and i64 %138, -2
br label %143
143: ; preds = %143, %141
%144 = phi i64 [ 0, %141 ], [ %157, %143 ]
%145 = phi i64 [ 0, %141 ], [ %158, %143 ]
%146 = getelementptr inbounds double, double* %31, i64 %144
%147 = bitcast double* %146 to <2 x double>*
%148 = load <2 x double>, <2 x double>* %147
%149 = fdiv <2 x double> %148, %135
%150 = bitcast double* %146 to <2 x double>*
store <2 x double> %149, <2 x double>* %150
%151 = or i64 %144, 2
%152 = getelementptr inbounds double, double* %31, i64 %151
%153 = bitcast double* %152 to <2 x double>*
%154 = load <2 x double>, <2 x double>* %153
%155 = fdiv <2 x double> %154, %135
%156 = bitcast double* %152 to <2 x double>*
store <2 x double> %155, <2 x double>* %156
%157 = add nuw i64 %144, 4
%158 = add nuw i64 %145, 2
%159 = icmp eq i64 %158, %142
br i1 %159, label %160, label %143
160: ; preds = %143, %132
%161 = phi i64 [ 0, %132 ], [ %157, %143 ]
%162 = icmp eq i64 %139, 0
br i1 %162, label %169, label %163
163: ; preds = %160
%164 = getelementptr inbounds double, double* %31, i64 %161
%165 = bitcast double* %164 to <2 x double>*
%166 = load <2 x double>, <2 x double>* %165
%167 = fdiv <2 x double> %166, %135
%168 = bitcast double* %164 to <2 x double>*
store <2 x double> %167, <2 x double>* %168
br label %169
169: ; preds = %160, %163
%170 = icmp eq i64 %133, %29
br i1 %170, label %180, label %171
171: ; preds = %128, %169
%172 = phi i64 [ 0, %128 ], [ %133, %169 ]
br label %173
173: ; preds = %171, %173
%174 = phi i64 [ %178, %173 ], [ %172, %171 ]
%175 = getelementptr inbounds double, double* %31, i64 %174
%176 = load double, double* %175
%177 = fdiv double %176, %129
store double %177, double* %175
%178 = add nuw nsw i64 %174, 1
%179 = icmp eq i64 %178, %29
br i1 %179, label %180, label %173
180: ; preds = %173, %169
%181 = load i32, i32* @optind
%182 = add nsw i32 %181, 1
%183 = sext i32 %182 to i64
%184 = getelementptr inbounds i8*, i8** %1, i64 %183
%185 = load i8*, i8** %184
%186 = tail call i32* @fopen(i8* %185, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%187 = tail call i32 @assert(i32* %186)
%188 = tail call i32 @fwrite(double* %31, i32 8, i32 %7, i32* %186)
%189 = tail call i32 @fclose(i32* %186)
%190 = tail call i32 @free(double* %34)
%191 = tail call i32 @free(double* %31)
br label %192
192: ; preds = %180, %19
%193 = load i32, i32* @EXIT_SUCCESS
ret i32 %193
}