#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 */
typedef int /*<<< orphan*/ mpz_t;

/* Variables and functions */
double atof(char *);
int ecm_factor(int /*<<< orphan*/, int /*<<< orphan*/, double,
               int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_out_str(int /*<<< orphan*/, int, int /*<<< orphan*/);
scalar_t__ mpz_set_str(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  mpz_t n, f;
  int res;
  double B1;
  if (argc != 3) {
    fprintf(stderr, "Usage: ecmfactor <number> <B1>\n");
    exit(1);
  }
  mpz_init(n);
  if (mpz_set_str(n, argv[1], 10)) {
    fprintf(stderr, "Invalid number: %s\n", argv[1]);
    exit(1);
  }
  B1 = atof(argv[2]);
  mpz_init(f);
  printf("Performing one curve with B1=%1.0f\n", B1);
  res = ecm_factor(f, n, B1, NULL);
  if (res > 0) {
    printf("found factor in step %u: ", res);
    mpz_out_str(stdout, 10, f);
    printf("\n");
  } else if (res == 0)
    printf("found no factor\n");
  else
    printf("error\n");
  mpz_clear(f);
  mpz_clear(n);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11d1 <main+0x41>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0xa,%edx
call   1090 <mpz_set_str@plt>
cmp    $0x0,%rax
je     1221 <main+0x91>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe10(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <mpz_init@plt>
movsd  -0x28(%rbp),%xmm0
lea    0xded(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
xor    %eax,%eax
mov    %eax,%edx
call   1070 <ecm_factor@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    12a9 <main+0x119>
mov    -0x1c(%rbp),%esi
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
mov    $0xa,%esi
call   1080 <mpz_out_str@plt>
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d9 <main+0x149>
cmpl   $0x0,-0x1c(%rbp)
jne    12c6 <main+0x136>
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d4 <main+0x144>
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d9 <main+0x149>
mov    -0x18(%rbp),%edi
call   10a0 <mpz_clear@plt>
mov    -0x14(%rbp),%edi
call   10a0 <mpz_clear@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x3,%edi
jne    126e <main+0xbe>
mov    %rsi,%rbx
call   1070 <mpz_init@plt>
mov    0x8(%rbx),%rsi
mov    $0xa,%edx
call   10b0 <mpz_set_str@plt>
test   %rax,%rax
jne    128f <main+0xdf>
mov    0x10(%rbx),%rdi
call   1050 <atof@plt>
movsd  %xmm0,0x8(%rsp)
call   1070 <mpz_init@plt>
lea    0xe3c(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1060 <printf@plt>
movsd  0x8(%rsp),%xmm0
xor    %edx,%edx
call   1090 <ecm_factor@plt>
test   %eax,%eax
jle    1245 <main+0x95>
lea    0xe3b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
mov    $0xa,%esi
call   10a0 <mpz_out_str@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    125c <main+0xac>
je     1250 <main+0xa0>
lea    0xe24(%rip),%rdi
jmp    1257 <main+0xa7>
lea    0xe21(%rip),%rdi
call   1040 <puts@plt>
call   10c0 <mpz_clear@plt>
call   10c0 <mpz_clear@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
lea    0xd82(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xd7d(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"Usage: ecmfactor <number> <B1>\0A\00"
@.str.1 = [20 x i8] c"Invalid number: %s\0A\00"
@.str.2 = [36 x i8] c"Performing one curve with B1=%1.0f\0A\00"
@.str.3 = [26 x i8] c"found factor in step %u: \00"
@stdout = global i32 0
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [17 x i8] c"found no factor\0A\00"
@.str.6 = [7 x i8] c"error\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 double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i32, i32* %6
%18 = call i32 @mpz_init(i32 %17)
%19 = load i32, i32* %6
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @mpz_set_str(i32 %19, i8* %22, i32 10)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %16
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %16
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call double @atof(i8* %35)
store double %36, double* %9
%37 = load i32, i32* %7
%38 = call i32 @mpz_init(i32 %37)
%39 = load double, double* %9
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), double %39)
%41 = load i32, i32* %7
%42 = load i32, i32* %6
%43 = load double, double* %9
%44 = call i32 @ecm_factor(i32 %41, i32 %42, double %43, i32* null)
store i32 %44, i32* %8
%45 = load i32, i32* %8
%46 = icmp sgt i32 %45, 0
br i1 %46, label %47, label %54
47: ; preds = %32
%48 = load i32, i32* %8
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %48)
%50 = load i32, i32* @stdout
%51 = load i32, i32* %7
%52 = call i32 @mpz_out_str(i32 %50, i32 10, i32 %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %62
54: ; preds = %32
%55 = load i32, i32* %8
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %54
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %61
59: ; preds = %54
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %61
61: ; preds = %59, %57
br label %62
62: ; preds = %61, %47
%63 = load i32, i32* %7
%64 = call i32 @mpz_clear(i32 %63)
%65 = load i32, i32* %6
%66 = call i32 @mpz_clear(i32 %65)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"Usage: ecmfactor <number> <B1>\0A\00"
@.str.1 = [20 x i8] c"Invalid number: %s\0A\00"
@.str.2 = [36 x i8] c"Performing one curve with B1=%1.0f\0A\00"
@.str.3 = [26 x i8] c"found factor in step %u: \00"
@stdout = global i32 0
@str = [6 x i8] c"error\00"
@str.7 = [16 x i8] c"found no factor\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = tail call i32 @mpz_init(i32 undef)
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @mpz_set_str(i32 undef, i8* %11, i32 10)
%13 = icmp eq i64 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %8
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %10
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %8
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call double @atof(i8* %21)
%23 = tail call i32 @mpz_init(i32 undef)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), double %22)
%25 = tail call i32 @ecm_factor(i32 undef, i32 undef, double %22, i32* null)
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %19
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%29 = load i32, i32* @stdout
%30 = tail call i32 @mpz_out_str(i32 %29, i32 10, i32 undef)
%31 = tail call i32 @putchar(i32 10)
br label %38
32: ; preds = %19
%33 = icmp eq i32 %25, 0
br i1 %33, label %34, label %36
34: ; preds = %32
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.7, i64 0, i64 0))
br label %38
36: ; preds = %32
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %38
38: ; preds = %34, %36, %27
%39 = tail call i32 @mpz_clear(i32 undef)
%40 = tail call i32 @mpz_clear(i32 undef)
ret i32 0
}