#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 */
float expf(float);
int rand();
int accept_worse(float cost, float new_cost, int temp) {
  int n_rand;
  float a = 0;
  n_rand = rand() % 2;
  a = expf((cost - new_cost) / temp);
  if (a >= n_rand && n_rand != 0)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<accept_worse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
mov    %edi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
movss  -0x8(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
cvtsi2ssl -0x10(%rbp),%xmm1
divss  %xmm1,%xmm0
call   1030 <expf@plt>
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
cvtsi2ssl -0x14(%rbp),%xmm1
ucomiss %xmm1,%xmm0
jb     1195 <accept_worse+0x75>
cmpl   $0x0,-0x14(%rbp)
je     1195 <accept_worse+0x75>
movl   $0x1,-0x4(%rbp)
jmp    119c <accept_worse+0x7c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<accept_worse>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
movss  %xmm1,0x4(%rsp)
movss  %xmm0,(%rsp)
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,%ebp
shr    $0x1f,%eax
add    %ebp,%eax
and    $0xfffffffe,%eax
sub    %eax,%ebp
movss  (%rsp),%xmm1
subss  0x4(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
divss  %xmm0,%xmm1
movaps %xmm1,%xmm0
call   1030 <expf@plt>
xorps  %xmm1,%xmm1
cvtsi2ss %ebp,%xmm1
ucomiss %xmm1,%xmm0
setae  %al
test   %ebp,%ebp
setne  %cl
and    %al,%cl
movzbl %cl,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @accept_worse(float %0, float %1, i32 %2) {
%4 = alloca i32
%5 = alloca float
%6 = alloca float
%7 = alloca i32
%8 = alloca i32
%9 = alloca float
store float %0, float* %5
store float %1, float* %6
store i32 %2, i32* %7
store float 0.000000e+00, float* %9
%10 = call i32 (...) @rand()
%11 = srem i32 %10, 2
store i32 %11, i32* %8
%12 = load float, float* %5
%13 = load float, float* %6
%14 = fsub float %12, %13
%15 = load i32, i32* %7
%16 = sitofp i32 %15 to float
%17 = fdiv float %14, %16
%18 = call float @expf(float %17)
store float %18, float* %9
%19 = load float, float* %9
%20 = load i32, i32* %8
%21 = sitofp i32 %20 to float
%22 = fcmp oge float %19, %21
br i1 %22, label %23, label %27
23: ; preds = %3
%24 = load i32, i32* %8
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 1, i32* %4
br label %28
27: ; preds = %23, %3
store i32 0, i32* %4
br label %28
28: ; preds = %27, %26
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
define i32 @accept_worse(float %0, float %1, i32 %2) {
%4 = tail call i32 (...) @rand()
%5 = srem i32 %4, 2
%6 = fsub float %0, %1
%7 = sitofp i32 %2 to float
%8 = fdiv float %6, %7
%9 = tail call float @expf(float %8)
%10 = sitofp i32 %5 to float
%11 = fcmp oge float %9, %10
%12 = icmp ne i32 %5, 0
%13 = and i1 %12, %11
%14 = zext i1 %13 to i32
ret i32 %14
}