#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 /*<<< orphan*/ remove(char *);
int mp_sqrt(int n, int radix, int in[], int out[], int tmp[], int nfft,
            double tmpfft[]) {
  void mp_load_0(int n, int radix, int out[]);
  int mp_get_nfft_init(int radix, int nfft_max);
  void mp_sqrt_init(int n, int radix, int in[], int out[], int out_rev[]);
  int mp_sqrt_newton(int n, int radix, int in[], int inout[], int inout_rev[],
                     char *f_name_tmp1, char *f_name_tmp2, int nfft,
                     double tmpfft[], char *f_name_tmp1fft, int *n_tmp1fft);
  int n_nwt, nfft_nwt, thr, prc, n_tmp1fft;
  char *f_name_tmp1fft = "tmp1fft.swp";
  char *f_name_tmp1 = "tmp1var.swp";
  char *f_name_tmp2 = "tmp2var.swp";
  if (in[0] < 0) {
    return -1;
  } else if (in[0] == 0) {
    mp_load_0(n, radix, out);
    return 0;
  }
  nfft_nwt = mp_get_nfft_init(radix, nfft);
  n_nwt = nfft_nwt + 2;
  if (n_nwt > n) {
    n_nwt = n;
  }
  mp_sqrt_init(n_nwt, radix, in, out, tmp);
  n_tmp1fft = 0;
  thr = 8;
  do {
    n_nwt = nfft_nwt + 2;
    if (n_nwt > n) {
      n_nwt = n;
    }
    prc = mp_sqrt_newton(n_nwt, radix, in, out, tmp, f_name_tmp1, f_name_tmp2,
                         nfft_nwt, tmpfft, f_name_tmp1fft, &n_tmp1fft);
    if (thr * nfft_nwt >= nfft) {
      thr = 0;
      if (2 * prc <= n_nwt - 2) {
        nfft_nwt >>= 1;
      }
    } else {
      if (3 * prc < n_nwt - 2) {
        nfft_nwt >>= 1;
      }
    }
    nfft_nwt <<= 1;
  } while (nfft_nwt <= nfft);
  remove(f_name_tmp1fft);
  remove(f_name_tmp1);
  remove(f_name_tmp2);
  return 0;
}


