#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 __float_as_int(float);
float __int_as_float(int);
int atomicCAS(int *, int, int);
float atomicMin(float *address, float val) {
  int ret = __float_as_int(*address);
  while (val < __int_as_float(ret)) {
    int old = ret;
    if ((ret = atomicCAS((int *)address, old, __float_as_int(val))) == old)
      break;
  }
  return __int_as_float(ret);
}


x86 assembly (clang, -O0):
<atomicMin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
call   1040 <__float_as_int@plt>
mov    %eax,-0x10(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <__int_as_float@plt>
movss  -0x18(%rbp),%xmm1
ucomiss %xmm1,%xmm0
jbe    11b3 <atomicMin+0x83>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movss  -0xc(%rbp),%xmm0
call   1040 <__float_as_int@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    %eax,%edx
call   1050 <atomicCAS@plt>
mov    %eax,-0x10(%rbp)
cmp    -0x14(%rbp),%eax
jne    11ae <atomicMin+0x7e>
jmp    11b3 <atomicMin+0x83>
jmp    1151 <atomicMin+0x21>
mov    -0x10(%rbp),%edi
call   1030 <__int_as_float@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atomicMin>:
push   %rbp
push   %rbx
push   %rax
movss  %xmm0,0x4(%rsp)
mov    %rdi,%rbx
movss  (%rdi),%xmm0
call   1040 <__float_as_int@plt>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <__int_as_float@plt>
ucomiss 0x4(%rsp),%xmm0
jbe    117b <atomicMin+0x4b>
movss  0x4(%rsp),%xmm0
call   1040 <__float_as_int@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1050 <atomicCAS@plt>
cmp    %ebp,%eax
jne    1150 <atomicMin+0x20>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <__int_as_float@plt>

LLVM IR (-O0):
define float @atomicMin(float* %0, float %1) {
%3 = alloca float*
%4 = alloca float
%5 = alloca i32
%6 = alloca i32
store float* %0, float** %3
store float %1, float* %4
%7 = load float*, float** %3
%8 = load float, float* %7
%9 = call i32 @__float_as_int(float %8)
store i32 %9, i32* %5
br label %10
10: ; preds = %26, %2
%11 = load float, float* %4
%12 = load i32, i32* %5
%13 = call float @__int_as_float(i32 %12)
%14 = fcmp olt float %11, %13
br i1 %14, label %15, label %27
15: ; preds = %10
%16 = load i32, i32* %5
store i32 %16, i32* %6
%17 = load float*, float** %3
%18 = bitcast float* %17 to i32*
%19 = load i32, i32* %6
%20 = load float, float* %4
%21 = call i32 @__float_as_int(float %20)
%22 = call i32 @atomicCAS(i32* %18, i32 %19, i32 %21)
store i32 %22, i32* %5
%23 = load i32, i32* %6
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %15
br label %27
26: ; preds = %15
br label %10
27: ; preds = %25, %10
%28 = load i32, i32* %5
%29 = call float @__int_as_float(i32 %28)
ret float %29
}

LLVM IR (-O2):
define float @atomicMin(float* %0, float %1) {
%3 = load float, float* %0
%4 = tail call i32 @__float_as_int(float %3)
%5 = bitcast float* %0 to i32*
br label %6
6: ; preds = %10, %2
%7 = phi i32 [ %4, %2 ], [ %12, %10 ]
%8 = tail call float @__int_as_float(i32 %7)
%9 = fcmp ogt float %8, %1
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = tail call i32 @__float_as_int(float %1)
%12 = tail call i32 @atomicCAS(i32* %5, i32 %7, i32 %11)
%13 = icmp eq i32 %12, %7
br i1 %13, label %14, label %6
14: ; preds = %10, %6
%15 = tail call float @__int_as_float(i32 %7)
ret float %15
}