#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 pow(int, int);
int CalculateEscSequence(int input, int *len_esc_sequence) {
  float x, y;
  int output;
  int N;
  N = -1;
  y = (float)((input) < 0 ? (-input) : (input));
  x = y / 16;
  while (x >= 1) {
    N++;
    x = x / 2;
  }
  *len_esc_sequence = 2 * N + 5;
  output = (int)((pow(2, N) - 1) * pow(2, N + 5) + y - pow(2, N + 4));
  return (output);
}


x86 assembly (clang, -O0):
<CalculateEscSequence>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x20(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    113d <CalculateEscSequence+0x2d>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1143 <CalculateEscSequence+0x33>
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
movss  0xea4(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
movss  0xe92(%rip),%xmm1
ucomiss %xmm1,%xmm0
jb     119f <CalculateEscSequence+0x8f>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
movss  -0x14(%rbp),%xmm0
movss  0xe77(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    1165 <CalculateEscSequence+0x55>
mov    -0x20(%rbp),%ecx
shl    $0x1,%ecx
add    $0x5,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%esi
mov    $0x2,%edi
call   1030 <pow@plt>
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%esi
add    $0x5,%esi
mov    $0x2,%edi
call   1030 <pow@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
imul   %ecx,%eax
cvtsi2ss %eax,%xmm0
addss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%esi
add    $0x4,%esi
mov    $0x2,%edi
call   1030 <pow@plt>
movss  -0x28(%rbp),%xmm0
cvtsi2ss %eax,%xmm1
subss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CalculateEscSequence>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%eax
neg    %eax
cmovs  %edi,%eax
cvtsi2ss %eax,%xmm1
movss  0xeda(%rip),%xmm0
movss  %xmm1,0x4(%rsp)
mulss  %xmm1,%xmm0
mov    $0xffffffff,%ebx
ucomiss 0xec8(%rip),%xmm0
jb     116c <CalculateEscSequence+0x5c>
mov    $0xffffffff,%ebx
movss  0xebd(%rip),%xmm1
movss  0xeb1(%rip),%xmm2
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebx
mulss  %xmm1,%xmm0
ucomiss %xmm2,%xmm0
jae    1160 <CalculateEscSequence+0x50>
lea    (%rbx,%rbx,1),%eax
add    $0x5,%eax
mov    %eax,(%rsi)
mov    $0x2,%edi
mov    %ebx,%esi
call   1030 <pow@plt>
mov    %eax,%ebp
add    $0xffffffff,%ebp
lea    0x5(%rbx),%esi
mov    $0x2,%edi
call   1030 <pow@plt>
imul   %ebp,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  0x4(%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,0x4(%rsp)
add    $0x4,%ebx
mov    $0x2,%edi
mov    %ebx,%esi
call   1030 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  0x4(%rsp),%xmm1
subss  %xmm0,%xmm1
cvttss2si %xmm1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @CalculateEscSequence(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca float
%6 = alloca float
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
store i32 -1, i32* %8
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* %3
%13 = sub nsw i32 0, %12
br label %16
14: ; preds = %2
%15 = load i32, i32* %3
br label %16
16: ; preds = %14, %11
%17 = phi i32 [ %13, %11 ], [ %15, %14 ]
%18 = sitofp i32 %17 to float
store float %18, float* %6
%19 = load float, float* %6
%20 = fdiv float %19, 1.600000e+01
store float %20, float* %5
br label %21
21: ; preds = %24, %16
%22 = load float, float* %5
%23 = fcmp oge float %22, 1.000000e+00
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = load i32, i32* %8
%26 = add nsw i32 %25, 1
store i32 %26, i32* %8
%27 = load float, float* %5
%28 = fdiv float %27, 2.000000e+00
store float %28, float* %5
br label %21
29: ; preds = %21
%30 = load i32, i32* %8
%31 = mul nsw i32 2, %30
%32 = add nsw i32 %31, 5
%33 = load i32*, i32** %4
store i32 %32, i32* %33
%34 = load i32, i32* %8
%35 = call i32 @pow(i32 2, i32 %34)
%36 = sub nsw i32 %35, 1
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 5
%39 = call i32 @pow(i32 2, i32 %38)
%40 = mul nsw i32 %36, %39
%41 = sitofp i32 %40 to float
%42 = load float, float* %6
%43 = fadd float %41, %42
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 4
%46 = call i32 @pow(i32 2, i32 %45)
%47 = sitofp i32 %46 to float
%48 = fsub float %43, %47
%49 = fptosi float %48 to i32
store i32 %49, i32* %7
%50 = load i32, i32* %7
ret i32 %50
}

LLVM IR (-O2):
define i32 @CalculateEscSequence(i32 %0, i32* nocapture writeonly %1) {
%3 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
%4 = sitofp i32 %3 to float
%5 = fmul float %4, 6.250000e-02
%6 = fcmp ult float %5, 1.000000e+00
br i1 %6, label %13, label %7
7: ; preds = %2, %7
%8 = phi i32 [ %10, %7 ], [ -1, %2 ]
%9 = phi float [ %11, %7 ], [ %5, %2 ]
%10 = add nsw i32 %8, 1
%11 = fmul float %9, 5.000000e-01
%12 = fcmp ult float %11, 1.000000e+00
br i1 %12, label %13, label %7
13: ; preds = %7, %2
%14 = phi i32 [ -1, %2 ], [ %10, %7 ]
%15 = shl nsw i32 %14, 1
%16 = add nsw i32 %15, 5
store i32 %16, i32* %1
%17 = tail call i32 @pow(i32 2, i32 %14)
%18 = add nsw i32 %17, -1
%19 = add nsw i32 %14, 5
%20 = tail call i32 @pow(i32 2, i32 %19)
%21 = mul nsw i32 %18, %20
%22 = sitofp i32 %21 to float
%23 = fadd float %4, %22
%24 = add nsw i32 %14, 4
%25 = tail call i32 @pow(i32 2, i32 %24)
%26 = sitofp i32 %25 to float
%27 = fsub float %23, %26
%28 = fptosi float %27 to i32
ret i32 %28
}