x86 assembly (clang, -O0):
<mp_sqrt>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    0x10(%rbp),%rax
mov    %edi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %rcx,-0x30(%rbp)
mov    %r8,-0x38(%rbp)
mov    %r9d,-0x3c(%rbp)
lea    0xe81(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    0xe82(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0xe83(%rip),%rax
mov    %rax,-0x68(%rbp)
mov    -0x28(%rbp),%rax
cmpl   $0x0,(%rax)
jge    11b2 <mp_sqrt+0x62>
movl   $0xffffffff,-0x14(%rbp)
jmp    1320 <mp_sqrt+0x1d0>
mov    -0x28(%rbp),%rax
cmpl   $0x0,(%rax)
jne    11da <mp_sqrt+0x8a>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x30(%rbp),%rdx
call   1070 <mp_load_0@plt>
movl   $0x0,-0x14(%rbp)
jmp    1320 <mp_sqrt+0x1d0>
jmp    11df <mp_sqrt+0x8f>
mov    -0x1c(%rbp),%edi
mov    -0x3c(%rbp),%esi
call   1050 <mp_get_nfft_init@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1208 <mp_sqrt+0xb8>
mov    -0x18(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
call   1060 <mp_sqrt_init@plt>
movl   $0x0,-0x50(%rbp)
movl   $0x8,-0x48(%rbp)
mov    -0x44(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1248 <mp_sqrt+0xf8>
mov    -0x18(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    -0x60(%rbp),%r9
mov    -0x68(%rbp),%r14
mov    -0x44(%rbp),%ebx
mov    0x10(%rbp),%r11
mov    -0x58(%rbp),%r10
lea    -0x50(%rbp),%rax
mov    %r14,(%rsp)
mov    %ebx,0x8(%rsp)
mov    %r11,0x10(%rsp)
mov    %r10,0x18(%rsp)
mov    %rax,0x20(%rsp)
call   1040 <mp_sqrt_newton@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x48(%rbp),%eax
imul   -0x44(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jl     12c9 <mp_sqrt+0x179>
movl   $0x0,-0x48(%rbp)
mov    -0x4c(%rbp),%eax
shl    $0x1,%eax
mov    -0x40(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jg     12c4 <mp_sqrt+0x174>
mov    -0x44(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    12e9 <mp_sqrt+0x199>
imul   $0x3,-0x4c(%rbp),%eax
mov    -0x40(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    12e4 <mp_sqrt+0x194>
mov    -0x44(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    12e9 <mp_sqrt+0x199>
mov    -0x44(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jle    122d <mp_sqrt+0xdd>
mov    -0x58(%rbp),%rdi
call   1030 <remove@plt>
mov    -0x60(%rbp),%rdi
call   1030 <remove@plt>
mov    -0x68(%rbp),%rdi
call   1030 <remove@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<mp_sqrt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,0x20(%rsp)
mov    %rcx,0x10(%rsp)
mov    %esi,0xc(%rsp)
cmpl   $0x0,(%rdx)
js     1279 <mp_sqrt+0x129>
mov    %edi,%ebx
je     1280 <mp_sqrt+0x130>
mov    %r9d,%ebp
mov    %rdx,%r13
mov    0xc(%rsp),%r15d
mov    %r15d,%edi
mov    %r9d,%esi
call   1050 <mp_get_nfft_init@plt>
mov    %eax,%r14d
lea    0x2(%r14),%edi
cmp    %ebx,%edi
cmovg  %ebx,%edi
mov    %r15d,%esi
mov    %r13,%rdx
mov    0x10(%rsp),%rcx
mov    0x20(%rsp),%r8
call   1060 <mp_sqrt_init@plt>
movl   $0x0,0x1c(%rsp)
mov    $0x8,%r12d
jmp    11e8 <mp_sqrt+0x98>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%rax,%rax,2),%eax
add    $0xfffffffe,%r15d
cmp    %r15d,%eax
setl   %cl
sar    %cl,%r14d
add    %r14d,%r14d
cmp    %ebp,%r14d
jg     1253 <mp_sqrt+0x103>
lea    0x2(%r14),%r15d
cmp    %ebx,%r15d
cmovg  %ebx,%r15d
sub    $0x8,%rsp
mov    %r15d,%edi
mov    0x14(%rsp),%esi
mov    %r13,%rdx
mov    0x18(%rsp),%rcx
mov    0x28(%rsp),%r8
lea    0xdfa(%rip),%r9
lea    0x24(%rsp),%rax
push   %rax
lea    0xde1(%rip),%rax
push   %rax
push   0x78(%rsp)
push   %r14
lea    0xdeb(%rip),%rax
push   %rax
call   1040 <mp_sqrt_newton@plt>
add    $0x30,%rsp
mov    %r14d,%ecx
imul   %r12d,%ecx
cmp    %ebp,%ecx
jl     11d0 <mp_sqrt+0x80>
add    %eax,%eax
add    $0xfffffffe,%r15d
cmp    %r15d,%eax
setle  %cl
xor    %r12d,%r12d
jmp    11dd <mp_sqrt+0x8d>
lea    0xda6(%rip),%rdi
call   1030 <remove@plt>
lea    0xda6(%rip),%rdi
call   1030 <remove@plt>
lea    0xda6(%rip),%rdi
call   1030 <remove@plt>
jmp    1290 <mp_sqrt+0x140>
mov    $0xffffffff,%eax
jmp    1292 <mp_sqrt+0x142>
mov    %ebx,%edi
mov    0xc(%rsp),%esi
mov    0x10(%rsp),%rdx
call   1070 <mp_load_0@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"tmp1fft.swp\00"
@.str.1 = [12 x i8] c"tmp1var.swp\00"
@.str.2 = [12 x i8] c"tmp2var.swp\00"
define i32 @mp_sqrt(i32 %0, i32 %1, i32* %2, i32* %3, i32* %4, i32 %5, double* %6) {
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca double*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i8*
%22 = alloca i8*
%23 = alloca i8*
store i32 %0, i32* %9
store i32 %1, i32* %10
store i32* %2, i32** %11
store i32* %3, i32** %12
store i32* %4, i32** %13
store i32 %5, i32* %14
store double* %6, double** %15
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %21
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8** %22
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8** %23
%24 = load i32*, i32** %11
%25 = getelementptr inbounds i32, i32* %24, i64 0
%26 = load i32, i32* %25
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %7
store i32 -1, i32* %8
br label %115
29: ; preds = %7
%30 = load i32*, i32** %11
%31 = getelementptr inbounds i32, i32* %30, i64 0
%32 = load i32, i32* %31
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = load i32, i32* %9
%36 = load i32, i32* %10
%37 = load i32*, i32** %12
store i32 0, i32* %8
br label %115
38: ; preds = %29
br label %39
39: ; preds = %38
%40 = load i32, i32* %10
%41 = load i32, i32* %14
%42 = call i32 @mp_get_nfft_init(i32 %40, i32 %41)
store i32 %42, i32* %17
%43 = load i32, i32* %17
%44 = add nsw i32 %43, 2
store i32 %44, i32* %16
%45 = load i32, i32* %16
%46 = load i32, i32* %9
%47 = icmp sgt i32 %45, %46
br i1 %47, label %48, label %50
48: ; preds = %39
%49 = load i32, i32* %9
store i32 %49, i32* %16
br label %50
50: ; preds = %48, %39
%51 = load i32, i32* %16
%52 = load i32, i32* %10
%53 = load i32*, i32** %11
%54 = load i32*, i32** %12
%55 = load i32*, i32** %13
store i32 0, i32* %20
store i32 8, i32* %18
br label %56
56: ; preds = %104, %50
%57 = load i32, i32* %17
%58 = add nsw i32 %57, 2
store i32 %58, i32* %16
%59 = load i32, i32* %16
%60 = load i32, i32* %9
%61 = icmp sgt i32 %59, %60
br i1 %61, label %62, label %64
62: ; preds = %56
%63 = load i32, i32* %9
store i32 %63, i32* %16
br label %64
64: ; preds = %62, %56
%65 = load i32, i32* %16
%66 = load i32, i32* %10
%67 = load i32*, i32** %11
%68 = load i32*, i32** %12
%69 = load i32*, i32** %13
%70 = load i8*, i8** %22
%71 = load i8*, i8** %23
%72 = load i32, i32* %17
%73 = load double*, double** %15
%74 = load i8*, i8** %21
%75 = call i32 @mp_sqrt_newton(i32 %65, i32 %66, i32* %67, i32* %68, i32* %69, i8* %70, i8* %71, i32 %72, double* %73, i8* %74, i32* %20)
store i32 %75, i32* %19
%76 = load i32, i32* %18
%77 = load i32, i32* %17
%78 = mul nsw i32 %76, %77
%79 = load i32, i32* %14
%80 = icmp sge i32 %78, %79
br i1 %80, label %81, label %91
81: ; preds = %64
store i32 0, i32* %18
%82 = load i32, i32* %19
%83 = mul nsw i32 2, %82
%84 = load i32, i32* %16
%85 = sub nsw i32 %84, 2
%86 = icmp sle i32 %83, %85
br i1 %86, label %87, label %90
87: ; preds = %81
%88 = load i32, i32* %17
%89 = ashr i32 %88, 1
store i32 %89, i32* %17
br label %90
90: ; preds = %87, %81
br label %101
91: ; preds = %64
%92 = load i32, i32* %19
%93 = mul nsw i32 3, %92
%94 = load i32, i32* %16
%95 = sub nsw i32 %94, 2
%96 = icmp slt i32 %93, %95
br i1 %96, label %97, label %100
97: ; preds = %91
%98 = load i32, i32* %17
%99 = ashr i32 %98, 1
store i32 %99, i32* %17
br label %100
100: ; preds = %97, %91
br label %101
101: ; preds = %100, %90
%102 = load i32, i32* %17
%103 = shl i32 %102, 1
store i32 %103, i32* %17
br label %104
104: ; preds = %101
%105 = load i32, i32* %17
%106 = load i32, i32* %14
%107 = icmp sle i32 %105, %106
br i1 %107, label %56, label %108
108: ; preds = %104
%109 = load i8*, i8** %21
%110 = call i32 @remove(i8* %109)
%111 = load i8*, i8** %22
%112 = call i32 @remove(i8* %111)
%113 = load i8*, i8** %23
%114 = call i32 @remove(i8* %113)
store i32 0, i32* %8
br label %115
115: ; preds = %108, %34, %28
%116 = load i32, i32* %8
ret i32 %116
}

LLVM IR (-O2):
@.str = [12 x i8] c"tmp1fft.swp\00"
@.str.1 = [12 x i8] c"tmp1var.swp\00"
@.str.2 = [12 x i8] c"tmp2var.swp\00"
define i32 @mp_sqrt(i32 %0, i32 %1, i32* %2, i32* %3, i32* %4, i32 %5, double* %6) {
%8 = alloca i32
%9 = bitcast i32* %8 to i8*
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 0
br i1 %11, label %48, label %12
12: ; preds = %7
%13 = icmp eq i32 %10, 0
br i1 %13, label %14, label %15
14: ; preds = %12
tail call void @mp_load_0(i32 %0, i32 %1, i32* %3)
br label %48
15: ; preds = %12
%16 = tail call i32 @mp_get_nfft_init(i32 %1, i32 %5)
%17 = add nsw i32 %16, 2
%18 = icmp sgt i32 %17, %0
%19 = select i1 %18, i32 %0, i32 %17
tail call void @mp_sqrt_init(i32 %19, i32 %1, i32* %2, i32* %3, i32* %4)
store i32 0, i32* %8
br label %20
20: ; preds = %37, %15
%21 = phi i32 [ 8, %15 ], [ %38, %37 ]
%22 = phi i32 [ %16, %15 ], [ %42, %37 ]
%23 = add nsw i32 %22, 2
%24 = icmp sgt i32 %23, %0
%25 = select i1 %24, i32 %0, i32 %23
%26 = call i32 @mp_sqrt_newton(i32 %25, i32 %1, i32* %2, i32* %3, i32* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %22, double* %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %8)
%27 = mul nsw i32 %22, %21
%28 = icmp slt i32 %27, %5
br i1 %28, label %33, label %29
29: ; preds = %20
%30 = shl nsw i32 %26, 1
%31 = add nsw i32 %25, -2
%32 = icmp sle i32 %30, %31
br label %37
33: ; preds = %20
%34 = mul nsw i32 %26, 3
%35 = add nsw i32 %25, -2
%36 = icmp slt i32 %34, %35
br label %37
37: ; preds = %33, %29
%38 = phi i32 [ 0, %29 ], [ %21, %33 ]
%39 = phi i1 [ %32, %29 ], [ %36, %33 ]
%40 = zext i1 %39 to i32
%41 = ashr i32 %22, %40
%42 = shl i32 %41, 1
%43 = icmp sgt i32 %42, %5
br i1 %43, label %44, label %20
44: ; preds = %37
%45 = call i32 @remove(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%46 = call i32 @remove(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%47 = call i32 @remove(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %48
48: ; preds = %7, %44, %14
%49 = phi i32 [ 0, %14 ], [ 0, %44 ], [ -1, %7 ]
ret i32 %49
}