#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 atoi(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  int N, x, y, z;
  N = atoi(argv[1]);
  printf("void fp_mul_comba%d(fp_int *A, fp_int *B, fp_int *C)\n"
         "{\n"
         "   fp_digit c0, c1, c2, at[%d];\n"
         "\n"
         "   memcpy(at, A->dp, %d * sizeof(fp_digit));\n"
         "   memcpy(at+%d, B->dp, %d * sizeof(fp_digit));\n"
         "   COMBA_START;\n"
         "\n"
         "   COMBA_CLEAR;\n",
         N, N + N, N, N, N);
  for (x = 0; x < (N + N - 1); x++) {
    printf("   /* %d */\n", x);
    if (x > 0) {
      printf("   COMBA_FORWARD;\n");
    }
    for (y = 0; y < N; y++) {
      for (z = 0; z < N; z++) {
        if ((y + z) == x) {
          printf("   MULADD(at[%d], at[%d]); ", y, z + N);
        }
      }
    }
    printf("\n"
           "   COMBA_STORE(C->dp[%d]);\n",
           x);
  }
  printf("   COMBA_STORE2(C->dp[%d]);\n"
         "   C->used = %d;\n"
         "   C->sign = A->sign ^ B->sign;\n"
         "   fp_clamp(C);\n"
         "   COMBA_FINI;\n"
         "}\n\n\n",
         N + N - 1, N + N);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
