#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*/ mpf_t;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ gmp_asprintf(char **, char *, int /*<<< orphan*/);
int /*<<< orphan*/ mpf_init2(int /*<<< orphan*/, unsigned long);
int /*<<< orphan*/ printf(char *, unsigned int, char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
int /*<<< orphan*/ threadedChudnovsky(unsigned long, int /*<<< orphan*/,
                                      unsigned long, unsigned long);
int main(int argc, char *argv[]) {
  unsigned long threadCount;
  unsigned long itercount;
  unsigned long precision;
  if (argc < 4) {
    fprintf(stderr, "HEY! argumentos..\n");
    fprintf(stderr, "\t%s  Nr_threads  Nr_iteracoes  Precisao_em_bytes",
            argv[0]);
    return -1;
  }
  threadCount = atoi(argv[1]);
  itercount = atoi(argv[2]);
  precision = 8 * atoi(argv[3]);
  if (itercount < threadCount) {
    fprintf(stderr, "HEY! nao podemos ter mais threads que iteracoes\n");
    return -1;
  }
  mpf_t pi;
  mpf_init2(pi, precision);
  threadedChudnovsky(threadCount, pi, precision, itercount);
  char *pi_str;
  gmp_asprintf(&pi_str, "%.Ff", pi);
  unsigned significantDigits = strlen(pi_str) - 2;
  printf("nr casas decimais: %u\n%s\n", significantDigits, pi_str);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11d1 <main+0x61>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe55(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129a <main+0x12a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
cltq
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1080 <atoi@plt>
shl    $0x3,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    123e <main+0xce>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129a <main+0x12a>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1090 <mpf_init2@plt>
mov    -0x18(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1050 <threadedChudnovsky@plt>
mov    -0x2c(%rbp),%edx
lea    -0x38(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   1070 <gmp_asprintf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x2,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%esi
mov    -0x38(%rbp),%rdx
lea    0xdec(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jg     11b6 <main+0x46>
mov    0x2e59(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xe6f(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xe6e(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    124c <main+0xdc>
mov    0x8(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
mov    0x18(%rbx),%rdi
call   1080 <atoi@plt>
cmp    %r14d,%ebp
jae    11f9 <main+0x89>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    124c <main+0xdc>
shl    $0x3,%eax
movslq %eax,%rbx
movslq %r14d,%r14
movslq %ebp,%rbp
mov    %rbx,%rsi
call   1090 <mpf_init2@plt>
mov    %r14,%rdi
mov    %rbx,%rdx
mov    %rbp,%rcx
call   1050 <threadedChudnovsky@plt>
lea    0xe53(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1070 <gmp_asprintf@plt>
mov    0x8(%rsp),%rdi
call   1030 <strlen@plt>
lea    -0x2(%rax),%esi
mov    0x8(%rsp),%rdx
lea    0xe35(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"HEY! argumentos..\0A\00"
@.str.1 = [49 x i8] c"\09%s Nr_threads Nr_iteracoes Precisao_em_bytes\00"
@.str.2 = [49 x i8] c"HEY! nao podemos ter mais threads que iteracoes\0A\00"
@.str.3 = [5 x i8] c"%.Ff\00"
@.str.4 = [26 x i8] c"nr casas decimais: %u\0A%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 4
br i1 %13, label %14, label %22
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i8* %20)
store i32 -1, i32* %3
br label %62
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
%27 = sext i32 %26 to i64
store i64 %27, i64* %6
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
%32 = sext i32 %31 to i64
store i64 %32, i64* %7
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 3
%35 = load i8*, i8** %34
%36 = call i32 @atoi(i8* %35)
%37 = mul nsw i32 8, %36
%38 = sext i32 %37 to i64
store i64 %38, i64* %8
%39 = load i64, i64* %7
%40 = load i64, i64* %6
%41 = icmp ult i64 %39, %40
br i1 %41, label %42, label %45
42: ; preds = %22
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %62
45: ; preds = %22
%46 = load i32, i32* %9
%47 = load i64, i64* %8
%48 = call i32 @mpf_init2(i32 %46, i64 %47)
%49 = load i64, i64* %6
%50 = load i32, i32* %9
%51 = load i64, i64* %8
%52 = load i64, i64* %7
%53 = call i32 @threadedChudnovsky(i64 %49, i32 %50, i64 %51, i64 %52)
%54 = load i32, i32* %9
%55 = call i32 @gmp_asprintf(i8** %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %54)
%56 = load i8*, i8** %10
%57 = call i32 @strlen(i8* %56)
%58 = sub nsw i32 %57, 2
store i32 %58, i32* %11
%59 = load i32, i32* %11
%60 = load i8*, i8** %10
%61 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %59, i8* %60)
store i32 0, i32* %3
br label %62
62: ; preds = %45, %42, %14
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"HEY! argumentos..\0A\00"
@.str.1 = [49 x i8] c"\09%s Nr_threads Nr_iteracoes Precisao_em_bytes\00"
@.str.2 = [49 x i8] c"HEY! nao podemos ter mais threads que iteracoes\0A\00"
@.str.3 = [5 x i8] c"%.Ff\00"
@.str.4 = [26 x i8] c"nr casas decimais: %u\0A%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = icmp slt i32 %0, 4
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %39
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = getelementptr inbounds i8*, i8** %1, i64 3
%19 = load i8*, i8** %18
%20 = tail call i32 @atoi(i8* %19)
%21 = shl nsw i32 %20, 3
%22 = sext i32 %21 to i64
%23 = icmp ult i32 %17, %14
br i1 %23, label %24, label %27
24: ; preds = %11
%25 = load i32, i32* @stderr
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
br label %39
27: ; preds = %11
%28 = sext i32 %14 to i64
%29 = sext i32 %17 to i64
%30 = tail call i32 @mpf_init2(i32 undef, i64 %22)
%31 = tail call i32 @threadedChudnovsky(i64 %28, i32 undef, i64 %22, i64 %29)
%32 = bitcast i8** %3 to i8*
%33 = call i32 @gmp_asprintf(i8** %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 undef)
%34 = load i8*, i8** %3
%35 = call i32 @strlen(i8* %34)
%36 = add nsw i32 %35, -2
%37 = load i8*, i8** %3
%38 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %36, i8* %37)
br label %39
39: ; preds = %27, %24, %5
%40 = phi i32 [ -1, %5 ], [ -1, %24 ], [ 0, %27 ]
ret i32 %40
}