#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 */
scalar_t__ EOF;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ error_print(char *);
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 *, double *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ realloc(double *, int);
scalar_t__ sqrt(double);
int /*<<< orphan*/ stderr;
void main(int argc, char *argv[]) {
  double *x, dum;
  int i, nn, j;
  long ik;
  FILE *fr;
  if (argc < 2 || argc > 2) {
    error_print(argv[0]);
    exit(1);
  }
  fr = fopen(argv[1], "r");
  x = (double *)calloc(1, sizeof(double));
  ik = 0;
  while ((fscanf(fr, "%le", &dum)) != EOF) {
    x = (double *)realloc(x, sizeof(double) * (ik + 1));
    if (x == NULL) {
      fprintf(stderr, "unfold: Allocation error while reading, exiting\n");
      exit(1);
    }
    x[ik] = dum;
    ik++;
  }
  nn = (int)sqrt((double)ik);
  fclose(fr);
  printf("\nA=[");
  ik = 0;
  for (i = 1; i <= nn; i++) {
    for (j = 1; j <= nn; j++) {
      if (j != nn)
        printf("%g ", x[ik]);
      else {
        if (i != nn)
          printf("%g\n", x[ik]);
        else
          printf("%g", x[ik]);
      }
      ik++;
    }
  }
  printf("];\n");
  free(x);
  fclose(fr);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
jl     11d3 <main+0x23>
cmpl   $0x2,-0x4(%rbp)
jle    11e9 <main+0x39>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <error_print@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe08(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    $0x1,%edi
mov    $0x8,%esi
call   1070 <calloc@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xddb(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1060 <fscanf@plt>
mov    0x2db1(%rip),%rcx
cmp    (%rcx),%rax
je     12a8 <main+0xf8>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rax
add    $0x1,%rax
shl    $0x3,%rax
mov    %eax,%esi
call   10a0 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1285 <main+0xd5>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
lea    0xd90(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    121c <main+0x6c>
cvtsi2sdq -0x38(%rbp),%xmm0
call   10c0 <sqrt@plt>
mov    %eax,-0x28(%rbp)
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x0,-0x38(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jg     13a0 <main+0x1f0>
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jg     138d <main+0x1dd>
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
je     1327 <main+0x177>
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xd21(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
jmp    1373 <main+0x1c3>
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
je     1353 <main+0x1a3>
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xcf9(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
jmp    136e <main+0x1be>
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xcdd(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
jmp    1373 <main+0x1c3>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12ef <main+0x13f>
jmp    1392 <main+0x1e2>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12dc <main+0x12c>
lea    0xca0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    135d <main+0x19d>
mov    0x8(%rsi),%rdi
lea    0xe1e(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r14
mov    $0x8,%ebp
mov    $0x1,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,%rbx
lea    0xdfa(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %r14,(%rsp)
mov    %r14,%rdi
call   1070 <fscanf@plt>
mov    0x2dc8(%rip),%r13
cmp    0x0(%r13),%rax
jne    122c <main+0x6c>
xorpd  %xmm0,%xmm0
jmp    1286 <main+0xc6>
xor    %r14d,%r14d
lea    0xdcc(%rip),%r15
lea    0x8(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %ebp,%esi
call   10b0 <realloc@plt>
test   %rax,%rax
je     133e <main+0x17e>
mov    %rax,%rbx
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%rax,%r14,8)
mov    (%rsp),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1070 <fscanf@plt>
add    $0x8,%ebp
add    $0x1,%r14
cmp    0x0(%r13),%rax
jne    1240 <main+0x80>
xorps  %xmm0,%xmm0
cvtsi2sd %r14,%xmm0
call   10d0 <sqrt@plt>
mov    %rax,%r15
mov    (%rsp),%rdi
call   1050 <fclose@plt>
lea    0xd99(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
test   %r15d,%r15d
jle    1312 <main+0x152>
mov    $0x1,%r14d
xor    %ebp,%ebp
lea    0xd83(%rip),%r12
mov    %r15,0x10(%rsp)
xchg   %ax,%ax
cmp    %r15d,%r14d
lea    0xd76(%rip),%r13
lea    0xd73(%rip),%rax
cmove  %rax,%r13
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0x1,%r15d
movsd  (%rbx,%rbp,8),%xmm0
mov    %r12,%rdi
cmove  %r13,%rdi
mov    $0x1,%al
call   1060 <printf@plt>
add    $0x1,%rbp
add    $0xffffffff,%r15d
jne    12e0 <main+0x120>
lea    0x1(%r14),%eax
mov    0x10(%rsp),%r15
cmp    %r15d,%r14d
mov    %eax,%r14d
jne    12c0 <main+0x100>
lea    0xd2e(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    (%rsp),%rdi
call   1050 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c93(%rip),%rax
mov    (%rax),%edi
lea    0xcb8(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    (%rsi),%rdi
call   10a0 <error_print@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [4 x i8] c"%le\00"
@EOF = global i64 0
@stderr = global i32 0
@.str.2 = [49 x i8] c"unfold: Allocation error while reading, exiting\0A\00"
@.str.3 = [5 x i8] c"\0AA=[\00"
@.str.4 = [4 x i8] c"%g \00"
@.str.5 = [4 x i8] c"%g\0A\00"
@.str.6 = [3 x i8] c"%g\00"
@.str.7 = [4 x i8] c"];\0A\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca double*
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca i32*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 2
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = load i32, i32* %3
%16 = icmp sgt i32 %15, 2
br i1 %16, label %17, label %23
17: ; preds = %14, %2
%18 = load i8**, i8*** %4
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 @error_print(i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %14
%24 = load i8**, i8*** %4
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %27, i32** %11
%28 = call i64 @calloc(i32 1, i32 8)
%29 = inttoptr i64 %28 to double*
store double* %29, double** %5
store i64 0, i64* %10
br label %30
30: ; preds = %49, %23
%31 = load i32*, i32** %11
%32 = call i64 @fscanf(i32* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %6)
%33 = load i64, i64* @EOF
%34 = icmp ne i64 %32, %33
br i1 %34, label %35, label %56
35: ; preds = %30
%36 = load double*, double** %5
%37 = load i64, i64* %10
%38 = add nsw i64 %37, 1
%39 = mul i64 8, %38
%40 = trunc i64 %39 to i32
%41 = call i64 @realloc(double* %36, i32 %40)
%42 = inttoptr i64 %41 to double*
store double* %42, double** %5
%43 = load double*, double** %5
%44 = icmp eq double* %43, null
br i1 %44, label %45, label %49
45: ; preds = %35
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %35
%50 = load double, double* %6
%51 = load double*, double** %5
%52 = load i64, i64* %10
%53 = getelementptr inbounds double, double* %51, i64 %52
store double %50, double* %53
%54 = load i64, i64* %10
%55 = add nsw i64 %54, 1
store i64 %55, i64* %10
br label %30
56: ; preds = %30
%57 = load i64, i64* %10
%58 = sitofp i64 %57 to double
%59 = call i64 @sqrt(double %58)
%60 = trunc i64 %59 to i32
store i32 %60, i32* %8
%61 = load i32*, i32** %11
%62 = call i32 @fclose(i32* %61)
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i64 0, i64* %10
store i32 1, i32* %7
br label %64
64: ; preds = %107, %56
%65 = load i32, i32* %7
%66 = load i32, i32* %8
%67 = icmp sle i32 %65, %66
br i1 %67, label %68, label %110
68: ; preds = %64
store i32 1, i32* %9
br label %69
69: ; preds = %103, %68
%70 = load i32, i32* %9
%71 = load i32, i32* %8
%72 = icmp sle i32 %70, %71
br i1 %72, label %73, label %106
73: ; preds = %69
%74 = load i32, i32* %9
%75 = load i32, i32* %8
%76 = icmp ne i32 %74, %75
br i1 %76, label %77, label %83
77: ; preds = %73
%78 = load double*, double** %5
%79 = load i64, i64* %10
%80 = getelementptr inbounds double, double* %78, i64 %79
%81 = load double, double* %80
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double %81)
br label %100
83: ; preds = %73
%84 = load i32, i32* %7
%85 = load i32, i32* %8
%86 = icmp ne i32 %84, %85
br i1 %86, label %87, label %93
87: ; preds = %83
%88 = load double*, double** %5
%89 = load i64, i64* %10
%90 = getelementptr inbounds double, double* %88, i64 %89
%91 = load double, double* %90
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), double %91)
br label %99
93: ; preds = %83
%94 = load double*, double** %5
%95 = load i64, i64* %10
%96 = getelementptr inbounds double, double* %94, i64 %95
%97 = load double, double* %96
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), double %97)
br label %99
99: ; preds = %93, %87
br label %100
100: ; preds = %99, %77
%101 = load i64, i64* %10
%102 = add nsw i64 %101, 1
store i64 %102, i64* %10
br label %103
103: ; preds = %100
%104 = load i32, i32* %9
%105 = add nsw i32 %104, 1
store i32 %105, i32* %9
br label %69
106: ; preds = %69
br label %107
107: ; preds = %106
%108 = load i32, i32* %7
%109 = add nsw i32 %108, 1
store i32 %109, i32* %7
br label %64
110: ; preds = %64
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%112 = load double*, double** %5
%113 = call i32 @free(double* %112)
%114 = load i32*, i32** %11
%115 = call i32 @fclose(i32* %114)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [4 x i8] c"%le\00"
@EOF = global i64 0
@stderr = global i32 0
@.str.2 = [49 x i8] c"unfold: Allocation error while reading, exiting\0A\00"
@.str.3 = [5 x i8] c"\0AA=[\00"
@.str.4 = [4 x i8] c"%g \00"
@.str.5 = [4 x i8] c"%g\0A\00"
@.str.6 = [3 x i8] c"%g\00"
@str = [3 x i8] c"];\00"
define void @main(i32 %0, i8** nocapture %1) {
%3 = alloca double
%4 = bitcast double* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @error_print(i8* %7)
%9 = tail call i32 @exit(i32 1)
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, i64 0, i64 0))
%14 = tail call i64 @calloc(i32 1, i32 8)
%15 = inttoptr i64 %14 to double*
%16 = call i64 @fscanf(i32* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %3)
%17 = load i64, i64* @EOF
%18 = icmp eq i64 %16, %17
br i1 %18, label %41, label %19
19: ; preds = %10, %32
%20 = phi double* [ %26, %32 ], [ %15, %10 ]
%21 = phi i64 [ %22, %32 ], [ 0, %10 ]
%22 = add nuw nsw i64 %21, 1
%23 = trunc i64 %22 to i32
%24 = shl i32 %23, 3
%25 = call i64 @realloc(double* %20, i32 %24)
%26 = inttoptr i64 %25 to double*
%27 = icmp eq i64 %25, 0
br i1 %27, label %28, label %32
28: ; preds = %19
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %19
%33 = load double, double* %3
%34 = getelementptr inbounds double, double* %26, i64 %21
store double %33, double* %34
%35 = call i64 @fscanf(i32* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %3)
%36 = load i64, i64* @EOF
%37 = icmp eq i64 %35, %36
br i1 %37, label %38, label %19
38: ; preds = %32
%39 = inttoptr i64 %25 to double*
%40 = sitofp i64 %22 to double
br label %41
41: ; preds = %38, %10
%42 = phi double [ %40, %38 ], [ 0.000000e+00, %10 ]
%43 = phi double* [ %39, %38 ], [ %15, %10 ]
%44 = call i64 @sqrt(double %42)
%45 = trunc i64 %44 to i32
%46 = call i32 @fclose(i32* %13)
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%48 = icmp slt i32 %45, 1
br i1 %48, label %71, label %49
49: ; preds = %41, %68
%50 = phi i64 [ %64, %68 ], [ 0, %41 ]
%51 = phi i32 [ %69, %68 ], [ 1, %41 ]
%52 = icmp eq i32 %51, %45
%53 = trunc i64 %50 to i32
%54 = add i32 %45, %53
%55 = select i1 %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0)
br label %56
56: ; preds = %49, %56
%57 = phi i64 [ %50, %49 ], [ %64, %56 ]
%58 = phi i32 [ 1, %49 ], [ %65, %56 ]
%59 = icmp eq i32 %58, %45
%60 = getelementptr inbounds double, double* %43, i64 %57
%61 = load double, double* %60
%62 = select i1 %59, i8* %55, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0)
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %62, double %61)
%64 = add i64 %57, 1
%65 = add nuw nsw i32 %58, 1
%66 = trunc i64 %64 to i32
%67 = icmp eq i32 %54, %66
br i1 %67, label %68, label %56
68: ; preds = %56
%69 = add nuw i32 %51, 1
%70 = icmp eq i32 %51, %45
br i1 %70, label %71, label %49
71: ; preds = %68, %41
%72 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%73 = call i32 @free(double* %43)
%74 = call i32 @fclose(i32* %13)
ret void
}