#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 */

/* Variables and functions */
int /*<<< orphan*/ burn_in(double *, int, int, double, double);
double *calloc(int, int);
int /*<<< orphan*/ display_progress(int, int, int);
double *generate_random_initial_path(int, double, double);
double **malloc(int);
int /*<<< orphan*/ memcpy(double *, double *, int);
int /*<<< orphan*/ metropolis_update(double *, double, int, int, double);
int /*<<< orphan*/ printf(char *);
double **get_sample_paths(int n_paths, int nt, int n_sweeps, int n_burn,
                          double g, double D) {
  int i;
  double *paths = calloc(n_paths * nt, sizeof(double));
  double **rows = malloc(n_paths * sizeof(double *));
  double *path = generate_random_initial_path(nt, -5.0, 5.0);
  for (i = 0; i < n_paths; ++i) {
    rows[i] = paths + i * nt;
  }
  burn_in(path, n_burn, nt, g, D);
  printf("Getting sample paths...\n");
  for (i = 0; i < n_paths; i++) {
    metropolis_update(path, g, n_sweeps, nt, D);
    memcpy(rows[i], path, nt * sizeof(double));
    display_progress(i, n_paths, n_paths / 10);
  }
  return rows;
}


x86 assembly (clang, -O0):
<get_sample_paths>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
mov    -0x4(%rbp),%edi
imul   -0x8(%rbp),%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x30(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%edi
movsd  0xe2f(%rip),%xmm0
movsd  0xe2f(%rip),%xmm1
call   1040 <generate_random_initial_path@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1223 <get_sample_paths+0xa3>
mov    -0x30(%rbp),%rdx
mov    -0x24(%rbp),%eax
imul   -0x8(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e9 <get_sample_paths+0x69>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%edx
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
call   1030 <burn_in@plt>
lea    0xdcd(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12b9 <get_sample_paths+0x139>
mov    -0x40(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
movsd  -0x20(%rbp),%xmm1
call   1090 <metropolis_update@plt>
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x40(%rbp),%rsi
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    -0x24(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
call   1080 <display_progress@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    124f <get_sample_paths+0xcf>
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sample_paths>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x18(%rsp)
mov    %ecx,%ebx
mov    %edx,%r13d
mov    %esi,%r15d
mov    %edi,%r14d
mov    %esi,%edi
imul   %r14d,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,0x8(%rsp)
lea    0x0(,%r14,8),%edi
call   10a0 <malloc@plt>
mov    %rax,%rbp
movsd  0xe2e(%rip),%xmm0
movsd  0xe2e(%rip),%xmm1
mov    %r15d,%edi
call   1050 <generate_random_initial_path@plt>
mov    %rax,%r12
test   %r14d,%r14d
jle    121d <get_sample_paths+0x9d>
mov    %ebx,0x4(%rsp)
mov    %r13d,0x24(%rsp)
mov    %r14d,%r13d
movslq %r15d,%r8
lea    -0x1(%r13),%rax
mov    %r13d,%r9d
and    $0x3,%r9d
cmp    $0x3,%rax
movsd  0x10(%rsp),%xmm1
movsd  0x18(%rsp),%xmm0
jae    1247 <get_sample_paths+0xc7>
xor    %edx,%edx
jmp    129c <get_sample_paths+0x11c>
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
movsd  0x18(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
call   1030 <burn_in@plt>
lea    0xdd3(%rip),%rdi
call   1040 <puts@plt>
jmp    1363 <get_sample_paths+0x1e3>
mov    %r13d,%r10d
and    $0xfffffffc,%r10d
mov    %r8,%r11
shl    $0x4,%r11
mov    %r8,%rax
shl    $0x5,%rax
lea    0x0(,%r8,8),%rbx
lea    (%rbx,%rbx,2),%rcx
xor    %edx,%edx
mov    0x8(%rsp),%rsi
nop
mov    %rsi,0x0(%rbp,%rdx,8)
lea    (%rsi,%rbx,1),%rdi
mov    %rdi,0x8(%rbp,%rdx,8)
lea    (%rsi,%r11,1),%rdi
mov    %rdi,0x10(%rbp,%rdx,8)
lea    (%rsi,%rcx,1),%rdi
mov    %rdi,0x18(%rbp,%rdx,8)
add    $0x4,%rdx
add    %rax,%rsi
cmp    %rdx,%r10
jne    1270 <get_sample_paths+0xf0>
test   %r9,%r9
je     12d0 <get_sample_paths+0x150>
lea    0x0(,%rdx,8),%rax
add    %rbp,%rax
imul   %r8,%rdx
mov    0x8(%rsp),%rcx
lea    (%rcx,%rdx,8),%rcx
shl    $0x3,%r8
xor    %edx,%edx
nop
mov    %rcx,(%rax,%rdx,8)
add    $0x1,%rdx
add    %r8,%rcx
cmp    %rdx,%r9
jne    12c0 <get_sample_paths+0x140>
mov    %r12,%rdi
mov    0x4(%rsp),%esi
mov    %r15d,%edx
call   1030 <burn_in@plt>
lea    0xd2a(%rip),%rdi
call   1040 <puts@plt>
test   %r14d,%r14d
mov    %r15,0x8(%rsp)
mov    0x24(%rsp),%ebx
jle    1363 <get_sample_paths+0x1e3>
mov    0x8(%rsp),%rax
lea    0x0(,%rax,8),%eax
mov    %eax,0x4(%rsp)
mov    $0xcccccccd,%r14d
imul   %r13,%r14
shr    $0x23,%r14
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
movsd  0x18(%rsp),%xmm0
mov    %ebx,%esi
mov    0x8(%rsp),%rdx
movsd  0x10(%rsp),%xmm1
call   1090 <metropolis_update@plt>
mov    0x0(%rbp,%r15,8),%rdi
mov    %r12,%rsi
mov    0x4(%rsp),%edx
call   1070 <memcpy@plt>
mov    %r15d,%edi
mov    %r13d,%esi
mov    %r14d,%edx
call   1080 <display_progress@plt>
add    $0x1,%r15
cmp    %r15,%r13
jne    1320 <get_sample_paths+0x1a0>
mov    %rbp,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Getting sample paths...\0A\00"
define double** @get_sample_paths(i32 %0, i32 %1, i32 %2, i32 %3, double %4, double %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca i32
%14 = alloca double*
%15 = alloca double**
%16 = alloca double*
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store double %4, double* %11
store double %5, double* %12
%17 = load i32, i32* %7
%18 = load i32, i32* %8
%19 = mul nsw i32 %17, %18
%20 = call double* @calloc(i32 %19, i32 8)
store double* %20, double** %14
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 8
%24 = trunc i64 %23 to i32
%25 = call double** @malloc(i32 %24)
store double** %25, double*** %15
%26 = load i32, i32* %8
%27 = call double* @generate_random_initial_path(i32 %26, double -5.000000e+00, double 5.000000e+00)
store double* %27, double** %16
store i32 0, i32* %13
br label %28
28: ; preds = %43, %6
%29 = load i32, i32* %13
%30 = load i32, i32* %7
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %46
32: ; preds = %28
%33 = load double*, double** %14
%34 = load i32, i32* %13
%35 = load i32, i32* %8
%36 = mul nsw i32 %34, %35
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %33, i64 %37
%39 = load double**, double*** %15
%40 = load i32, i32* %13
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double*, double** %39, i64 %41
store double* %38, double** %42
br label %43
43: ; preds = %32
%44 = load i32, i32* %13
%45 = add nsw i32 %44, 1
store i32 %45, i32* %13
br label %28
46: ; preds = %28
%47 = load double*, double** %16
%48 = load i32, i32* %10
%49 = load i32, i32* %8
%50 = load double, double* %11
%51 = load double, double* %12
%52 = call i32 @burn_in(double* %47, i32 %48, i32 %49, double %50, double %51)
%53 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %13
br label %54
54: ; preds = %81, %46
%55 = load i32, i32* %13
%56 = load i32, i32* %7
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %84
58: ; preds = %54
%59 = load double*, double** %16
%60 = load double, double* %11
%61 = load i32, i32* %9
%62 = load i32, i32* %8
%63 = load double, double* %12
%64 = call i32 @metropolis_update(double* %59, double %60, i32 %61, i32 %62, double %63)
%65 = load double**, double*** %15
%66 = load i32, i32* %13
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds double*, double** %65, i64 %67
%69 = load double*, double** %68
%70 = load double*, double** %16
%71 = load i32, i32* %8
%72 = sext i32 %71 to i64
%73 = mul i64 %72, 8
%74 = trunc i64 %73 to i32
%75 = call i32 @memcpy(double* %69, double* %70, i32 %74)
%76 = load i32, i32* %13
%77 = load i32, i32* %7
%78 = load i32, i32* %7
%79 = sdiv i32 %78, 10
%80 = call i32 @display_progress(i32 %76, i32 %77, i32 %79)
br label %81
81: ; preds = %58
%82 = load i32, i32* %13
%83 = add nsw i32 %82, 1
store i32 %83, i32* %13
br label %54
84: ; preds = %54
%85 = load double**, double*** %15
ret double** %85
}

LLVM IR (-O2):
@str = [24 x i8] c"Getting sample paths...\00"
define noalias double** @get_sample_paths(i32 %0, i32 %1, i32 %2, i32 %3, double %4, double %5) {
%7 = mul nsw i32 %1, %0
%8 = tail call double* @calloc(i32 %7, i32 8)
%9 = shl i32 %0, 3
%10 = tail call double** @malloc(i32 %9)
%11 = tail call double* @generate_random_initial_path(i32 %1, double -5.000000e+00, double 5.000000e+00)
%12 = icmp sgt i32 %0, 0
br i1 %12, label %13, label %71
13: ; preds = %6
%14 = sext i32 %1 to i64
%15 = zext i32 %0 to i64
%16 = add nsw i64 %15, -1
%17 = and i64 %15, 3
%18 = icmp ult i64 %16, 3
br i1 %18, label %42, label %19
19: ; preds = %13
%20 = and i64 %15, 4294967292
br label %21
21: ; preds = %21, %19
%22 = phi i64 [ 0, %19 ], [ %39, %21 ]
%23 = phi i64 [ 0, %19 ], [ %40, %21 ]
%24 = mul nsw i64 %22, %14
%25 = getelementptr inbounds double, double* %8, i64 %24
%26 = getelementptr inbounds double*, double** %10, i64 %22
store double* %25, double** %26
%27 = or i64 %22, 1
%28 = mul nsw i64 %27, %14
%29 = getelementptr inbounds double, double* %8, i64 %28
%30 = getelementptr inbounds double*, double** %10, i64 %27
store double* %29, double** %30
%31 = or i64 %22, 2
%32 = mul nsw i64 %31, %14
%33 = getelementptr inbounds double, double* %8, i64 %32
%34 = getelementptr inbounds double*, double** %10, i64 %31
store double* %33, double** %34
%35 = or i64 %22, 3
%36 = mul nsw i64 %35, %14
%37 = getelementptr inbounds double, double* %8, i64 %36
%38 = getelementptr inbounds double*, double** %10, i64 %35
store double* %37, double** %38
%39 = add nuw nsw i64 %22, 4
%40 = add i64 %23, 4
%41 = icmp eq i64 %40, %20
br i1 %41, label %42, label %21
42: ; preds = %21, %13
%43 = phi i64 [ 0, %13 ], [ %39, %21 ]
%44 = icmp eq i64 %17, 0
br i1 %44, label %54, label %45
45: ; preds = %42, %45
%46 = phi i64 [ %51, %45 ], [ %43, %42 ]
%47 = phi i64 [ %52, %45 ], [ 0, %42 ]
%48 = mul nsw i64 %46, %14
%49 = getelementptr inbounds double, double* %8, i64 %48
%50 = getelementptr inbounds double*, double** %10, i64 %46
store double* %49, double** %50
%51 = add nuw nsw i64 %46, 1
%52 = add i64 %47, 1
%53 = icmp eq i64 %52, %17
br i1 %53, label %54, label %45
54: ; preds = %45, %42
%55 = tail call i32 @burn_in(double* %11, i32 %3, i32 %1, double %4, double %5)
%56 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br i1 %12, label %57, label %74
57: ; preds = %54
%58 = shl i32 %1, 3
%59 = udiv i32 %0, 10
%60 = zext i32 %0 to i64
br label %61
61: ; preds = %57, %61
%62 = phi i64 [ 0, %57 ], [ %69, %61 ]
%63 = tail call i32 @metropolis_update(double* %11, double %4, i32 %2, i32 %1, double %5)
%64 = getelementptr inbounds double*, double** %10, i64 %62
%65 = load double*, double** %64
%66 = tail call i32 @memcpy(double* %65, double* %11, i32 %58)
%67 = trunc i64 %62 to i32
%68 = tail call i32 @display_progress(i32 %67, i32 %0, i32 %59)
%69 = add nuw nsw i64 %62, 1
%70 = icmp eq i64 %69, %60
br i1 %70, label %74, label %61
71: ; preds = %6
%72 = tail call i32 @burn_in(double* %11, i32 %3, i32 %1, double %4, double %5)
%73 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %74
74: ; preds = %61, %71, %54
ret double** %10
}