add    -0x14(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x14(%rbp),%r8d
mov    -0x14(%rbp),%r9d
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    123d <main+0x11d>
mov    -0x18(%rbp),%esi
lea    0xf4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
jle    11ac <main+0x8c>
lea    0xf3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    121e <main+0xfe>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    120b <main+0xeb>
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    11f8 <main+0xd8>
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
add    -0x14(%rbp),%edx
lea    0xf06(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fd <main+0xdd>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11c6 <main+0xa6>
jmp    1210 <main+0xf0>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b3 <main+0x93>
mov    -0x18(%rbp),%esi
lea    0xeeb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116f <main+0x4f>
mov    -0x14(%rbp),%esi
add    -0x14(%rbp),%esi
sub    $0x1,%esi
mov    -0x14(%rbp),%edx
add    -0x14(%rbp),%edx
lea    0xedd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
mov    %eax,%ebx
lea    (%rbx,%rbx,1),%edx
lea    0xead(%rip),%rdi
mov    %eax,%esi
mov    %edx,0x10(%rsp)
mov    %eax,%ecx
mov    %eax,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1040 <printf@plt>
lea    (%rbx,%rbx,1),%eax
add    $0xffffffff,%eax
mov    %eax,0xc(%rsp)
test   %ebx,%ebx
jle    1231 <main+0x101>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
mov    $0x1,%ecx
cmovge %eax,%ecx
mov    %ecx,0x14(%rsp)
lea    0xf50(%rip),%rbp
xor    %r13d,%r13d
jmp    11bc <main+0x8c>
nopl   0x0(%rax)
lea    0xf59(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r13d
cmp    0x14(%rsp),%r13d
je     1231 <main+0x101>
lea    0xf14(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r13d,%r13d
je     11de <main+0xae>
lea    0xfb5(%rip),%rdi
call   1030 <puts@plt>
xor    %r14d,%r14d
mov    %r13d,%r15d
jmp    11fd <main+0xcd>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r14d
add    $0xffffffff,%r15d
cmp    %ebx,%r14d
je     11a0 <main+0x70>
xor    %r12d,%r12d
jmp    1219 <main+0xe9>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r12d
cmp    %r12d,%ebx
je     11f0 <main+0xc0>
cmp    %r12d,%r15d
jne    1210 <main+0xe0>
lea    (%rbx,%r12,1),%edx
mov    %rbp,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1210 <main+0xe0>
lea    0xee5(%rip),%rdi
mov    0xc(%rsp),%esi
mov    0x10(%rsp),%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [215 x i8] c"void fp_mul_comba%d(fp_int *A, fp_int *B, fp_int *C)\0A{\0A fp_digit c0, c1, c2, at[%d];\0A\0A memcpy(at, A->dp, %d * sizeof(fp_digit));\0A memcpy(at+%d, B->dp, %d * sizeof(fp_digit));\0A COMBA_START;\0A\0A COMBA_CLEAR;\0A\00"
@.str.1 = [13 x i8] c" /* %d */\0A\00"
@.str.2 = [19 x i8] c" COMBA_FORWARD;\0A\00"
@.str.3 = [28 x i8] c" MULADD(at[%d], at[%d]); \00"
@.str.4 = [29 x i8] c"\0A COMBA_STORE(C->dp[%d]);\0A\00"
@.str.5 = [113 x i8] c" COMBA_STORE2(C->dp[%d]);\0A C->used = %d;\0A C->sign = A->sign ^ B->sign;\0A fp_clamp(C);\0A COMBA_FINI;\0A}\0A\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @atoi(i8* %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = load i32, i32* %6
%16 = load i32, i32* %6
%17 = add nsw i32 %15, %16
%18 = load i32, i32* %6
%19 = load i32, i32* %6
%20 = load i32, i32* %6
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([215 x i8], [215 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %17, i32 %18, i32 %19, i32 %20)
store i32 0, i32* %7
br label %22
22: ; preds = %69, %2
%23 = load i32, i32* %7
%24 = load i32, i32* %6
%25 = load i32, i32* %6
%26 = add nsw i32 %24, %25
%27 = sub nsw i32 %26, 1
%28 = icmp slt i32 %23, %27
br i1 %28, label %29, label %72
29: ; preds = %22
%30 = load i32, i32* %7
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %7
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %34, %29
store i32 0, i32* %8
br label %37
37: ; preds = %63, %36
%38 = load i32, i32* %8
%39 = load i32, i32* %6
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %66
41: ; preds = %37
store i32 0, i32* %9
br label %42
42: ; preds = %59, %41
%43 = load i32, i32* %9
%44 = load i32, i32* %6
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %62
46: ; preds = %42
%47 = load i32, i32* %8
%48 = load i32, i32* %9
%49 = add nsw i32 %47, %48
%50 = load i32, i32* %7
%51 = icmp eq i32 %49, %50
br i1 %51, label %52, label %58
52: ; preds = %46
%53 = load i32, i32* %8
%54 = load i32, i32* %9
%55 = load i32, i32* %6
%56 = add nsw i32 %54, %55
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %53, i32 %56)
br label %58
58: ; preds = %52, %46
br label %59
59: ; preds = %58
%60 = load i32, i32* %9
%61 = add nsw i32 %60, 1
store i32 %61, i32* %9
br label %42
62: ; preds = %42
br label %63
63: ; preds = %62
%64 = load i32, i32* %8
%65 = add nsw i32 %64, 1
store i32 %65, i32* %8
br label %37
66: ; preds = %37
%67 = load i32, i32* %7
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %67)
br label %69
69: ; preds = %66
%70 = load i32, i32* %7
%71 = add nsw i32 %70, 1
store i32 %71, i32* %7
br label %22
72: ; preds = %22
%73 = load i32, i32* %6
%74 = load i32, i32* %6
%75 = add nsw i32 %73, %74
%76 = sub nsw i32 %75, 1
%77 = load i32, i32* %6
%78 = load i32, i32* %6
%79 = add nsw i32 %77, %78
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([113 x i8], [113 x i8]* @.str.5, i64 0, i64 0), i32 %76, i32 %79)
ret i32 0
}

LLVM IR (-O2):
@.str = [215 x i8] c"void fp_mul_comba%d(fp_int *A, fp_int *B, fp_int *C)\0A{\0A fp_digit c0, c1, c2, at[%d];\0A\0A memcpy(at, A->dp, %d * sizeof(fp_digit));\0A memcpy(at+%d, B->dp, %d * sizeof(fp_digit));\0A COMBA_START;\0A\0A COMBA_CLEAR;\0A\00"
@.str.1 = [13 x i8] c" /* %d */\0A\00"
@.str.3 = [28 x i8] c" MULADD(at[%d], at[%d]); \00"
@.str.4 = [29 x i8] c"\0A COMBA_STORE(C->dp[%d]);\0A\00"
@.str.5 = [113 x i8] c" COMBA_STORE2(C->dp[%d]);\0A C->used = %d;\0A C->sign = A->sign ^ B->sign;\0A fp_clamp(C);\0A COMBA_FINI;\0A}\0A\0A\0A\00"
@str = [18 x i8] c" COMBA_FORWARD;\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @atoi(i8* %4)
%6 = shl nsw i32 %5, 1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([215 x i8], [215 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6, i32 %5, i32 %5, i32 %5)
%8 = add i32 %6, -1
%9 = icmp sgt i32 %5, 0
br i1 %9, label %10, label %38
10: ; preds = %2
%11 = call i32 @llvm.smax.i32(i32 %8, i32 1)
br label %12
12: ; preds = %10, %34
%13 = phi i32 [ 0, %10 ], [ %36, %34 ]
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = icmp eq i32 %13, 0
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %18
18: ; preds = %12, %16
br label %19
19: ; preds = %18, %31
%20 = phi i32 [ %32, %31 ], [ 0, %18 ]
br label %21
21: ; preds = %19, %28
%22 = phi i32 [ %29, %28 ], [ 0, %19 ]
%23 = add nuw nsw i32 %22, %20
%24 = icmp eq i32 %23, %13
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = add nsw i32 %22, %5
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %20, i32 %26)
br label %28
28: ; preds = %21, %25
%29 = add nuw nsw i32 %22, 1
%30 = icmp eq i32 %29, %5
br i1 %30, label %31, label %21
31: ; preds = %28
%32 = add nuw nsw i32 %20, 1
%33 = icmp eq i32 %32, %5
br i1 %33, label %34, label %19
34: ; preds = %31
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %13)
%36 = add nuw nsw i32 %13, 1
%37 = icmp eq i32 %36, %11
br i1 %37, label %38, label %12
38: ; preds = %34, %2
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([113 x i8], [113 x i8]* @.str.5, i64 0, i64 0), i32 %8, i32 %6)
ret i32 0
}