#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 */
char *_ada_phc_factor(int, char *);
int /*<<< orphan*/ adafinal();
int /*<<< orphan*/ adainit();
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, ...);
int main() {
  int n, i = 0;
  char ch, s[80], *f;
  printf("Give number of variables : ");
  scanf("%d", &n);
  printf("Give a polynomial in %d variables, terminate with ';' :\n", n);
  ch = ' ';
  while (scanf("%c", &ch) == 1) {
    s[i++] = ch;
    if (ch == ';')
      break;
  }
  s[i] = '\0';
  printf("The polynomial read : %s\n", s);
  printf("Calling PHC... \n");
  adainit();
  f = _ada_phc_factor(n, s);
  adafinal();
  printf("... done with the call.\n");
  printf("The factors are %s \n", f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea1(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x8(%rbp),%esi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movb   $0x20,-0xd(%rbp)
lea    0xeb6(%rip),%rdi
lea    -0xd(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    11e1 <main+0x91>
mov    -0xd(%rbp),%cl
mov    -0xc(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0xc(%rbp)
cltq
mov    %cl,-0x60(%rbp,%rax,1)
movsbl -0xd(%rbp),%eax
cmp    $0x3b,%eax
jne    11dc <main+0x8c>
jmp    11e1 <main+0x91>
jmp    119b <main+0x4b>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x60(%rbp,%rax,1)
lea    -0x60(%rbp),%rsi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <adainit@plt>
mov    -0x8(%rbp),%edi
lea    -0x60(%rbp),%rsi
call   1030 <_ada_phc_factor@plt>
mov    %rax,-0x68(%rbp)
mov    $0x0,%al
call   1050 <adafinal@plt>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x68(%rbp),%rsi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x60,%rsp
lea    0xe90(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe9e(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0xc(%rsp),%esi
lea    0xe8a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movb   $0x20,0xb(%rsp)
lea    0xeb0(%rip),%r14
lea    0xb(%rsp),%r15
xor    %ebx,%ebx
nop
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
cmp    $0x1,%eax
jne    11d3 <main+0x73>
movzbl 0xb(%rsp),%eax
mov    %al,0x10(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0x3b,%al
jne    11b0 <main+0x50>
movslq %ebx,%rax
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xe79(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe92(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1080 <adainit@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
call   1030 <_ada_phc_factor@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <adafinal@plt>
lea    0xe79(%rip),%rdi
call   1040 <puts@plt>
lea    0xe48(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Give number of variables : \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [57 x i8] c"Give a polynomial in %d variables, terminate with ';' :\0A\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [26 x i8] c"The polynomial read : %s\0A\00"
@.str.5 = [17 x i8] c"Calling PHC... \0A\00"
@.str.6 = [25 x i8] c"... done with the call.\0A\00"
@.str.7 = [21 x i8] c"The factors are %s \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = alloca [80 x i8]
%6 = alloca i8*
store i32 0, i32* %1
store i32 0, i32* %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0), i32 %9)
store i8 32, i8* %4
br label %11
11: ; preds = %24, %0
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %25
14: ; preds = %11
%15 = load i8, i8* %4
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
%18 = sext i32 %16 to i64
%19 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 %18
store i8 %15, i8* %19
%20 = load i8, i8* %4
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 59
br i1 %22, label %23, label %24
23: ; preds = %14
br label %25
24: ; preds = %14
br label %11
25: ; preds = %23, %11
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 %27
store i8 0, i8* %28
%29 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%32 = call i32 (...) @adainit()
%33 = load i32, i32* %2
%34 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%35 = call i8* @_ada_phc_factor(i32 %33, i8* %34)
store i8* %35, i8** %6
%36 = call i32 (...) @adafinal()
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
%38 = load i8*, i8** %6
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i8* %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [28 x i8] c"Give number of variables : \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [57 x i8] c"Give a polynomial in %d variables, terminate with ';' :\0A\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [26 x i8] c"The polynomial read : %s\0A\00"
@.str.7 = [21 x i8] c"The factors are %s \0A\00"
@str = [16 x i8] c"Calling PHC... \00"
@str.8 = [24 x i8] c"... done with the call.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca [80 x i8]
%4 = bitcast i32* %1 to i8*
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0), i32 %8)
store i8 32, i8* %2
br label %10
10: ; preds = %14, %0
%11 = phi i64 [ %16, %14 ], [ 0, %0 ]
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = load i8, i8* %2
%16 = add nuw i64 %11, 1
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %11
store i8 %15, i8* %17
%18 = icmp eq i8 %15, 59
br i1 %18, label %19, label %10
19: ; preds = %14, %10
%20 = phi i64 [ %16, %14 ], [ %11, %10 ]
%21 = shl i64 %20, 32
%22 = ashr exact i64 %21, 32
%23 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %22
store i8 0, i8* %23
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %5)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%26 = call i32 (...) @adainit()
%27 = load i32, i32* %1
%28 = call i8* @_ada_phc_factor(i32 %27, i8* %5)
%29 = call i32 (...) @adafinal()
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.8, i64 0, i64 0))
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i8* %28)
ret i32 0
}