#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*/ printf(char *, ...);
int main(void) {
  int x, y, z;
  printf("#ifdef TFM_SMALL_SET\n"
         "/* computes x/R == x (mod N) via Montgomery Reduction */\n"
         "void fp_montgomery_reduce_small(fp_int *a, fp_int *m, fp_digit mp)\n"
         "{\n"
         "   fp_digit c[FP_SIZE], *_c, *tmpm, mu, cy;\n"
         "   int      oldused, x, y, pa;\n"
         "\n"
         "#if defined(USE_MEMSET)\n"
         "   /* now zero the buff */\n"
         "   memset(c, 0, sizeof c);\n"
         "#endif\n"
         "   pa = m->used;\n"
         "\n"
         "   /* copy the input */\n"
         "   oldused = a->used;\n"
         "   for (x = 0; x < oldused; x++) {\n"
         "       c[x] = a->dp[x];\n"
         "   }\n"
         "#if !defined(USE_MEMSET)\n"
         "   for (; x < 2*pa+3; x++) {\n"
         "       c[x] = 0;\n"
         "   }\n"
         "#endif\n"
         "   MONT_START;\n"
         "\n"
         "   switch (pa) {\n");
  for (x = 1; x <= 16; x++) {
    if (x > 16 && (x != 32 && x != 48 && x != 64))
      continue;
    if (x > 16)
      printf("#ifdef TFM_HUGE\n");
    printf("      case %d:\n", x);
    for (y = 0; y < x; y++) {
      printf("            x = %d; cy   = 0;\n"
             "            LOOP_START;\n"
             "            _c   = c + %d;\n"
             "            tmpm = m->dp;\n",
             y, y);
      printf("#ifdef INNERMUL8\n");
      for (z = 0; z + 8 <= x; z += 8) {
        printf("            INNERMUL8; _c += 8; tmpm += 8;\n");
      }
      for (; z < x; z++) {
        printf("            INNERMUL; ++_c;\n");
      }
      printf("#else\n");
      for (z = 0; z < x; z++) {
        printf("            INNERMUL; ++_c;\n");
      }
      printf("#endif\n");
      printf("            LOOP_END;\n"
             "            while (cy) {\n"
             "               PROPCARRY;\n"
             "               ++_c;\n"
             "            }\n");
    }
    printf("         break;\n");
    if (x > 16)
      printf("#endif /* TFM_HUGE */\n");
  }
  printf("  }\n"
         "  /* now copy out */\n"
         "  _c   = c + pa;\n"
         "  tmpm = a->dp;\n"
         "  for (x = 0; x < pa+1; x++) {\n"
         "     *tmpm++ = *_c++;\n"
         "  }\n"
         "\n"
         "  for (; x < oldused; x++)   {\n"
         "     *tmpm++ = 0;\n"
         "  }\n"
         "\n"
         "  MONT_FINI;\n"
         "\n"
         "  a->used = pa+1;\n"
         "  fp_clamp(a);\n"
         "\n"
         "  /* if A >= m then A = A - m */\n"
         "  if (fp_cmp_mag (a, m) != FP_LT) {\n"
         "    s_fp_sub (a, m, a);\n"
         "  }\n"
         "}\n\n#endif\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0x10,-0x8(%rbp)
jg     12c8 <main+0x1b8>
cmpl   $0x10,-0x8(%rbp)
jle    116b <main+0x5b>
cmpl   $0x20,-0x8(%rbp)
je     116b <main+0x5b>
cmpl   $0x30,-0x8(%rbp)
je     116b <main+0x5b>
cmpl   $0x40,-0x8(%rbp)
je     116b <main+0x5b>
jmp    12ba <main+0x1aa>
cmpl   $0x10,-0x8(%rbp)
jle    1183 <main+0x73>
lea    0x10ad(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0x10ad(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    128f <main+0x17f>
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0x1096(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0x10f4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x8,%eax
cmp    -0x8(%rbp),%eax
jg     11fb <main+0xeb>
lea    0x10e2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x10(%rbp)
jmp    11d0 <main+0xc0>
jmp    1200 <main+0xf0>
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1228 <main+0x118>
lea    0x10e1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1200 <main+0xf0>
lea    0x10e2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1265 <main+0x155>
lea    0x10a4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    123d <main+0x12d>
lea    0x127f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0x109e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    119b <main+0x8b>
lea    0x10ef(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x10,-0x8(%rbp)
jle    12b5 <main+0x1a5>
lea    0x10e8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ba <main+0x1aa>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1134 <main+0x24>
lea    0x10de(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xf4a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r15d
lea    0x1338(%rip),%r13
lea    0x134d(%rip),%r12
nopl   0x0(%rax,%rax,1)
lea    0xea9(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xe99(%rip),%rdi
mov    %ebp,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x1270(%rip),%rdi
call   1030 <puts@plt>
mov    $0x0,%r14d
cmp    $0x8,%r15d
jb     11c0 <main+0xa0>
xor    %r14d,%r14d
nopl   (%rax)
mov    %r14d,%ebx
mov    %r12,%rdi
call   1030 <puts@plt>
lea    0x8(%rbx),%r14d
add    $0x10,%ebx
cmp    %r15d,%ebx
jbe    11a0 <main+0x80>
cmp    %r15d,%r14d
jae    11d1 <main+0xb1>
nopl   0x0(%rax)
mov    %r13,%rdi
call   1030 <puts@plt>
add    $0x1,%r14d
cmp    %r14d,%r15d
jne    11c0 <main+0xa0>
lea    0x1232(%rip),%rdi
call   1030 <puts@plt>
mov    %r15d,%ebx
mov    %r13,%rdi
call   1030 <puts@plt>
add    $0xffffffff,%ebx
jne    11e0 <main+0xc0>
lea    0x11ee(%rip),%rdi
call   1030 <puts@plt>
lea    0x1210(%rip),%rdi
call   1030 <puts@plt>
add    $0x1,%ebp
cmp    %r15d,%ebp
jne    1170 <main+0x50>
lea    0x11d1(%rip),%rdi
call   1030 <puts@plt>
add    $0x1,%r15d
cmp    $0x11,%r15d
jne    1150 <main+0x30>
lea    0x1072(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [553 x i8] c"#ifdef TFM_SMALL_SET\0A/* computes x/R == x (mod N) via Montgomery Reduction */\0Avoid fp_montgomery_reduce_small(fp_int *a, fp_int *m, fp_digit mp)\0A{\0A fp_digit c[FP_SIZE], *_c, *tmpm, mu, cy;\0A int oldused, x, y, pa;\0A\0A#if defined(USE_MEMSET)\0A /* now zero the buff */\0A memset(c, 0, sizeof c);\0A#endif\0A pa = m->used;\0A\0A /* copy the input */\0A oldused = a->used;\0A for (x = 0; x < oldused; x++) {\0A c[x] = a->dp[x];\0A }\0A#if !defined(USE_MEMSET)\0A for (; x < 2*pa+3; x++) {\0A c[x] = 0;\0A }\0A#endif\0A MONT_START;\0A\0A switch (pa) {\0A\00"
@.str.1 = [17 x i8] c"#ifdef TFM_HUGE\0A\00"
@.str.2 = [16 x i8] c" case %d:\0A\00"
@.str.3 = [108 x i8] c" x = %d; cy = 0;\0A LOOP_START;\0A _c = c + %d;\0A tmpm = m->dp;\0A\00"
@.str.4 = [18 x i8] c"#ifdef INNERMUL8\0A\00"
@.str.5 = [44 x i8] c" INNERMUL8; _c += 8; tmpm += 8;\0A\00"
@.str.6 = [29 x i8] c" INNERMUL; ++_c;\0A\00"
@.str.7 = [7 x i8] c"#else\0A\00"
@.str.8 = [8 x i8] c"#endif\0A\00"
@.str.9 = [109 x i8] c" LOOP_END;\0A while (cy) {\0A PROPCARRY;\0A ++_c;\0A }\0A\00"
@.str.10 = [17 x i8] c" break;\0A\00"
@.str.11 = [23 x i8] c"#endif /* TFM_HUGE */\0A\00"
@.str.12 = [326 x i8] c" }\0A /* now copy out */\0A _c = c + pa;\0A tmpm = a->dp;\0A for (x = 0; x < pa+1; x++) {\0A *tmpm++ = *_c++;\0A }\0A\0A for (; x < oldused; x++) {\0A *tmpm++ = 0;\0A }\0A\0A MONT_FINI;\0A\0A a->used = pa+1;\0A fp_clamp(a);\0A\0A /* if A >= m then A = A - m */\0A if (fp_cmp_mag (a, m) != FP_LT) {\0A s_fp_sub (a, m, a);\0A }\0A}\0A\0A#endif\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([553 x i8], [553 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %2
br label %6
6: ; preds = %83, %0
%7 = load i32, i32* %2
%8 = icmp sle i32 %7, 16
br i1 %8, label %9, label %86
9: ; preds = %6
%10 = load i32, i32* %2
%11 = icmp sgt i32 %10, 16
br i1 %11, label %12, label %22
12: ; preds = %9
%13 = load i32, i32* %2
%14 = icmp ne i32 %13, 32
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = load i32, i32* %2
%17 = icmp ne i32 %16, 48
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i32, i32* %2
%20 = icmp ne i32 %19, 64
br i1 %20, label %21, label %22
21: ; preds = %18
br label %83
22: ; preds = %18, %15, %12, %9
%23 = load i32, i32* %2
%24 = icmp sgt i32 %23, 16
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %22
%28 = load i32, i32* %2
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %28)
store i32 0, i32* %3
br label %30
30: ; preds = %73, %27
%31 = load i32, i32* %3
%32 = load i32, i32* %2
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %76
34: ; preds = %30
%35 = load i32, i32* %3
%36 = load i32, i32* %3
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([108 x i8], [108 x i8]* @.str.3, i64 0, i64 0), i32 %35, i32 %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %4
br label %39
39: ; preds = %46, %34
%40 = load i32, i32* %4
%41 = add nsw i32 %40, 8
%42 = load i32, i32* %2
%43 = icmp sle i32 %41, %42
br i1 %43, label %44, label %49
44: ; preds = %39
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0))
br label %46
46: ; preds = %44
%47 = load i32, i32* %4
%48 = add nsw i32 %47, 8
store i32 %48, i32* %4
br label %39
49: ; preds = %39
br label %50
50: ; preds = %56, %49
%51 = load i32, i32* %4
%52 = load i32, i32* %2
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %59
54: ; preds = %50
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
br label %56
56: ; preds = %54
%57 = load i32, i32* %4
%58 = add nsw i32 %57, 1
store i32 %58, i32* %4
br label %50
59: ; preds = %50
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %4
br label %61
61: ; preds = %67, %59
%62 = load i32, i32* %4
%63 = load i32, i32* %2
%64 = icmp slt i32 %62, %63
br i1 %64, label %65, label %70
65: ; preds = %61
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
br label %67
67: ; preds = %65
%68 = load i32, i32* %4
%69 = add nsw i32 %68, 1
store i32 %69, i32* %4
br label %61
70: ; preds = %61
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([109 x i8], [109 x i8]* @.str.9, i64 0, i64 0))
br label %73
73: ; preds = %70
%74 = load i32, i32* %3
%75 = add nsw i32 %74, 1
store i32 %75, i32* %3
br label %30
76: ; preds = %30
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0))
%78 = load i32, i32* %2
%79 = icmp sgt i32 %78, 16
br i1 %79, label %80, label %82
80: ; preds = %76
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.11, i64 0, i64 0))
br label %82
82: ; preds = %80, %76
br label %83
83: ; preds = %82, %21
%84 = load i32, i32* %2
%85 = add nsw i32 %84, 1
store i32 %85, i32* %2
br label %6
86: ; preds = %6
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([326 x i8], [326 x i8]* @.str.12, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [16 x i8] c" case %d:\0A\00"
@.str.3 = [108 x i8] c" x = %d; cy = 0;\0A LOOP_START;\0A _c = c + %d;\0A tmpm = m->dp;\0A\00"
@str = [552 x i8] c"#ifdef TFM_SMALL_SET\0A/* computes x/R == x (mod N) via Montgomery Reduction */\0Avoid fp_montgomery_reduce_small(fp_int *a, fp_int *m, fp_digit mp)\0A{\0A fp_digit c[FP_SIZE], *_c, *tmpm, mu, cy;\0A int oldused, x, y, pa;\0A\0A#if defined(USE_MEMSET)\0A /* now zero the buff */\0A memset(c, 0, sizeof c);\0A#endif\0A pa = m->used;\0A\0A /* copy the input */\0A oldused = a->used;\0A for (x = 0; x < oldused; x++) {\0A c[x] = a->dp[x];\0A }\0A#if !defined(USE_MEMSET)\0A for (; x < 2*pa+3; x++) {\0A c[x] = 0;\0A }\0A#endif\0A MONT_START;\0A\0A switch (pa) {\00"
@str.13 = [325 x i8] c" }\0A /* now copy out */\0A _c = c + pa;\0A tmpm = a->dp;\0A for (x = 0; x < pa+1; x++) {\0A *tmpm++ = *_c++;\0A }\0A\0A for (; x < oldused; x++) {\0A *tmpm++ = 0;\0A }\0A\0A MONT_FINI;\0A\0A a->used = pa+1;\0A fp_clamp(a);\0A\0A /* if A >= m then A = A - m */\0A if (fp_cmp_mag (a, m) != FP_LT) {\0A s_fp_sub (a, m, a);\0A }\0A}\0A\0A#endif\00"
@str.14 = [16 x i8] c" break;\00"
@str.15 = [17 x i8] c"#ifdef INNERMUL8\00"
@str.16 = [6 x i8] c"#else\00"
@str.17 = [7 x i8] c"#endif\00"
@str.18 = [108 x i8] c" LOOP_END;\0A while (cy) {\0A PROPCARRY;\0A ++_c;\0A }\00"
@str.20 = [28 x i8] c" INNERMUL; ++_c;\00"
@str.21 = [43 x i8] c" INNERMUL8; _c += 8; tmpm += 8;\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([552 x i8], [552 x i8]* @str, i64 0, i64 0))
br label %2
2: ; preds = %0, %36
%3 = phi i32 [ 1, %0 ], [ %38, %36 ]
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %3)
%5 = icmp ult i32 %3, 8
br label %6
6: ; preds = %2, %31
%7 = phi i32 [ 0, %2 ], [ %34, %31 ]
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([108 x i8], [108 x i8]* @.str.3, i64 0, i64 0), i32 %7, i32 %7)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.15, i64 0, i64 0))
br i1 %5, label %12, label %14
10: ; preds = %14
%11 = icmp ult i32 %15, %3
br i1 %11, label %12, label %24
12: ; preds = %6, %10
%13 = phi i32 [ 0, %6 ], [ %15, %10 ]
br label %19
14: ; preds = %6, %14
%15 = phi i32 [ %17, %14 ], [ 8, %6 ]
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.21, i64 0, i64 0))
%17 = add nuw nsw i32 %15, 8
%18 = icmp ugt i32 %17, %3
br i1 %18, label %10, label %14
19: ; preds = %12, %19
%20 = phi i32 [ %22, %19 ], [ %13, %12 ]
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.20, i64 0, i64 0))
%22 = add nuw nsw i32 %20, 1
%23 = icmp eq i32 %22, %3
br i1 %23, label %24, label %19
24: ; preds = %19, %10
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.16, i64 0, i64 0))
br label %26
26: ; preds = %24, %26
%27 = phi i32 [ 0, %24 ], [ %29, %26 ]
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.20, i64 0, i64 0))
%29 = add nuw nsw i32 %27, 1
%30 = icmp eq i32 %29, %3
br i1 %30, label %31, label %26
31: ; preds = %26
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.17, i64 0, i64 0))
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([108 x i8], [108 x i8]* @str.18, i64 0, i64 0))
%34 = add nuw nsw i32 %7, 1
%35 = icmp eq i32 %34, %3
br i1 %35, label %36, label %6
36: ; preds = %31
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.14, i64 0, i64 0))
%38 = add nuw nsw i32 %3, 1
%39 = icmp eq i32 %38, 17
br i1 %39, label %40, label %2
40: ; preds = %36
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([325 x i8], [325 x i8]* @str.13, i64 0, i64 0))
ret i32 0
}