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

/* Variables and functions */
int /*<<< orphan*/ MPFR_RNDD;
int /*<<< orphan*/ MPFR_RNDU;
int atoi(char *);
int /*<<< orphan*/ mpfr_add(int /*<<< orphan*/, int /*<<< orphan*/,
                            int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_div(int /*<<< orphan*/, int /*<<< orphan*/,
                            int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_init2(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpfr_mul_ui(int /*<<< orphan*/, int /*<<< orphan*/,
                               unsigned int, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_out_str(int /*<<< orphan*/, int, int /*<<< orphan*/,
                                int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpfr_set_d(int /*<<< orphan*/, double, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  if (argc < 2) {
    printf("Usage ./test num_of_loops \n");
    return 0;
  }
  int loop = atoi(argv[1]);
  unsigned int i;
  mpfr_t s, t, u;
  mpfr_init2(t, 200);
  mpfr_set_d(t, 1.0, MPFR_RNDD);
  mpfr_init2(s, 200);
  mpfr_set_d(s, 1.0, MPFR_RNDD);
  mpfr_init2(u, 200);
  for (i = 1; i <= loop; i++) {
    mpfr_mul_ui(t, t, i, MPFR_RNDU);
    mpfr_set_d(u, 1.0, MPFR_RNDD);
    mpfr_div(u, u, t, MPFR_RNDD);
    mpfr_add(s, s, u, MPFR_RNDD);
  }
  printf("Sum is ");
  mpfr_out_str(stdout, 10, 0, s, MPFR_RNDD);
  putchar('\n');
  mpfr_clear(s);
  mpfr_clear(t);
  mpfr_clear(u);
  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   $0x2,-0x8(%rbp)
jge    11d8 <main+0x38>
lea    0xe41(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1317 <main+0x177>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%edi
mov    $0xc8,%esi
call   10c0 <mpfr_init2@plt>
mov    -0x20(%rbp),%edi
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
movsd  0xdf7(%rip),%xmm0
call   1050 <mpfr_set_d@plt>
mov    -0x1c(%rbp),%edi
mov    $0xc8,%esi
call   10c0 <mpfr_init2@plt>
mov    -0x1c(%rbp),%edi
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
movsd  0xdd1(%rip),%xmm0
call   1050 <mpfr_set_d@plt>
mov    -0x24(%rbp),%edi
mov    $0xc8,%esi
call   10c0 <mpfr_init2@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
ja     12c0 <main+0x120>
mov    -0x20(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    0x2d74(%rip),%rax
mov    (%rax),%ecx
call   1030 <mpfr_mul_ui@plt>
mov    -0x24(%rbp),%edi
mov    0x2d73(%rip),%rax
mov    (%rax),%esi
movsd  0xd81(%rip),%xmm0
call   1050 <mpfr_set_d@plt>
mov    -0x24(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    0x2d54(%rip),%rax
mov    (%rax),%ecx
call   10a0 <mpfr_div@plt>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    0x2d3d(%rip),%rax
mov    (%rax),%ecx
call   1090 <mpfr_add@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1248 <main+0xa8>
lea    0xd5d(%rip),%rdi
call   1060 <printf@plt>
mov    0x2cfd(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%ecx
mov    0x2d09(%rip),%rax
mov    (%rax),%r8d
mov    $0xa,%esi
xor    %edx,%edx
call   1080 <mpfr_out_str@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    -0x1c(%rbp),%edi
call   1070 <mpfr_clear@plt>
mov    -0x20(%rbp),%edi
call   1070 <mpfr_clear@plt>
mov    -0x24(%rbp),%edi
call   1070 <mpfr_clear@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     11cd <main+0x1d>
lea    0xe4d(%rip),%rdi
call   1050 <puts@plt>
jmp    129c <main+0xec>
mov    0x8(%rsi),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r14d
mov    $0xc8,%esi
call   10d0 <mpfr_init2@plt>
mov    0x2dfe(%rip),%rbx
mov    (%rbx),%esi
movsd  0xe0c(%rip),%xmm0
call   1060 <mpfr_set_d@plt>
mov    $0xc8,%esi
call   10d0 <mpfr_init2@plt>
mov    (%rbx),%esi
movsd  0xdf3(%rip),%xmm0
call   1060 <mpfr_set_d@plt>
mov    $0xc8,%esi
call   10d0 <mpfr_init2@plt>
test   %r14d,%r14d
je     125f <main+0xaf>
mov    $0x1,%ebp
mov    0x2dab(%rip),%r15
nopl   (%rax)
mov    (%r15),%ecx
mov    %ebp,%edx
call   1030 <mpfr_mul_ui@plt>
mov    (%rbx),%esi
movsd  0xdbc(%rip),%xmm0
call   1060 <mpfr_set_d@plt>
mov    (%rbx),%ecx
call   10b0 <mpfr_div@plt>
mov    (%rbx),%ecx
call   10a0 <mpfr_add@plt>
add    $0x1,%ebp
cmp    %r14d,%ebp
jbe    1230 <main+0x80>
lea    0xda2(%rip),%rdi
call   1070 <printf@plt>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%r8d
mov    $0xa,%esi
xor    %edx,%edx
call   1090 <mpfr_out_str@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
call   1080 <mpfr_clear@plt>
call   1080 <mpfr_clear@plt>
call   1080 <mpfr_clear@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Usage ./test num_of_loops \0A\00"
@MPFR_RNDD = global i32 0
@MPFR_RNDU = global i32 0
@.str.1 = [8 x i8] c"Sum is \00"
@stdout = global i32 0
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
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %71
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %6
%20 = load i32, i32* %9
%21 = call i32 @mpfr_init2(i32 %20, i32 200)
%22 = load i32, i32* %9
%23 = load i32, i32* @MPFR_RNDD
%24 = call i32 @mpfr_set_d(i32 %22, double 1.000000e+00, i32 %23)
%25 = load i32, i32* %8
%26 = call i32 @mpfr_init2(i32 %25, i32 200)
%27 = load i32, i32* %8
%28 = load i32, i32* @MPFR_RNDD
%29 = call i32 @mpfr_set_d(i32 %27, double 1.000000e+00, i32 %28)
%30 = load i32, i32* %10
%31 = call i32 @mpfr_init2(i32 %30, i32 200)
store i32 1, i32* %7
br label %32
32: ; preds = %55, %15
%33 = load i32, i32* %7
%34 = load i32, i32* %6
%35 = icmp ule i32 %33, %34
br i1 %35, label %36, label %58
36: ; preds = %32
%37 = load i32, i32* %9
%38 = load i32, i32* %9
%39 = load i32, i32* %7
%40 = load i32, i32* @MPFR_RNDU
%41 = call i32 @mpfr_mul_ui(i32 %37, i32 %38, i32 %39, i32 %40)
%42 = load i32, i32* %10
%43 = load i32, i32* @MPFR_RNDD
%44 = call i32 @mpfr_set_d(i32 %42, double 1.000000e+00, i32 %43)
%45 = load i32, i32* %10
%46 = load i32, i32* %10
%47 = load i32, i32* %9
%48 = load i32, i32* @MPFR_RNDD
%49 = call i32 @mpfr_div(i32 %45, i32 %46, i32 %47, i32 %48)
%50 = load i32, i32* %8
%51 = load i32, i32* %8
%52 = load i32, i32* %10
%53 = load i32, i32* @MPFR_RNDD
%54 = call i32 @mpfr_add(i32 %50, i32 %51, i32 %52, i32 %53)
br label %55
55: ; preds = %36
%56 = load i32, i32* %7
%57 = add i32 %56, 1
store i32 %57, i32* %7
br label %32
58: ; preds = %32
%59 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%60 = load i32, i32* @stdout
%61 = load i32, i32* %8
%62 = load i32, i32* @MPFR_RNDD
%63 = call i32 @mpfr_out_str(i32 %60, i32 10, i32 0, i32 %61, i32 %62)
%64 = call i32 @putchar(i8 signext 10)
%65 = load i32, i32* %8
%66 = call i32 @mpfr_clear(i32 %65)
%67 = load i32, i32* %9
%68 = call i32 @mpfr_clear(i32 %67)
%69 = load i32, i32* %10
%70 = call i32 @mpfr_clear(i32 %69)
store i32 0, i32* %3
br label %71
71: ; preds = %58, %13
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
@MPFR_RNDD = global i32 0
@MPFR_RNDU = global i32 0
@.str.1 = [8 x i8] c"Sum is \00"
@stdout = global i32 0
@str = [27 x i8] c"Usage ./test num_of_loops \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %39
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = tail call i32 @mpfr_init2(i32 undef, i32 200)
%11 = load i32, i32* @MPFR_RNDD
%12 = tail call i32 @mpfr_set_d(i32 undef, double 1.000000e+00, i32 %11)
%13 = tail call i32 @mpfr_init2(i32 undef, i32 200)
%14 = load i32, i32* @MPFR_RNDD
%15 = tail call i32 @mpfr_set_d(i32 undef, double 1.000000e+00, i32 %14)
%16 = tail call i32 @mpfr_init2(i32 undef, i32 200)
%17 = icmp eq i32 %9, 0
br i1 %17, label %30, label %18
18: ; preds = %6, %18
%19 = phi i32 [ %28, %18 ], [ 1, %6 ]
%20 = load i32, i32* @MPFR_RNDU
%21 = tail call i32 @mpfr_mul_ui(i32 undef, i32 undef, i32 %19, i32 %20)
%22 = load i32, i32* @MPFR_RNDD
%23 = tail call i32 @mpfr_set_d(i32 undef, double 1.000000e+00, i32 %22)
%24 = load i32, i32* @MPFR_RNDD
%25 = tail call i32 @mpfr_div(i32 undef, i32 undef, i32 undef, i32 %24)
%26 = load i32, i32* @MPFR_RNDD
%27 = tail call i32 @mpfr_add(i32 undef, i32 undef, i32 undef, i32 %26)
%28 = add i32 %19, 1
%29 = icmp ugt i32 %28, %9
br i1 %29, label %30, label %18
30: ; preds = %18, %6
%31 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* @stdout
%33 = load i32, i32* @MPFR_RNDD
%34 = tail call i32 @mpfr_out_str(i32 %32, i32 10, i32 0, i32 undef, i32 %33)
%35 = tail call i32 @putchar(i8 signext 10)
%36 = tail call i32 @mpfr_clear(i32 undef)
%37 = tail call i32 @mpfr_clear(i32 undef)
%38 = tail call i32 @mpfr_clear(i32 undef)
br label %39
39: ; preds = %30, %4
ret i32 0
}