#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 pow(double, int);
double grad_inverse_transform(double z, double lb, double ub) {
  if (!isinf(lb) && isinf(ub)) {
    return exp(z);
  } else if (!isinf(ub) && isinf(lb)) {
    return -exp(z);
  } else if (isinf(ub) && isinf(lb)) {
    return 1.0;
  }
  double inv_logit_x;
  if (z > 0) {
    double exp_minus_x = exp(-z);
    inv_logit_x = exp_minus_x / pow((1.0 + exp_minus_x), 2);
  } else {
    double exp_x = exp(z);
    inv_logit_x = exp_x / pow((1.0 + exp_x), 2);
  }
  return (ub - lb) * inv_logit_x;
}


x86 assembly (clang, -O0):
<grad_inverse_transform>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <isinf@plt>
cmp    $0x0,%rax
jne    1183 <grad_inverse_transform+0x53>
movsd  -0x20(%rbp),%xmm0
call   1050 <isinf@plt>
cmp    $0x0,%rax
je     1183 <grad_inverse_transform+0x53>
movsd  -0x10(%rbp),%xmm0
call   1030 <exp@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    12de <grad_inverse_transform+0x1ae>
movsd  -0x20(%rbp),%xmm0
call   1050 <isinf@plt>
cmp    $0x0,%rax
jne    11d6 <grad_inverse_transform+0xa6>
movsd  -0x18(%rbp),%xmm0
call   1050 <isinf@plt>
cmp    $0x0,%rax
je     11d6 <grad_inverse_transform+0xa6>
movsd  -0x10(%rbp),%xmm0
call   1030 <exp@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12de <grad_inverse_transform+0x1ae>
movsd  -0x20(%rbp),%xmm0
call   1050 <isinf@plt>
cmp    $0x0,%rax
je     1210 <grad_inverse_transform+0xe0>
movsd  -0x18(%rbp),%xmm0
call   1050 <isinf@plt>
cmp    $0x0,%rax
je     1210 <grad_inverse_transform+0xe0>
movsd  0xdfa(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12de <grad_inverse_transform+0x1ae>
jmp    1215 <grad_inverse_transform+0xe5>
jmp    121a <grad_inverse_transform+0xea>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1289 <grad_inverse_transform+0x159>
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  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xd9c(%rip),%xmm0
addsd  -0x30(%rbp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    12ca <grad_inverse_transform+0x19a>
movsd  -0x10(%rbp),%xmm0
call   1030 <exp@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xd56(%rip),%xmm0
addsd  -0x38(%rbp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grad_inverse_transform>:
sub    $0x38,%rsp
movaps %xmm2,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movsd  %xmm1,0x8(%rsp)
movaps %xmm1,%xmm0
call   1050 <isinf@plt>
test   %rax,%rax
je     1191 <grad_inverse_transform+0x61>
movaps 0x20(%rsp),%xmm0
call   1050 <isinf@plt>
test   %rax,%rax
je     1219 <grad_inverse_transform+0xe9>
movapd 0x20(%rsp),%xmm0
call   1050 <isinf@plt>
test   %rax,%rax
je     11ae <grad_inverse_transform+0x7e>
movsd  0x8(%rsp),%xmm0
call   1050 <isinf@plt>
test   %rax,%rax
je     11ae <grad_inverse_transform+0x7e>
movsd  0xe84(%rip),%xmm0
add    $0x38,%rsp
ret
movaps 0x20(%rsp),%xmm0
call   1050 <isinf@plt>
test   %rax,%rax
je     1151 <grad_inverse_transform+0x21>
movaps 0x10(%rsp),%xmm0
add    $0x38,%rsp
jmp    1030 <exp@plt>
movapd 0xe4a(%rip),%xmm1
movapd 0x10(%rsp),%xmm2
xorpd  %xmm2,%xmm1
xorpd  %xmm0,%xmm0
cmpltsd %xmm2,%xmm0
andpd  %xmm0,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
call   1030 <exp@plt>
movapd %xmm0,%xmm1
movsd  %xmm0,0x10(%rsp)
movsd  0xe24(%rip),%xmm0
addsd  %xmm1,%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd 0x20(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
mulsd  %xmm1,%xmm0
add    $0x38,%rsp
ret
movsd  0x8(%rsp),%xmm0
call   1050 <isinf@plt>
test   %rax,%rax
je     1164 <grad_inverse_transform+0x34>
movaps 0x10(%rsp),%xmm0
call   1030 <exp@plt>
xorps  0xdc2(%rip),%xmm0
add    $0x38,%rsp
ret

LLVM IR (-O0):
define double @grad_inverse_transform(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 %21, 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 %21
18: ; preds = %14
%19 = load double, double* %5
%20 = call double @exp(double %19)
store double %20, double* %4
br label %70
21: ; preds = %14, %3
%22 = load double, double* %7
%23 = call i64 @isinf(double %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %33, label %25
25: ; preds = %21
%26 = load double, double* %6
%27 = call i64 @isinf(double %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load double, double* %5
%31 = call double @exp(double %30)
%32 = fneg double %31
store double %32, double* %4
br label %70
33: ; preds = %25, %21
%34 = load double, double* %7
%35 = call i64 @isinf(double %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %33
%38 = load double, double* %6
%39 = call i64 @isinf(double %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %37
store double 1.000000e+00, double* %4
br label %70
42: ; preds = %37, %33
br label %43
43: ; preds = %42
br label %44
44: ; preds = %43
%45 = load double, double* %5
%46 = fcmp ogt double %45, 0.000000e+00
br i1 %46, label %47, label %56
47: ; preds = %44
%48 = load double, double* %5
%49 = fneg double %48
%50 = call double @exp(double %49)
store double %50, double* %9
%51 = load double, double* %9
%52 = load double, double* %9
%53 = fadd double 1.000000e+00, %52
%54 = call double @pow(double %53, i32 2)
%55 = fdiv double %51, %54
store double %55, double* %8
br label %64
56: ; preds = %44
%57 = load double, double* %5
%58 = call double @exp(double %57)
store double %58, double* %10
%59 = load double, double* %10
%60 = load double, double* %10
%61 = fadd double 1.000000e+00, %60
%62 = call double @pow(double %61, i32 2)
%63 = fdiv double %59, %62
store double %63, double* %8
br label %64
64: ; preds = %56, %47
%65 = load double, double* %7
%66 = load double, double* %6
%67 = fsub double %65, %66
%68 = load double, double* %8
%69 = fmul double %67, %68
store double %69, double* %4
br label %70
70: ; preds = %64, %41, %29, %18
%71 = load double, double* %4
ret double %71
}

LLVM IR (-O2):
define double @grad_inverse_transform(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 %11
6: ; preds = %3
%7 = tail call i64 @isinf(double %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call double @exp(double %0)
br label %36
11: ; preds = %6, %3
%12 = tail call i64 @isinf(double %2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = tail call i64 @isinf(double %1)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = tail call double @exp(double %0)
%19 = fneg double %18
br label %36
20: ; preds = %14, %11
%21 = tail call i64 @isinf(double %2)
%22 = icmp eq i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = tail call i64 @isinf(double %1)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %36
26: ; preds = %23, %20
%27 = fcmp ogt double %0, 0.000000e+00
%28 = fneg double %0
%29 = select i1 %27, double %28, double %0
%30 = tail call double @exp(double %29)
%31 = fadd double %30, 1.000000e+00
%32 = tail call double @pow(double %31, i32 2)
%33 = fdiv double %30, %32
%34 = fsub double %2, %1
%35 = fmul double %34, %33
br label %36
36: ; preds = %23, %26, %17, %9
%37 = phi double [ %35, %26 ], [ %19, %17 ], [ %10, %9 ], [ 1.000000e+00, %23 ]
ret double %37
}