#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 _ada_use_c2fac(int, int *, int *, double *);
int /*<<< orphan*/ adafinal();
int /*<<< orphan*/ adainit();
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  printf("\nTesting using factorization in PHCpack from within C ...\n");
  adainit();
  {
    int fail, choice = 0;
    int *a;
    int b[2];
    double *c;
    char skip_newline;
    do {
      if (choice == 3) {
        double gamma[2];
        gamma[0] = 0.929016078002768;
        gamma[1] = 0.370039358463874;
        fail = _ada_use_c2fac(choice, a, b, gamma);
      } else if (choice == 5) {
        int n;
        printf("Give max #loops : ");
        scanf("%d", &n);
        printf("initialize with %d loops...\n", n);
        fail = _ada_use_c2fac(choice, &n, b, c);
      } else {
        fail = _ada_use_c2fac(choice, a, b, c);
        if (choice == 1)
          printf("fail = %d, n = %d, dim = %d, deg = %d\n", fail, *a, b[0],
                 b[1]);
      }
      printf("Give a number (0 for menu, -1 to exit) : ");
      scanf("%d", &choice);
      skip_newline = getchar();
    } while (choice >= 0);
  }
  adafinal();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <adainit@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x3,-0xc(%rbp)
jne    11cb <main+0x6b>
movsd  0xe6b(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe56(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   1030 <_ada_use_c2fac@plt>
mov    %eax,-0x8(%rbp)
jmp    1269 <main+0x109>
cmpl   $0x5,-0xc(%rbp)
jne    1220 <main+0xc0>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe74(%rip),%rdi
lea    -0x44(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x44(%rbp),%esi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    -0x44(%rbp),%rsi
call   1030 <_ada_use_c2fac@plt>
mov    %eax,-0x8(%rbp)
jmp    1264 <main+0x104>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1030 <_ada_use_c2fac@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    125f <main+0xff>
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1264 <main+0x104>
jmp    1269 <main+0x109>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xde0(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1070 <scanf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x29(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    118b <main+0x2b>
mov    $0x0,%al
call   1060 <adafinal@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xf0f(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1090 <adainit@plt>
movl   $0x0,0x4(%rsp)
lea    0xe83(%rip),%rbx
lea    0x10(%rsp),%r15
lea    0xe7a(%rip),%r12
lea    0x8(%rsp),%r13
lea    0xeb2(%rip),%rbp
lea    0x4(%rsp),%r14
xor    %edi,%edi
jmp    122a <main+0xba>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xe39(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <scanf@plt>
mov    0x10(%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%edi
mov    %r15,%rsi
mov    %r13,%rdx
call   1040 <_ada_use_c2fac@plt>
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <scanf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0x4(%rsp),%edi
test   %edi,%edi
js     127a <main+0x10a>
cmp    $0x5,%edi
je     11d0 <main+0x60>
cmp    $0x3,%edi
jne    1250 <main+0xe0>
movaps 0xdc5(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
mov    $0x3,%edi
mov    %r13,%rdx
mov    %r15,%rcx
jmp    1201 <main+0x91>
nopl   (%rax)
mov    %r13,%rdx
call   1040 <_ada_use_c2fac@plt>
cmpl   $0x1,0x4(%rsp)
jne    1206 <main+0x96>
mov    0x8(%rsp),%ecx
mov    0xc(%rsp),%r8d
lea    0xdd4(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1206 <main+0x96>
xor    %eax,%eax
call   1070 <adafinal@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [59 x i8] c"\0ATesting using factorization in PHCpack from within C ...\0A\00"
@.str.1 = [19 x i8] c"Give max #loops : \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [29 x i8] c"initialize with %d loops...\0A\00"
@.str.4 = [39 x i8] c"fail = %d, n = %d, dim = %d, deg = %d\0A\00"
@.str.5 = [42 x i8] c"Give a number (0 for menu, -1 to exit) : \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [2 x i32]
%6 = alloca double*
%7 = alloca i8
%8 = alloca [2 x double]
%9 = alloca i32
store i32 0, i32* %1
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (...) @adainit()
store i32 0, i32* %3
br label %12
12: ; preds = %58, %0
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 3
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = getelementptr inbounds [2 x double], [2 x double]* %8, i64 0, i64 0
store double 0x3FEDBA7FED0F5CC3, double* %16
%17 = getelementptr inbounds [2 x double], [2 x double]* %8, i64 0, i64 1
store double 0x3FD7AEB98FB57341, double* %17
%18 = load i32, i32* %3
%19 = load i32*, i32** %4
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%21 = getelementptr inbounds [2 x double], [2 x double]* %8, i64 0, i64 0
%22 = call i32 @_ada_use_c2fac(i32 %18, i32* %19, i32* %20, double* %21)
store i32 %22, i32* %2
br label %54
23: ; preds = %12
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, 5
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %9)
%29 = load i32, i32* %9
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %3
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%33 = load double*, double** %6
%34 = call i32 @_ada_use_c2fac(i32 %31, i32* %9, i32* %32, double* %33)
store i32 %34, i32* %2
br label %53
35: ; preds = %23
%36 = load i32, i32* %3
%37 = load i32*, i32** %4
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%39 = load double*, double** %6
%40 = call i32 @_ada_use_c2fac(i32 %36, i32* %37, i32* %38, double* %39)
store i32 %40, i32* %2
%41 = load i32, i32* %3
%42 = icmp eq i32 %41, 1
br i1 %42, label %43, label %52
43: ; preds = %35
%44 = load i32, i32* %2
%45 = load i32*, i32** %4
%46 = load i32, i32* %45
%47 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%48 = load i32, i32* %47
%49 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%50 = load i32, i32* %49
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %44, i32 %46, i32 %48, i32 %50)
br label %52
52: ; preds = %43, %35
br label %53
53: ; preds = %52, %26
br label %54
54: ; preds = %53, %15
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0))
%56 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%57 = call signext i8 (...) @getchar()
store i8 %57, i8* %7
br label %58
58: ; preds = %54
%59 = load i32, i32* %3
%60 = icmp sge i32 %59, 0
br i1 %60, label %12, label %61
61: ; preds = %58
%62 = call i32 (...) @adafinal()
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [19 x i8] c"Give max #loops : \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [29 x i8] c"initialize with %d loops...\0A\00"
@.str.4 = [39 x i8] c"fail = %d, n = %d, dim = %d, deg = %d\0A\00"
@.str.5 = [42 x i8] c"Give a number (0 for menu, -1 to exit) : \00"
@str = [58 x i8] c"\0ATesting using factorization in PHCpack from within C ...\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca <2 x double>
%4 = alloca i32
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 (...) @adainit()
%7 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%8 = bitcast [2 x i32]* %2 to i8*
%9 = bitcast i32* %4 to i8*
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%11 = bitcast <2 x double>* %3 to i8*
%12 = getelementptr inbounds <2 x double>, <2 x double>* %3, i64 0, i64 0
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
br label %14
14: ; preds = %33, %0
%15 = phi i32 [ %37, %33 ], [ 0, %0 ]
switch i32 %15, label %25 [
i32 3, label %16
i32 5, label %18
]
16: ; preds = %14
store <2 x double> <double 0x3FEDBA7FED0F5CC3, double 0x3FD7AEB98FB57341>, <2 x double>* %3
%17 = call i32 @_ada_use_c2fac(i32 3, i32* undef, i32* %10, double* %12)
br label %33
18: ; preds = %14
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%21 = load i32, i32* %4
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %1
%24 = call i32 @_ada_use_c2fac(i32 %23, i32* %4, i32* %10, double* undef)
br label %33
25: ; preds = %14
%26 = call i32 @_ada_use_c2fac(i32 %15, i32* undef, i32* %10, double* undef)
%27 = load i32, i32* %1
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i32, i32* %10
%31 = load i32, i32* %13
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %26, i32 undef, i32 %30, i32 %31)
br label %33
33: ; preds = %18, %29, %25, %16
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0))
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%36 = call signext i8 (...) @getchar()
%37 = load i32, i32* %1
%38 = icmp sgt i32 %37, -1
br i1 %38, label %14, label %39
39: ; preds = %33
%40 = call i32 (...) @adafinal()
ret i32 0
}