#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 exp(double);
scalar_t__ isinf(double);
double inverse_transform2(double z, double lb, double ub) {
  if (!isinf(lb) && isinf(ub)) {
    return exp(z) + lb;
  } else if (!isinf(ub) && isinf(lb)) {
    return ub - exp(z);
  } else if (isinf(ub) && isinf(lb)) {
    return z;
  }
  double inv_logit_x;
  if (z > 0) {
    double exp_minus_x = exp(-z);
    inv_logit_x = 1.0 / (1.0 + exp_minus_x);
    if (!isinf(z) && inv_logit_x == 1)
      inv_logit_x = 1 - 1e-15;
  } else {
    double exp_x = exp(z);
    inv_logit_x = 1.0 - 1.0 / (1.0 + exp_x);
    if (!isinf(z) && inv_logit_x == 0)
      inv_logit_x = 1e-15;
  }
  return lb + (ub - lb) * inv_logit_x;
}


x86 assembly (clang, -O0):
<inverse_transform2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <isinf@plt>
cmp    $0x0,%rax
jne    1178 <inverse_transform2+0x58>
movsd  -0x20(%rbp),%xmm0
call   1040 <isinf@plt>
cmp    $0x0,%rax
je     1178 <inverse_transform2+0x58>
movsd  -0x10(%rbp),%xmm0
call   1030 <exp@plt>
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    133c <inverse_transform2+0x21c>
movsd  -0x20(%rbp),%xmm0
call   1040 <isinf@plt>
cmp    $0x0,%rax
jne    11ca <inverse_transform2+0xaa>
movsd  -0x18(%rbp),%xmm0
call   1040 <isinf@plt>
cmp    $0x0,%rax
je     11ca <inverse_transform2+0xaa>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    133c <inverse_transform2+0x21c>
movsd  -0x20(%rbp),%xmm0
call   1040 <isinf@plt>
cmp    $0x0,%rax
je     1201 <inverse_transform2+0xe1>
movsd  -0x18(%rbp),%xmm0
call   1040 <isinf@plt>
cmp    $0x0,%rax
je     1201 <inverse_transform2+0xe1>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    133c <inverse_transform2+0x21c>
jmp    1206 <inverse_transform2+0xe6>
jmp    120b <inverse_transform2+0xeb>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    12a4 <inverse_transform2+0x184>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <exp@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  0xdb5(%rip),%xmm1
addsd  -0x30(%rbp),%xmm1
movsd  0xda8(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <isinf@plt>
cmp    $0x0,%rax
jne    129f <inverse_transform2+0x17f>
movsd  -0x28(%rbp),%xmm0
movsd  0xd7e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    129f <inverse_transform2+0x17f>
jp     129f <inverse_transform2+0x17f>
movsd  0xd76(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    131b <inverse_transform2+0x1fb>
movsd  -0x10(%rbp),%xmm0
call   1030 <exp@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  0xd45(%rip),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  0xd38(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  0xd2c(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <isinf@plt>
cmp    $0x0,%rax
jne    1316 <inverse_transform2+0x1f6>
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1316 <inverse_transform2+0x1f6>
jp     1316 <inverse_transform2+0x1f6>
movsd  0xcf7(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    131b <inverse_transform2+0x1fb>
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inverse_transform2>:
sub    $0x38,%rsp
movsd  %xmm2,(%rsp)
movaps %xmm0,0x10(%rsp)
movsd  %xmm1,0x8(%rsp)
movaps %xmm1,%xmm0
call   1040 <isinf@plt>
test   %rax,%rax
je     117d <inverse_transform2+0x5d>
movsd  (%rsp),%xmm0
call   1040 <isinf@plt>
test   %rax,%rax
je     121d <inverse_transform2+0xfd>
movsd  (%rsp),%xmm0
call   1040 <isinf@plt>
test   %rax,%rax
je     11a2 <inverse_transform2+0x82>
movsd  0x8(%rsp),%xmm0
call   1040 <isinf@plt>
test   %rax,%rax
je     11a2 <inverse_transform2+0x82>
movaps 0x10(%rsp),%xmm0
add    $0x38,%rsp
ret
movsd  (%rsp),%xmm0
call   1040 <isinf@plt>
test   %rax,%rax
je     1141 <inverse_transform2+0x21>
movapd 0x10(%rsp),%xmm0
call   1030 <exp@plt>
addsd  0x8(%rsp),%xmm0
add    $0x38,%rsp
ret
xorpd  %xmm0,%xmm0
movapd 0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jbe    124e <inverse_transform2+0x12e>
movapd 0xe62(%rip),%xmm0
xorpd  %xmm1,%xmm0
call   1030 <exp@plt>
movsd  0xe31(%rip),%xmm1
addsd  %xmm1,%xmm0
divsd  %xmm0,%xmm1
movapd %xmm1,0x20(%rsp)
movaps 0x10(%rsp),%xmm0
call   1040 <isinf@plt>
movapd 0x20(%rsp),%xmm2
test   %rax,%rax
movsd  (%rsp),%xmm0
jne    12b0 <inverse_transform2+0x190>
movsd  0xdfd(%rip),%xmm3
cmpeqsd %xmm2,%xmm3
movapd %xmm3,%xmm1
andnpd %xmm2,%xmm1
movsd  0xdf8(%rip),%xmm2
jmp    12a8 <inverse_transform2+0x188>
movsd  0x8(%rsp),%xmm0
call   1040 <isinf@plt>
test   %rax,%rax
je     1154 <inverse_transform2+0x34>
movapd 0x10(%rsp),%xmm0
call   1030 <exp@plt>
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x38,%rsp
ret
movapd %xmm1,%xmm0
call   1030 <exp@plt>
movsd  0xda1(%rip),%xmm2
addsd  %xmm2,%xmm0
movapd %xmm2,%xmm1
divsd  %xmm0,%xmm1
subsd  %xmm1,%xmm2
movapd %xmm2,0x20(%rsp)
movaps 0x10(%rsp),%xmm0
call   1040 <isinf@plt>
movapd 0x20(%rsp),%xmm2
test   %rax,%rax
movsd  (%rsp),%xmm0
jne    12b0 <inverse_transform2+0x190>
xorpd  %xmm3,%xmm3
cmpeqsd %xmm2,%xmm3
movapd %xmm3,%xmm1
andnpd %xmm2,%xmm1
movsd  0xd60(%rip),%xmm2
andpd  %xmm3,%xmm2
orpd   %xmm1,%xmm2
movsd  0x8(%rsp),%xmm1
subsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x38,%rsp
ret

LLVM IR (-O0):
define double @inverse_transform2(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
%11 = load double, double* %6
%12 = call i64 @isinf(double %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %23, label %14
14: ; preds = %3
%15 = load double, double* %7
%16 = call i64 @isinf(double %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load double, double* %5
%20 = call double @exp(double %19)
%21 = load double, double* %6
%22 = fadd double %20, %21
store double %22, double* %4
br label %88
23: ; preds = %14, %3
%24 = load double, double* %7
%25 = call i64 @isinf(double %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %36, label %27
27: ; preds = %23
%28 = load double, double* %6
%29 = call i64 @isinf(double %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %27
%32 = load double, double* %7
%33 = load double, double* %5
%34 = call double @exp(double %33)
%35 = fsub double %32, %34
store double %35, double* %4
br label %88
36: ; preds = %27, %23
%37 = load double, double* %7
%38 = call i64 @isinf(double %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %36
%41 = load double, double* %6
%42 = call i64 @isinf(double %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = load double, double* %5
store double %45, double* %4
br label %88
46: ; preds = %40, %36
br label %47
47: ; preds = %46
br label %48
48: ; preds = %47
%49 = load double, double* %5
%50 = fcmp ogt double %49, 0.000000e+00
br i1 %50, label %51, label %66
51: ; preds = %48
%52 = load double, double* %5
%53 = fneg double %52
%54 = call double @exp(double %53)
store double %54, double* %9
%55 = load double, double* %9
%56 = fadd double 1.000000e+00, %55
%57 = fdiv double 1.000000e+00, %56
store double %57, double* %8
%58 = load double, double* %5
%59 = call i64 @isinf(double %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %65, label %61
61: ; preds = %51
%62 = load double, double* %8
%63 = fcmp oeq double %62, 1.000000e+00
br i1 %63, label %64, label %65
64: ; preds = %61
store double 0x3FEFFFFFFFFFFFF7, double* %8
br label %65
65: ; preds = %64, %61, %51
br label %81
66: ; preds = %48
%67 = load double, double* %5
%68 = call double @exp(double %67)
store double %68, double* %10
%69 = load double, double* %10
%70 = fadd double 1.000000e+00, %69
%71 = fdiv double 1.000000e+00, %70
%72 = fsub double 1.000000e+00, %71
store double %72, double* %8
%73 = load double, double* %5
%74 = call i64 @isinf(double %73)
%75 = icmp ne i64 %74, 0
br i1 %75, label %80, label %76
76: ; preds = %66
%77 = load double, double* %8
%78 = fcmp oeq double %77, 0.000000e+00
br i1 %78, label %79, label %80
79: ; preds = %76
store double 1.000000e-15, double* %8
br label %80
80: ; preds = %79, %76, %66
br label %81
81: ; preds = %80, %65
%82 = load double, double* %6
%83 = load double, double* %7
%84 = load double, double* %6
%85 = fsub double %83, %84
%86 = load double, double* %8
%87 = call double @llvm.fmuladd.f64(double %85, double %86, double %82)
store double %87, double* %4
br label %88
88: ; preds = %81, %44, %31, %18
%89 = load double, double* %4
ret double %89
}

LLVM IR (-O2):
define double @inverse_transform2(double %0, double %1, double %2) {
%4 = tail call i64 @isinf(double %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = tail call i64 @isinf(double %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = tail call double @exp(double %0)
%11 = fadd double %10, %1
br label %53
12: ; preds = %6, %3
%13 = tail call i64 @isinf(double %2)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %12
%16 = tail call i64 @isinf(double %1)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = tail call double @exp(double %0)
%20 = fsub double %2, %19
br label %53
21: ; preds = %15, %12
%22 = tail call i64 @isinf(double %2)
%23 = icmp eq i64 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = tail call i64 @isinf(double %1)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %53
27: ; preds = %24, %21
%28 = fcmp ogt double %0, 0.000000e+00
br i1 %28, label %29, label %39
29: ; preds = %27
%30 = fneg double %0
%31 = tail call double @exp(double %30)
%32 = fadd double %31, 1.000000e+00
%33 = fdiv double 1.000000e+00, %32
%34 = tail call i64 @isinf(double %0)
%35 = icmp eq i64 %34, 0
%36 = fcmp oeq double %33, 1.000000e+00
%37 = select i1 %35, i1 %36, i1 false
%38 = select i1 %37, double 0x3FEFFFFFFFFFFFF7, double %33
br label %49
39: ; preds = %27
%40 = tail call double @exp(double %0)
%41 = fadd double %40, 1.000000e+00
%42 = fdiv double 1.000000e+00, %41
%43 = fsub double 1.000000e+00, %42
%44 = tail call i64 @isinf(double %0)
%45 = icmp eq i64 %44, 0
%46 = fcmp oeq double %43, 0.000000e+00
%47 = select i1 %45, i1 %46, i1 false
%48 = select i1 %47, double 1.000000e-15, double %43
br label %49
49: ; preds = %39, %29
%50 = phi double [ %38, %29 ], [ %48, %39 ]
%51 = fsub double %2, %1
%52 = tail call double @llvm.fmuladd.f64(double %51, double %50, double %1)
br label %53
53: ; preds = %24, %49, %18, %9
%54 = phi double [ %52, %49 ], [ %20, %18 ], [ %11, %9 ], [ %0, %24 ]
ret double %54
}