#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 M_PI;
float calculateMaxReadoutGradientAmplitude(float, float);
int fabs(float);
int sqrt(int);
void ccr_calcGT(float gradientLimit, float slewRateLimit, float kR,
                float fieldOfView, float T, float *G0, float *T0) {
  float T_halfsine0;
  float readoutGradientLimit =
      calculateMaxReadoutGradientAmplitude(fieldOfView, T);
  float Gmax =
      (((readoutGradientLimit) < (gradientLimit)) ? (readoutGradientLimit)
                                                  : (gradientLimit));
  float A = 2 * kR;
  if (fabs(A / 4257.6388f) < 2 * Gmax * Gmax / slewRateLimit)
    T_halfsine0 = M_PI * sqrt(fabs(A / 4257.6388f) / 2 / slewRateLimit);
  else
    T_halfsine0 = M_PI * fabs(A / 4257.6388f) / 2 / Gmax;
  *G0 = M_PI * fabs(A / 4257.6388f) / 2 / T_halfsine0;
  *T0 = 2 * T_halfsine0;
  return;
}


x86 assembly (clang, -O0):
<ccr_calcGT>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  %xmm3,-0x10(%rbp)
movss  %xmm4,-0x14(%rbp)
mov    %rdi,-0x20(%rbp)
mov    %rsi,-0x28(%rbp)
movss  -0x10(%rbp),%xmm0
movss  -0x14(%rbp),%xmm1
call   1050 <calculateMaxReadoutGradientAmplitude@plt>
movss  %xmm0,-0x30(%rbp)
movss  -0x30(%rbp),%xmm1
movss  -0x4(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    118f <ccr_calcGT+0x5f>
movss  -0x30(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
jmp    1199 <ccr_calcGT+0x69>
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x3c(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  0xe55(%rip),%xmm0
mulss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x38(%rbp)
movss  -0x38(%rbp),%xmm0
movss  0xe42(%rip),%xmm1
divss  %xmm1,%xmm0
call   1030 <fabs@plt>
cvtsi2ss %eax,%xmm1
movss  0xe29(%rip),%xmm0
mulss  -0x34(%rbp),%xmm0
mulss  -0x34(%rbp),%xmm0
divss  -0x8(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    1241 <ccr_calcGT+0x111>
mov    0x2df2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
movss  -0x38(%rbp),%xmm0
movss  0xdfc(%rip),%xmm1
divss  %xmm1,%xmm0
call   1030 <fabs@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm0
divss  -0x8(%rbp),%xmm0
cvttss2si %xmm0,%edi
call   1040 <sqrt@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
imul   %ecx,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x2c(%rbp)
jmp    1281 <ccr_calcGT+0x151>
mov    0x2da0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
movss  -0x38(%rbp),%xmm0
movss  0xdaa(%rip),%xmm1
divss  %xmm1,%xmm0
call   1030 <fabs@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
imul   %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm0
divss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    0x2d60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
movss  -0x38(%rbp),%xmm0
movss  0xd6a(%rip),%xmm1
divss  %xmm1,%xmm0
call   1030 <fabs@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%eax
imul   %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm0
divss  -0x2c(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movss  %xmm0,(%rax)
movss  0xd34(%rip),%xmm0
mulss  -0x2c(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movss  %xmm0,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ccr_calcGT>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movss  %xmm2,0xc(%rsp)
movss  %xmm1,0x4(%rsp)
movss  %xmm0,0x8(%rsp)
movaps %xmm3,%xmm0
movaps %xmm4,%xmm1
call   1050 <calculateMaxReadoutGradientAmplitude@plt>
minss  0x8(%rsp),%xmm0
movss  %xmm0,0x8(%rsp)
movss  0xc(%rsp),%xmm0
addss  %xmm0,%xmm0
divss  0xe85(%rip),%xmm0
movss  %xmm0,0xc(%rsp)
call   1030 <fabs@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,0x14(%rsp)
movss  0x8(%rsp),%xmm0
movaps %xmm0,%xmm1
addss  %xmm0,%xmm1
mulss  %xmm0,%xmm1
divss  0x4(%rsp),%xmm1
movss  %xmm1,0x10(%rsp)
mov    0x2e31(%rip),%rbx
mov    (%rbx),%ebp
movss  0xc(%rsp),%xmm0
call   1030 <fabs@plt>
movss  0x10(%rsp),%xmm0
ucomiss 0x14(%rsp),%xmm0
jbe    11fc <ccr_calcGT+0xcc>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
xorps  %xmm0,%xmm0
cvtsi2ss %ecx,%xmm0
divss  0x4(%rsp),%xmm0
cvttss2si %xmm0,%edi
call   1040 <sqrt@plt>
imul   %ebp,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
jmp    1215 <ccr_calcGT+0xe5>
imul   %ebp,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
xorps  %xmm0,%xmm0
cvtsi2ss %ecx,%xmm0
divss  0x8(%rsp),%xmm0
movss  %xmm0,0x4(%rsp)
mov    (%rbx),%ebx
movss  0xc(%rsp),%xmm0
call   1030 <fabs@plt>
imul   %ebx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
xorps  %xmm0,%xmm0
cvtsi2ss %ecx,%xmm0
movss  0x4(%rsp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,(%r15)
addss  %xmm1,%xmm1
movss  %xmm1,(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@M_PI = global i32 0
define void @ccr_calcGT(float %0, float %1, float %2, float %3, float %4, float* %5, float* %6) {
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca float
%13 = alloca float*
%14 = alloca float*
%15 = alloca float
%16 = alloca float
%17 = alloca float
%18 = alloca float
store float %0, float* %8
store float %1, float* %9
store float %2, float* %10
store float %3, float* %11
store float %4, float* %12
store float* %5, float** %13
store float* %6, float** %14
%19 = load float, float* %11
%20 = load float, float* %12
%21 = call float @calculateMaxReadoutGradientAmplitude(float %19, float %20)
store float %21, float* %16
%22 = load float, float* %16
%23 = load float, float* %8
%24 = fcmp olt float %22, %23
br i1 %24, label %25, label %27
25: ; preds = %7
%26 = load float, float* %16
br label %29
27: ; preds = %7
%28 = load float, float* %8
br label %29
29: ; preds = %27, %25
%30 = phi float [ %26, %25 ], [ %28, %27 ]
store float %30, float* %17
%31 = load float, float* %10
%32 = fmul float 2.000000e+00, %31
store float %32, float* %18
%33 = load float, float* %18
%34 = fdiv float %33, 0x40B0A1A380000000
%35 = call i32 @fabs(float %34)
%36 = sitofp i32 %35 to float
%37 = load float, float* %17
%38 = fmul float 2.000000e+00, %37
%39 = load float, float* %17
%40 = fmul float %38, %39
%41 = load float, float* %9
%42 = fdiv float %40, %41
%43 = fcmp olt float %36, %42
br i1 %43, label %44, label %57
44: ; preds = %29
%45 = load i32, i32* @M_PI
%46 = load float, float* %18
%47 = fdiv float %46, 0x40B0A1A380000000
%48 = call i32 @fabs(float %47)
%49 = sdiv i32 %48, 2
%50 = sitofp i32 %49 to float
%51 = load float, float* %9
%52 = fdiv float %50, %51
%53 = fptosi float %52 to i32
%54 = call i32 @sqrt(i32 %53)
%55 = mul nsw i32 %45, %54
%56 = sitofp i32 %55 to float
store float %56, float* %15
br label %67
57: ; preds = %29
%58 = load i32, i32* @M_PI
%59 = load float, float* %18
%60 = fdiv float %59, 0x40B0A1A380000000
%61 = call i32 @fabs(float %60)
%62 = mul nsw i32 %58, %61
%63 = sdiv i32 %62, 2
%64 = sitofp i32 %63 to float
%65 = load float, float* %17
%66 = fdiv float %64, %65
store float %66, float* %15
br label %67
67: ; preds = %57, %44
%68 = load i32, i32* @M_PI
%69 = load float, float* %18
%70 = fdiv float %69, 0x40B0A1A380000000
%71 = call i32 @fabs(float %70)
%72 = mul nsw i32 %68, %71
%73 = sdiv i32 %72, 2
%74 = sitofp i32 %73 to float
%75 = load float, float* %15
%76 = fdiv float %74, %75
%77 = load float*, float** %13
store float %76, float* %77
%78 = load float, float* %15
%79 = fmul float 2.000000e+00, %78
%80 = load float*, float** %14
store float %79, float* %80
ret void
}

LLVM IR (-O2):
@M_PI = global i32 0
define void @ccr_calcGT(float %0, float %1, float %2, float %3, float %4, float* nocapture writeonly %5, float* nocapture writeonly %6) {
%8 = tail call float @calculateMaxReadoutGradientAmplitude(float %3, float %4)
%9 = fcmp olt float %8, %0
%10 = select i1 %9, float %8, float %0
%11 = fmul float %2, 2.000000e+00
%12 = fdiv float %11, 0x40B0A1A380000000
%13 = tail call i32 @fabs(float %12)
%14 = sitofp i32 %13 to float
%15 = fmul float %10, 2.000000e+00
%16 = fmul float %10, %15
%17 = fdiv float %16, %1
%18 = fcmp ogt float %17, %14
%19 = load i32, i32* @M_PI
%20 = tail call i32 @fabs(float %12)
br i1 %18, label %21, label %29
21: ; preds = %7
%22 = sdiv i32 %20, 2
%23 = sitofp i32 %22 to float
%24 = fdiv float %23, %1
%25 = fptosi float %24 to i32
%26 = tail call i32 @sqrt(i32 %25)
%27 = mul nsw i32 %26, %19
%28 = sitofp i32 %27 to float
br label %34
29: ; preds = %7
%30 = mul nsw i32 %20, %19
%31 = sdiv i32 %30, 2
%32 = sitofp i32 %31 to float
%33 = fdiv float %32, %10
br label %34
34: ; preds = %29, %21
%35 = phi float [ %28, %21 ], [ %33, %29 ]
%36 = load i32, i32* @M_PI
%37 = tail call i32 @fabs(float %12)
%38 = mul nsw i32 %37, %36
%39 = sdiv i32 %38, 2
%40 = sitofp i32 %39 to float
%41 = fdiv float %40, %35
store float %41, float* %5
%42 = fmul float %35, 2.000000e+00
store float %42, float* %6
ret void
}