#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 */
double delta_S(double *, double, double, int);
int /*<<< orphan*/ exp(double);
double fmin(double, int /*<<< orphan*/);
double rand_in_range(double, double);
double metropolis_update(double *path, double g, int n_sweeps, int nt,
                         double D) {
  int sweep, tstep;
  double shift, dS, accept_prob;
  for (sweep = 0; sweep < n_sweeps; sweep++) {
    for (tstep = 0; tstep < nt; tstep++) {
      shift = rand_in_range(-1.0 * D, D);
      dS = delta_S(path, g, shift, tstep);
      accept_prob = fmin(1.0, exp(-1.0 * dS));
      if (rand_in_range(0.0, 1.0) <= accept_prob) {
        path[tstep] += shift;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<metropolis_update>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    123e <metropolis_update+0xfe>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    122b <metropolis_update+0xeb>
movsd  0xe7e(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
call   1060 <rand_in_range@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mov    -0x28(%rbp),%esi
call   1040 <delta_S@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  0xe47(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
call   1050 <exp@plt>
mov    %eax,%edi
movsd  0xe2b(%rip),%xmm0
call   1030 <fmin@plt>
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  0xe16(%rip),%xmm1
call   1060 <rand_in_range@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1218 <metropolis_update+0xd8>
movsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    121d <metropolis_update+0xdd>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1176 <metropolis_update+0x36>
jmp    1230 <metropolis_update+0xf0>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1163 <metropolis_update+0x23>
xorps  %xmm0,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<metropolis_update>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
movapd %xmm1,0x20(%rsp)
movsd  %xmm0,0x8(%rsp)
test   %esi,%esi
jle    1234 <metropolis_update+0xf4>
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbx
movapd 0xe8d(%rip),%xmm0
xorpd  0x20(%rsp),%xmm0
movapd %xmm0,0x30(%rsp)
mov    %edx,%r12d
xor    %r13d,%r13d
jmp    119d <metropolis_update+0x5d>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r13d
cmp    %r15d,%r13d
je     1234 <metropolis_update+0xf4>
test   %r14d,%r14d
jle    1190 <metropolis_update+0x50>
xor    %ebp,%ebp
jmp    11b9 <metropolis_update+0x79>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%r12
je     1190 <metropolis_update+0x50>
movaps 0x30(%rsp),%xmm0
movaps 0x20(%rsp),%xmm1
call   1060 <rand_in_range@plt>
movaps %xmm0,%xmm1
mov    %rbx,%rdi
movsd  0x8(%rsp),%xmm0
movsd  %xmm1,0x10(%rsp)
mov    %ebp,%esi
call   1040 <delta_S@plt>
xorps  0xe18(%rip),%xmm0
call   1050 <exp@plt>
movsd  0xe1b(%rip),%xmm0
mov    %eax,%edi
call   1030 <fmin@plt>
movsd  %xmm0,0x18(%rsp)
xorpd  %xmm0,%xmm0
movsd  0xe02(%rip),%xmm1
call   1060 <rand_in_range@plt>
movsd  0x18(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jb     11b0 <metropolis_update+0x70>
movsd  0x10(%rsp),%xmm0
addsd  (%rbx,%rbp,8),%xmm0
movsd  %xmm0,(%rbx,%rbp,8)
jmp    11b0 <metropolis_update+0x70>
xorpd  %xmm0,%xmm0
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @metropolis_update(double* %0, double %1, i32 %2, i32 %3, double %4) {
%6 = alloca double*
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca i32
%12 = alloca i32
%13 = alloca double
%14 = alloca double
%15 = alloca double
store double* %0, double** %6
store double %1, double* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store double %4, double* %10
store i32 0, i32* %11
br label %16
16: ; preds = %55, %5
%17 = load i32, i32* %11
%18 = load i32, i32* %8
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %58
20: ; preds = %16
store i32 0, i32* %12
br label %21
21: ; preds = %51, %20
%22 = load i32, i32* %12
%23 = load i32, i32* %9
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %54
25: ; preds = %21
%26 = load double, double* %10
%27 = fmul double -1.000000e+00, %26
%28 = load double, double* %10
%29 = call double @rand_in_range(double %27, double %28)
store double %29, double* %13
%30 = load double*, double** %6
%31 = load double, double* %7
%32 = load double, double* %13
%33 = load i32, i32* %12
%34 = call double @delta_S(double* %30, double %31, double %32, i32 %33)
store double %34, double* %14
%35 = load double, double* %14
%36 = fmul double -1.000000e+00, %35
%37 = call i32 @exp(double %36)
%38 = call double @fmin(double 1.000000e+00, i32 %37)
store double %38, double* %15
%39 = call double @rand_in_range(double 0.000000e+00, double 1.000000e+00)
%40 = load double, double* %15
%41 = fcmp ole double %39, %40
br i1 %41, label %42, label %50
42: ; preds = %25
%43 = load double, double* %13
%44 = load double*, double** %6
%45 = load i32, i32* %12
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %44, i64 %46
%48 = load double, double* %47
%49 = fadd double %48, %43
store double %49, double* %47
br label %50
50: ; preds = %42, %25
br label %51
51: ; preds = %50
%52 = load i32, i32* %12
%53 = add nsw i32 %52, 1
store i32 %53, i32* %12
br label %21
54: ; preds = %21
br label %55
55: ; preds = %54
%56 = load i32, i32* %11
%57 = add nsw i32 %56, 1
store i32 %57, i32* %11
br label %16
58: ; preds = %16
ret double 0.000000e+00
}

LLVM IR (-O2):
define double @metropolis_update(double* %0, double %1, i32 %2, i32 %3, double %4) {
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %33
7: ; preds = %5
%8 = icmp sgt i32 %3, 0
%9 = fneg double %4
%10 = zext i32 %3 to i64
br label %11
11: ; preds = %7, %30
%12 = phi i32 [ 0, %7 ], [ %31, %30 ]
br i1 %8, label %13, label %30
13: ; preds = %11, %27
%14 = phi i64 [ %28, %27 ], [ 0, %11 ]
%15 = tail call double @rand_in_range(double %9, double %4)
%16 = trunc i64 %14 to i32
%17 = tail call double @delta_S(double* %0, double %1, double %15, i32 %16)
%18 = fneg double %17
%19 = tail call i32 @exp(double %18)
%20 = tail call double @fmin(double 1.000000e+00, i32 %19)
%21 = tail call double @rand_in_range(double 0.000000e+00, double 1.000000e+00)
%22 = fcmp ugt double %21, %20
br i1 %22, label %27, label %23
23: ; preds = %13
%24 = getelementptr inbounds double, double* %0, i64 %14
%25 = load double, double* %24
%26 = fadd double %15, %25
store double %26, double* %24
br label %27
27: ; preds = %13, %23
%28 = add nuw nsw i64 %14, 1
%29 = icmp eq i64 %28, %10
br i1 %29, label %30, label %13
30: ; preds = %27, %11
%31 = add nuw nsw i32 %12, 1
%32 = icmp eq i32 %31, %2
br i1 %32, label %33, label %11
33: ; preds = %30, %5
ret double 0.000000e+00
}